Bug: "Timed out while attempting to establish a connection to the container" error after fresh install of Docker and AWS SAM
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
I just installed AWS SAM and Docker and am attempting to work with a basic Lambda Function. The issue is that the Lambda fails to mount on the Docker container.
## Set up
I just installed the latest version of docker:
```Docker version 24.0.5, build 24.0.5-0ubuntu1~20.04.1```
I also installed the latest version of SAM:
```SAM CLI, version 1.116.0```
I then created a very basic lambda function:
```
exports.handler = async (event) => {
console.log("Lambda | handler | Called");
return {
statusCode: 200,
body: JSON.stringify({ message: "Hello from Lambda!" }),
};
};
```
And a YAML:
```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Basic SAM App
Resources:
BasicFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: app.handler
Runtime: nodejs20.x
Events:
BasicApi:
Type: Api
Properties:
Path: /basic
Method: get
Outputs:
BasicApiUrl:
Description: "API Gateway endpoint URL for the Basic function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/basic/"
BasicFunctionArn:
Description: "Basic Lambda Function ARN"
Value: !GetAtt BasicFunction.Arn
```
## Usage & Errors:
The app builds fine via ```sam build```:
```
Building codeuri: /home/mnicol/Documents/samtest runtime: nodejs20.x metadata: {} architecture: x86_64 functions: BasicFunction
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrcAndLockfile
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Running NodejsNpmBuilder:LockfileCleanUp
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided
```
The issue is that when I run ```sam local invoke```, the program hangs on the "Mounting" stage and times out.
```
(base) mnicol@COECE-057000D:~/Documents/samtest$ sam local invoke --debug
2024-05-22 12:12:03,915 | Config file location: /home/mnicol/Documents/samtest/samconfig.toml
2024-05-22 12:12:03,922 | Loading configuration values from [default.['local', 'invoke'].parameters] (env.command_name.section) in config file at
'/home/mnicol/Documents/samtest/samconfig.toml'...
2024-05-22 12:12:03,924 | Configuration values successfully loaded.
2024-05-22 12:12:03,926 | Configuration values are: {}
2024-05-22 12:12:03,932 | Using SAM Template at /home/mnicol/Documents/samtest/.aws-sam/build/template.yaml
2024-05-22 12:12:03,979 | Using config file: samconfig.toml, config environment: default
2024-05-22 12:12:03,980 | Expand command line arguments to:
2024-05-22 12:12:03,982 | --template_file=/home/mnicol/Documents/samtest/.aws-sam/build/template.yaml --no_event --layer_cache_basedir=/home/mnicol/.aws-sam/layers-pkg
--container_host=localhost --container_host_interface=127.0.0.1
2024-05-22 12:12:03,984 | local invoke command is called
2024-05-22 12:12:03,990 | No Parameters detected in the template
2024-05-22 12:12:04,082 | Sam customer defined id is more priority than other IDs. Customer defined id for resource BasicFunction is BasicFunction
2024-05-22 12:12:04,084 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2024-05-22 12:12:04,087 | 0 stacks found in the template
2024-05-22 12:12:04,089 | No Parameters detected in the template
2024-05-22 12:12:04,133 | Sam customer defined id is more priority than other IDs. Customer defined id for resource BasicFunction is BasicFunction
2024-05-22 12:12:04,135 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2024-05-22 12:12:04,137 | 2 resources found in the stack
2024-05-22 12:12:04,138 | Found Serverless function with name='BasicFunction' and CodeUri='BasicFunction'
2024-05-22 12:12:04,140 | --base-dir is not presented, adjusting uri BasicFunction relative to /home/mnicol/Documents/samtest/.aws-sam/build/template.yaml
2024-05-22 12:12:04,150 | Found one Lambda function with name 'BasicFunction'
2024-05-22 12:12:04,152 | Invoking app.handler (nodejs20.x)
2024-05-22 12:12:04,154 | No environment variables found for function 'BasicFunction'
2024-05-22 12:12:04,155 | Loading AWS credentials from session with profile 'None'
2024-05-22 12:12:04,177 | Resolving code path. Cwd=/home/mnicol/Documents/samtest/.aws-sam/build, CodeUri=/home/mnicol/Documents/samtest/.aws-sam/build/BasicFunction
2024-05-22 12:12:04,179 | Resolved absolute path to code is /home/mnicol/Documents/samtest/.aws-sam/build/BasicFunction
2024-05-22 12:12:04,180 | Resolving code path. Cwd=/home/mnicol/Documents/samtest/.aws-sam/build, CodeUri=/home/mnicol/Documents/samtest/.aws-sam/build/BasicFunction
2024-05-22 12:12:04,182 | Resolved real code path to /home/mnicol/Documents/samtest/.aws-sam/build/BasicFunction
2024-05-22 12:12:04,183 | Code /home/mnicol/Documents/samtest/.aws-sam/build/BasicFunction is not a zip/jar file
2024-05-22 12:12:05,276 | Local image is up-to-date
2024-05-22 12:12:05,290 | Checking free port on 127.0.0.1:5776
2024-05-22 12:12:05,296 | Using local image: public.ecr.aws/lambda/nodejs:20-rapid-x86_64.
2024-05-22 12:12:05,299 | Mounting /home/mnicol/Documents/samtest/.aws-sam/build/BasicFunction as /var/task:ro,delegated, inside runtime container
2024-05-22 12:14:15,314 | [Container state] OOMKilled False
2024-05-22 12:14:15,876 | Cleaning all decompressed code dirs
2024-05-22 12:14:15,879 | Timed out while attempting to establish a connection to the container. You can increase this timeout by setting the SAM_CLI_CONTAINER_CONNECTION_TIMEOUT
environment variable. The current timeout is 20.0 (seconds).
2024-05-22 12:14:15,882 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-05-22 12:14:15,901 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-05-22 12:14:15,903 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '7d6d182b-57cc-4891-9327-584c9a66b9bb', 'installationId': '95421c31-2aea-40e7-9e7d-9f2cbe723bfe',
'sessionId': 'a36e3464-e364-4d52-a876-924656dc1a41', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.8', 'samcliVersion': '1.116.0', 'awsProfileProvided': False,
'debugFlagProvided': True, 'region': '', 'commandName': 'sam local invoke', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName':
'9077a2ede8e4875966ec89aec30503e4979f9a0bcf4cdfdce0b4c7a179127402', 'initialCommit': None}, 'duration': 131903, 'exitReason': 'success', 'exitCode': 0}}]}
2024-05-22 12:14:15,903 | Unable to find Click Context for getting session_id.
2024-05-22 12:14:15,916 | Sending Telemetry: {'metrics': [{'events': {'requestId': 'b563867b-0767-499b-be91-03c24c62970c', 'installationId': '95421c31-2aea-40e7-9e7d-9f2cbe723bfe',
'sessionId': 'a36e3464-e364-4d52-a876-924656dc1a41', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.8', 'samcliVersion': '1.116.0', 'commandName': 'sam local invoke',
'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '2eb82ff0705c4440826af8694d89a149', 'time_stamp': '2024-05-22
16:12:03.915', 'exception_name': None}, {'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '8fdf72c122554d4d8c78b360badc3e01', 'time_stamp': '2024-05-22
16:12:03.979', 'exception_name': None}]}}}]}
2024-05-22 12:14:16,269 | Telemetry response: 200
2024-05-22 12:14:16,271 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
(base) mnicol@COECE-057000D:~/Documents/samtest$
```
Contributor guide
Assessment
This issue has not been assessed yet.