Skip to content

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

@mushishi78

Description

@mushishi78

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions