aws-sam-cli: local start-api --warm-containers with --template in a directory under $HOME gets stuck

Description:

When using the --template parameter together with --warm-containers using sam local start-api, the CLI gets stuck at this message and the container never starts:

Mounting /Users/viljamikuosmanen/sam-app as /var/task:ro,delegated inside runtime container

Steps to reproduce:

Initialise a fresh project using the nodejs12.x quick-start-web template:

$ sam init
...
    -----------------------
    Generating application:
    -----------------------
    Name: sam-app
    Runtime: nodejs12.x
    Dependency Manager: npm
    Application Template: quick-start-web
    Output Directory: .

Attempt to start the local api supplying the --template flag in order to mount the whole directory:

$ cd sam-app
$ sam build
$ sam local start-api  --warm-containers EAGER --template template.yml --debug

Observed result:

Command output:

2020-12-30 14:39:12,050 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2020-12-30 14:39:12,137 | local start-api command is called
2020-12-30 14:39:12,151 | No Parameters detected in the template
2020-12-30 14:39:12,175 | 6 resources found in the template
2020-12-30 14:39:12,175 | Found Serverless function with name='getAllItemsFunction' and CodeUri='.'
2020-12-30 14:39:12,175 | Found Serverless function with name='getByIdFunction' and CodeUri='.'
2020-12-30 14:39:12,175 | Found Serverless function with name='putItemFunction' and CodeUri='.'
2020-12-30 14:39:12,180 | Initializing the lambda functions containers.
2020-12-30 14:39:12,180 | Async execution started
2020-12-30 14:39:12,180 | Invoking function functools.partial(<function InvokeContext._initialize_all_functions_containers.<locals>.initialize_function_container at 0x1072efa60>, Function(name='getAllItemsFunction', functionname='getAllItemsFunction', runtime='nodejs12.x', memory=128, timeout=100, handler='src/handlers/get-all-items.getAllItemsHandler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='.', environment={'Variables': {'SAMPLE_TABLE': 'SampleTable'}}, rolearn=None, layers=[], events={'Api': {'Type': 'HttpApi', 'Properties': {'ApiId': 'ServerlessHttpApi', 'Path': '$default', 'Method': 'x-amazon-apigateway-any-method'}}}, metadata=None, codesign_config_arn=None))
2020-12-30 14:39:12,181 | Invoking function functools.partial(<function InvokeContext._initialize_all_functions_containers.<locals>.initialize_function_container at 0x1072efa60>, Function(name='getByIdFunction', functionname='getByIdFunction', runtime='nodejs12.x', memory=128, timeout=100, handler='src/handlers/get-by-id.getByIdHandler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='.', environment={'Variables': {'SAMPLE_TABLE': 'SampleTable'}}, rolearn=None, layers=[], events={'Api': {'Type': 'Api', 'Properties': {'Path': '/{id}', 'Method': 'GET', 'RestApiId': 'ServerlessRestApi'}}}, metadata=None, codesign_config_arn=None))
2020-12-30 14:39:12,181 | Invoking function functools.partial(<function InvokeContext._initialize_all_functions_containers.<locals>.initialize_function_container at 0x1072efa60>, Function(name='putItemFunction', functionname='putItemFunction', runtime='nodejs12.x', memory=128, timeout=100, handler='src/handlers/put-item.putItemHandler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='.', environment={'Variables': {'SAMPLE_TABLE': 'SampleTable'}}, rolearn=None, layers=[], events={'Api': {'Type': 'Api', 'Properties': {'Path': '/', 'Method': 'POST', 'RestApiId': 'ServerlessRestApi'}}}, metadata=None, codesign_config_arn=None))
2020-12-30 14:39:12,182 | Environment variables overrides data is standard format
2020-12-30 14:39:12,182 | Waiting for async results
2020-12-30 14:39:12,182 | Loading AWS credentials from session with profile 'None'
2020-12-30 14:39:12,183 | Environment variables overrides data is standard format
2020-12-30 14:39:12,188 | Environment variables overrides data is standard format
2020-12-30 14:39:12,191 | Loading AWS credentials from session with profile 'None'
2020-12-30 14:39:12,191 | Loading AWS credentials from session with profile 'None'
2020-12-30 14:39:12,211 | Resolving code path. Cwd=/Users/viljamikuosmanen/sam-app, CodeUri=.
2020-12-30 14:39:12,212 | Resolving code path. Cwd=/Users/viljamikuosmanen/sam-app, CodeUri=.
2020-12-30 14:39:12,212 | Resolved absolute path to code is /Users/viljamikuosmanen/sam-app
2020-12-30 14:39:12,213 | Resolved absolute path to code is /Users/viljamikuosmanen/sam-app
2020-12-30 14:39:12,213 | Code /Users/viljamikuosmanen/sam-app is not a zip/jar file
2020-12-30 14:39:12,214 | Code /Users/viljamikuosmanen/sam-app is not a zip/jar file
2020-12-30 14:39:12,216 | Resolving code path. Cwd=/Users/viljamikuosmanen/sam-app, CodeUri=.
2020-12-30 14:39:12,216 | Resolved absolute path to code is /Users/viljamikuosmanen/sam-app
2020-12-30 14:39:12,217 | Code /Users/viljamikuosmanen/sam-app is not a zip/jar file
2020-12-30 14:39:12,244 | Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-nodejs12.x:rapid-1.15.0.

2020-12-30 14:39:12,244 | Mounting /Users/viljamikuosmanen/sam-app as /var/task:ro,delegated inside runtime container
2020-12-30 14:39:12,245 | Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-nodejs12.x:rapid-1.15.0.

2020-12-30 14:39:12,245 | Mounting /Users/viljamikuosmanen/sam-app as /var/task:ro,delegated inside runtime container
2020-12-30 14:39:12,246 | Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-nodejs12.x:rapid-1.15.0.

2020-12-30 14:39:12,246 | Mounting /Users/viljamikuosmanen/sam-app as /var/task:ro,delegated inside runtime container

SAM CLI gets stuck and the container gets created but never started.

Starting with --warm-containers LAZY starts the local API but runtime containers fail to start when requested.

Without the --template parameter, the local api works as expected.

Expected result:

I expected the runtime container to mount my local project directory and the local api to be exposed at port 3000.

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

  1. Mac OS Catalina 10.15.7
  2. SAM CLI, version 1.15.0
  3. Docker version 20.10.0, build 7287ab3

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

So as long as the template isn’t directly one level under $HOME, it works? πŸ˜…

I think no … I think the issue will happen if the parent directory of your project contains a lot of directories. I will investigate more on this issue in the morning.

Thank you so much for your help @moelasmar ! This helped me already find a good workaround so I can proceed with my work. πŸ‘

Ok, I got the issue … I believe that the issue in this snippet of code: https://github.com/aws/aws-sam-cli/blob/ff2b11498d4f83fcd011e63ff29f4be8faba5b1d/samcli/lib/utils/file_observer.py#L105-L115 thanks @anttiviljami for your support.