Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static_dir relative to .aws-sam/build directory #3309

Closed
mushishi78 opened this issue Sep 28, 2021 · 4 comments
Closed

static_dir relative to .aws-sam/build directory #3309

mushishi78 opened this issue Sep 28, 2021 · 4 comments
Labels

Comments

@mushishi78
Copy link

Description:

When using the --static-dir argument, it's says and the code seems to think that it's relative to the current working directory, but the cwd seems to be .aws-sam/build not where the command is invoked from

Steps to reproduce:

  1. Create a project with a template file
  2. Create a folder for static assets
  3. Invoke sam local start-api -s ./public

Observed result:

Can't find the folder unless you do sam local start-api -s ../../public

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: MacOS BigSur (M1)
  2. sam --version: 1.32.0
  3. AWS region: N/A
2021-09-28 09:08:09,630 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-09-28 09:08:09,631 | Using config file: samconfig.toml, config environment: default
2021-09-28 09:08:09,631 | Expand command line arguments to:
2021-09-28 09:08:09,631 | --template_file=/Users/max/dev/wedding/.aws-sam/build/template.yaml --parameter_overrides={'Locality': 'local', 'Environment': 'test', 'TableName': 'testWeddingTable'} --log_file=.logs/test.log --static_dir=./public --host=127.0.0.1 --port=3000 --layer_cache_basedir=/Users/max/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1 
2021-09-28 09:08:09,688 | local start-api command is called
2021-09-28 09:08:09,693 | Collected default values for parameters: {'Locality': 'local', 'Environment': 'develop'}
2021-09-28 09:08:09,706 | 5 stacks found in the template
2021-09-28 09:08:09,706 | Collected default values for parameters: {'Locality': 'local', 'Environment': 'develop'}
2021-09-28 09:08:09,718 | 5 resources found in the stack 
2021-09-28 09:08:09,718 | Collected default values for parameters: {'Locality': 'local', 'Environment': 'develop'}
2021-09-28 09:08:09,729 | Found Serverless function with name='IndexFunction' and CodeUri='IndexFunction'
2021-09-28 09:08:09,729 | --base-dir is not presented, adjusting uri IndexFunction relative to /Users/max/dev/wedding/.aws-sam/build/template.yaml
2021-09-28 09:08:09,729 | Found Serverless function with name='LoginGetFunction' and CodeUri='LoginGetFunction'
2021-09-28 09:08:09,729 | --base-dir is not presented, adjusting uri LoginGetFunction relative to /Users/max/dev/wedding/.aws-sam/build/template.yaml
2021-09-28 09:08:09,729 | Found Serverless function with name='PullFunction' and CodeUri='PullFunction'
2021-09-28 09:08:09,729 | --base-dir is not presented, adjusting uri PullFunction relative to /Users/max/dev/wedding/.aws-sam/build/template.yaml
2021-09-28 09:08:09,729 | Found Serverless function with name='TestGetAllFunction' and CodeUri='TestGetAllFunction'
2021-09-28 09:08:09,729 | --base-dir is not presented, adjusting uri TestGetAllFunction relative to /Users/max/dev/wedding/.aws-sam/build/template.yaml
2021-09-28 09:08:09,743 | Collected default values for parameters: {'Locality': 'local', 'Environment': 'develop'}
2021-09-28 09:08:09,755 | Collected default values for parameters: {'Locality': 'local', 'Environment': 'develop'}
2021-09-28 09:08:09,767 | Found '1' API Events in Serverless function with name 'IndexFunction'
2021-09-28 09:08:09,767 | Found '1' API Events in Serverless function with name 'LoginGetFunction'
2021-09-28 09:08:09,767 | Found '1' API Events in Serverless function with name 'PullFunction'
2021-09-28 09:08:09,767 | Found '1' API Events in Serverless function with name 'TestGetAllFunction'
2021-09-28 09:08:09,767 | Detected Inline Swagger definition
2021-09-28 09:08:09,767 | Lambda function integration not found in Swagger document at path='/' method='get'
2021-09-28 09:08:09,767 | Lambda function integration not found in Swagger document at path='/login' method='get'
2021-09-28 09:08:09,767 | Lambda function integration not found in Swagger document at path='/pull' method='get'
2021-09-28 09:08:09,767 | Lambda function integration not found in Swagger document at path='/test-get-all' method='get'
2021-09-28 09:08:09,767 | Found '0' APIs in resource 'ServerlessRestApi'
2021-09-28 09:08:09,767 | Removed duplicates from '0' Explicit APIs and '4' Implicit APIs to produce '4' APIs
2021-09-28 09:08:09,767 | 4 APIs found in the template
2021-09-28 09:08:09,774 | Mounting IndexFunction at http://127.0.0.1:3000/ [GET]
2021-09-28 09:08:09,774 | Mounting PullFunction at http://127.0.0.1:3000/pull [GET]
2021-09-28 09:08:09,774 | Mounting TestGetAllFunction at http://127.0.0.1:3000/test-get-all [GET]
2021-09-28 09:08:09,774 | Mounting LoginGetFunction at http://127.0.0.1:3000/login [GET]
2021-09-28 09:08:09,774 | You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2021-09-28 09:08:09,775 | Localhost server is starting up. Multi-threading = True
2021-09-28 09:08:09  * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)

I can see this output says something about --base-dir is not presented, adjusting uri but I've tried using that argument with the preceeding sam build command it didn't seem to do much.

@c2tarun c2tarun added the area/local/start-api sam local start-api command label Sep 29, 2021
@c2tarun
Copy link
Contributor

c2tarun commented Sep 29, 2021

Hi @mushishi78 ,

Thanks for reporting this. I took a quick look and it seem to be expected behavior. Based on this code it seem to resolve the static resource path relative to where the template file is. Now if the project hasn't been built then it should resolve based on the template file in the project. But if the project is built then it will resolve based on the template file in .aws-sam/build folder.

I don't think this is an issue with local start-api command. I think we should have some way to put static resources inside the build folder so that all resources can be reached from one location. But then again the problem I see with that approach is that every time static resource is modified user will have to build the project. I'll sync with team on what is the right approach here and update this issue.

Thanks
Tarun

@mushishi78
Copy link
Author

Thanks Tarun for the quick and well explained response. I'm sure I'll be happy with whatever conclusion your team reaches. Thanks for your help

@qingchm
Copy link
Contributor

qingchm commented Jan 28, 2022

@mushishi78 Thanks for your understanding! Since this is expected behaviour I will close this issue for now please feel free to reach out or re-open the ticket if you have any further concerns! Thanks!

@qingchm qingchm closed this as completed Jan 28, 2022
@amanAtHoneyHealth
Copy link

I think we should have some way to put static resources inside the build folder so that all resources can be reached from one location.
@c2tarun how do I add the static folder in my .aws-sam/build/ folder 🤔 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants