aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Bug: No response from invoke container for helloworld function

Open czone45 opened this issue 3 years ago • 5 comments

Description:

i created a new sam app. and then immediately called sam but the lambda call timesout. I have set the timeout setting in the template.yml file to 1 minuts with the same result.

Function 'HelloWorldFunction' timed out after 3 seconds No response from invoke container for HelloWorldFunction

Steps to reproduce:

SAM init 1 - Hello world example Use the most popular runtime and package type? (Python and zip): Y Would you like to enable X-Ray tracing on the function(s) in your application? [y/N]: N Would you like to enable monitoring using CloudWatch Application Insights? N project name = Sam-Python-Hello

c:\App Dev Code\SAM_Helloworld\SAM-Python-Hello>sam local invoke HelloWorldFunction --event events/event.json Invoking app.lambda_handler (python3.9) Local image is up-to-date Using local image: public.ecr.aws/lambda/python:3.9-rapid-x86_64.

Mounting c:\App Dev Code\SAM_Helloworld\SAM-Python-Hello\hello_world as /var/task:ro,delegated inside runtime container Function 'HelloWorldFunction' timed out after 3 seconds No response from invoke container for HelloWorldFunction

Observed result:

c:\App Dev Code\SAM_Helloworld\SAM-Python-Hello>sam local invoke --debug 2023-03-15 12:34:48,092 | Config file location: c:\App Dev Code\SAM_Helloworld\SAM-Python-Hello\samconfig.toml 2023-03-15 12:34:48,093 | Loading configuration values from [default.['local', 'invoke'].parameters] (env.command_name.section) in config file at 'c:\App Dev Code\SAM_Helloworld\SAM-Python-Hello\samconfig.toml'... 2023-03-15 12:34:48,098 | Configuration values successfully loaded. 2023-03-15 12:34:48,099 | Configuration values are: {'stack_name': 'SAM-Python-Hello'} 2023-03-15 12:34:48,106 | Using SAM Template at c:\App Dev Code\SAM_Helloworld\SAM-Python-Hello\template.yaml 2023-03-15 12:34:48,125 | Using config file: samconfig.toml, config environment: default 2023-03-15 12:34:48,125 | Expand command line arguments to: 2023-03-15 12:34:48,126 | --template_file=c:\App Dev Code\SAM_Helloworld\SAM-Python-Hello\template.yaml --no_event --layer_cache_basedir=C:\Users\ingramc2\AppData\Roaming\AWS SAM\layers-pkg --container_host=localhost --container_host_interface=127.0.0.1 2023-03-15 12:34:48,126 | local invoke command is called 2023-03-15 12:34:48,130 | No Parameters detected in the template 2023-03-15 12:34:48,162 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id 2023-03-15 12:34:48,162 | 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 2023-03-15 12:34:48,165 | 0 stacks found in the template 2023-03-15 12:34:48,165 | No Parameters detected in the template 2023-03-15 12:34:48,184 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id 2023-03-15 12:34:48,184 | 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 2023-03-15 12:34:48,187 | 2 resources found in the stack 2023-03-15 12:34:48,187 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello_world/' 2023-03-15 12:34:48,187 | --base-dir is not presented, adjusting uri hello_world/ relative to c:\App Dev Code\SAM_Helloworld\SAM-Python-Hello\template.yaml 2023-03-15 12:34:48,207 | Found one Lambda function with name 'HelloWorldFunction' 2023-03-15 12:34:48,208 | Invoking app.lambda_handler (python3.9) 2023-03-15 12:34:48,208 | No environment variables found for function 'HelloWorldFunction' 2023-03-15 12:34:48,208 | Loading AWS credentials from session with profile 'None' 2023-03-15 12:34:50,248 | Resolving code path. Cwd=c:\App Dev Code\SAM_Helloworld\SAM-Python-Hello, CodeUri=c:\App Dev Code\SAM_Helloworld\SAM-Python-Hello\hello_world 2023-03-15 12:34:50,248 | Resolved absolute path to code is c:\App Dev Code\SAM_Helloworld\SAM-Python-Hello\hello_world 2023-03-15 12:34:50,249 | Code c:\App Dev Code\SAM_Helloworld\SAM-Python-Hello\hello_world is not a zip/jar file 2023-03-15 12:34:54,876 | Local image is up-to-date 2023-03-15 12:34:54,905 | Using local image: public.ecr.aws/lambda/python:3.9-rapid-x86_64.

