question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
moelasmarcommented, Dec 31, 2020

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.

1reaction
anttiviljamicommented, Dec 31, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

sam local start-api - AWS Serverless Application Model
When it's accessed (through a browser, CLI, and so on), it starts a Docker container locally to invoke the function.
Read more >
Troubleshoot Dataflow errors - Google Cloud
The Dataflow job appears to be stuck because no worker activity has been seen in the last 1h. This error typically occurs when...
Read more >
Fix list for IBM WebSphere Application Server V8.5
The following is a complete listing of fixes for V8.5 with the most ... Monitored directory deployment hangs when application is deployed on...
Read more >
Environment variables and app settings in Azure App Service
Set to true to enable the /home directory to be shared across scaled instances. The default is true for custom containers.
Read more >
AWS SAM Local Lambda invocations slow - Stack Overflow
sam local start-api --warm-containers EAGER --template . ... the containers that run the function from starting every time it is invoked by ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found