2023-03-15 12:34:54,906 | Mounting c:\App Dev Code\SAM_Helloworld\SAM-Python-Hello\hello_world as /var/task:ro,delegated inside runtime container 2023-03-15 12:34:56,102 | Starting a timer for 3 seconds for function 'HelloWorldFunction' 2023-03-15 12:34:59,113 | Function 'HelloWorldFunction' timed out after 3 seconds 2023-03-15 12:34:59,176 | Failed to get the logs from the container Traceback (most recent call last): File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\docker\container.py", line 402, in _write_container_output for stdout_data, stderr_data in output_itr: File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\types\daemon.py", line 32, in next return next(self._stream) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\api\client.py", line 406, in gen = (demux_adaptor(*frame) for frame in gen) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 94, in frames_iter_no_tty (stream, n) = next_frame_header(socket) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 66, in next_frame_header data = read_exactly(socket, 8) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 51, in read_exactly next_data = read(socket, n - len(data)) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 35, in read return socket.recv(n) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipesocket.py", line 23, in wrapped return f(self, *args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipesocket.py", line 117, in recv err, data = win32file.ReadFile(self._handle, bufsize) pywintypes.error: (109, 'ReadFile', 'The pipe has been ended.') 2023-03-15 12:34:59,840 | Container was not created. Skipping deletion 2023-03-15 12:34:59,840 | Cleaning all decompressed code dirs 2023-03-15 12:34:59,842 | No response from invoke container for HelloWorldFunction 2023-03-15 12:34:59,844 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics 2023-03-15 12:35:01,074 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '781c44c1-48ed-4ef9-aff8-8cd057a3cba4', 'installationId': '4c0a5835-ef16-405c-8cc7-3c0b9dbf2073', 'sessionId': '3d04fcea-535c-4254-8351-e2a7e409f2a9', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.8', 'samcliVersion': '1.74.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local invoke', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': 'a68a3862d830eb307fc996fa8610d6852ad368dfb78b890cee6a03d461c092a2', 'initialCommit': None}, 'duration': 11718, 'exitReason': 'success', 'exitCode': 0}}]} 2023-03-15 12:35:01,689 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

Expected result:

SAM to locally invoke the lambda

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

# Paste the output of `sam --info` here

{ "version": "1.74.0", "system": { "python": "3.8.8", "os": "Windows-10-10.0.19041-SP0" }, "additional_dependencies": { "docker_engine": "20.10.23", "aws_cdk": "Not available", "terraform": "Not available" } }

Add --debug flag to command you are running

czone45 avatar Mar 15 '23 16:03 czone45

Thanks for raising the issue. I couldn't reproduce the issue in my Windows machine. However, from your provided logs, it seems like there's some issue from Docker. Looks like it couldn't create the lambda container for some reason. But I'm not 100% sure. Will need more investigation.

hawflau avatar Mar 16 '23 21:03 hawflau

I am looking in container.py for some reason it is blowing up on wait_for_logs. I hope that helps. Thanks for confirming that it is working on your end. This a fantastic tool and I am really looking forward to using it.

cingram avatar Mar 16 '23 21:03 cingram

I have the exact same issue, is there a fix yet?

JakobG-dev avatar Apr 18 '23 16:04 JakobG-dev

I have the same issue on Windows 11. Docker-desktop: 4.18.0 AWS SAM CLI: 1.81

I can build my sam application with sam build --user-container, but I cannot run sam local invoke and get the same error.

{ "version": "1.81.0", "system": { "python": "3.8.8", "os": "Windows-10-10.0.22621-SP0" }, "additional_dependencies": { "docker_engine": "20.10.24", "aws_cdk": "Not available", "terraform": "Not available" } }

MathiasBuus avatar Apr 27 '23 10:04 MathiasBuus

Consolidating issues here: https://github.com/aws/aws-sam-cli/issues/4833

sriram-mv avatar May 01 '23 05:05 sriram-mv