aws-sam-cli: Issues on SAM 1.79.0 fails locally after deployed at AWS - No response from invoke container: Lambda response must be valid json
Description:
Same issues here. I don’t know why it started happening. I was working in my code and running it using sam local start-api and suddenlly it started breaking with:
Invalid lambda response received: Lambda response must be valid json
It started happening after I deployed at AWS with sam deploy - I don’t know if it breaked because of this.
Steps to reproduce:
- Create a new project using the
sam initand select the HelloWorld Template with nodejs18/typescript, or .NET 6, or python, does not matter the stack. - Run
sam build- build succeed. - Run a
sam local start-apiand try to access thehttp://127.0.0.1:3000/helloroute and got the error.
Observed result:
# sam local start-api
...
Lambda function 'HelloWorldFunction' is already running
Starting a timer for 3 seconds for function 'HelloWorldFunction'
Function 'HelloWorldFunction' timed out after 3 seconds
No response from invoke container for HelloWorldFunction
Invalid lambda response received: Lambda response must be valid json
2023-04-12 19:04:28 127.0.0.1 - - [12/Apr/2023 19:04:28] "GET /hello HTTP/1.1" 502 -
Expected result:
Should be able to see the json response from HelloWorldFunction from the SAM Template in browser or http client (postman).
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Windows 11
- SAM CLI, version 1.79.0
- aws-cli/2.11.11 Python/3.11.2 Windows/10 exe/AMD64 prompt/off
{
"version": "1.79.0",
"system": {
"python": "3.8.8",
"os": "Windows-10-10.0.22621-SP0"
},
"additional_dependencies": {
"docker_engine": "20.10.22",
"aws_cdk": "Not available",
"terraform": "Not available"
}
}
Add --debug flag to command you are running
# sam local start-api --debug
2023-04-12 19:04:17,245 | Config file location: D:\Projects\some-app\samconfig.toml
2023-04-12 19:04:17,245 | Loading configuration values from [default.['local', 'start-api'].parameters] (env.command_name.section) in config file at 'D:\Projects\some-app\samconfig.toml'...
2023-04-12 19:04:17,728 | Create Observer for resource D:\Projects\some-app\.aws-sam\build with recursive False
2023-04-12 19:04:17,738 | Initializing the lambda functions containers.
2023-04-12 19:04:17,740 | Async execution started
2023-04-12 19:04:17,740 | Invoking function functools.partial(<function InvokeContext._initialize_all_functions_containers.<locals>.initialize_function_container at 0x00000222D2BA7550>, Function(function_id='HelloWorldFunction', name='HelloWorldFunction', functionname='HelloWorldFunction', runtime='nodejs18.x', memory=None, timeout=3, handler='app.lambdaHandler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='D:\\Projects\\some-app\\.aws-sam\\build\\HelloWorldFunction', environment={'Variables': {'NODE_OPTIONS': ' --enable-source-maps'}}, rolearn=None, layers=[], events={'HelloWorld': {'Type': 'Api', 'Properties': {'Path': '/hello', 'Method': 'get', 'RestApiId': 'ServerlessRestApi'}}}, metadata={'BuildMethod': 'esbuild', 'BuildProperties': {'EntryPoints': ['app.ts'], 'Minify': True, 'Sourcemap': True, 'Target': 'es2020'}, 'SamResourceId': 'HelloWorldFunction'}, inlinecode=None, codesign_config_arn=None, architectures=['x86_64'], function_url_config=None, stack_path='', runtime_management_config=None))2023-04-12 19:04:17,741 | Waiting for async results
2023-04-12 19:04:17,747 | Loading AWS credentials from session with profile 'None'
2023-04-12 19:04:17,755 | Resolving code path. Cwd=D:\Projects\some-app\.aws-sam\build, CodeUri=D:\Projects\some-app\.aws-sam\build\HelloWorldFunction
2023-04-12 19:04:17,755 | Resolved absolute path to code is D:\Projects\some-app\.aws-sam\build\HelloWorldFunction
2023-04-12 19:04:17,757 | watch resource D:\Projects\some-app\.aws-sam\build\HelloWorldFunction
2023-04-12 19:04:17,757 | Create Observer for resource D:\Projects\some-app\.aws-sam\build\HelloWorldFunction with recursive True
2023-04-12 19:04:17,758 | watch resource D:\Projects\some-app\.aws-sam\build\HelloWorldFunction's parent D:\Projects\some-app\.aws-sam\build
2023-04-12 19:04:17,759 | Code D:\Projects\some-app\.aws-sam\build\HelloWorldFunction is not a zip/jar file
2023-04-12 19:04:20,941 | Local image is up-to-date
2023-04-12 19:04:20,952 | Using local image: public.ecr.aws/lambda/nodejs:18-rapid-x86_64.
2023-04-12 19:04:20,952 | Mounting D:\Projects\some-app\.aws-sam\build\HelloWorldFunction as /var/task:ro,delegated, inside runtime container
2023-04-12 19:04:21,488 | Async execution completed
2023-04-12 19:04:21,489 | Containers Initialization is done.
2023-04-12 19:04:21,489 | Found '1' API Events in Serverless function with name 'HelloWorldFunction'
2023-04-12 19:04:21,489 | Detected Inline Swagger definition
2023-04-12 19:04:21,489 | Lambda function integration not found in Swagger document at path='/hello' method='get'
2023-04-12 19:04:21,489 | Found '0' APIs in resource 'ServerlessRestApi'
2023-04-12 19:04:21,489 | Removed duplicates from '0' Explicit APIs and '1' Implicit APIs to produce '1' APIs
2023-04-12 19:04:21,489 | 1 APIs found in the template
2023-04-12 19:04:21,490 | Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
2023-04-12 19:04:21,491 | 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. If you used sam build before running local commands, you will need to re-run sam build for the changes to be picked up. You only need to restart SAM CLI if you update your AWS SAM template
2023-04-12 19:04:21,491 | Localhost server is starting up. Multi-threading = True
2023-04-12 19:04:21 WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:3000
2023-04-12 19:04:21 Press CTRL+C to quit
2023-04-12 19:04:24,662 | Constructed String representation of Event to invoke Lambda. Event: {"body": null, "headers": {"Accept": "*/*", "Accept-Encoding": "gzip, deflate, br", "Connection": "keep-alive", "Host": "127.0.0.1:3000", "Postman-Token": "e0be7d5d-5fa5-4f59-88a5-c826fab4edd4", "User-Agent": "PostmanRuntime/7.32.2", "X-Forwarded-Port": "3000", "X-Forwarded-Proto": "http"}, "httpMethod": "GET", "isBase64Encoded": false, "multiValueHeaders": {"Accept": ["*/*"], "Accept-Encoding": ["gzip, deflate, br"], "Connection": ["keep-alive"], "Host": ["127.0.0.1:3000"], "Postman-Token": ["e0be7d5d-5fa5-4f59-88a5-c826fab4edd4"], "User-Agent": ["PostmanRuntime/7.32.2"], "X-Forwarded-Port": ["3000"], "X-Forwarded-Proto": ["http"]}, "multiValueQueryStringParameters": null, "path": "/hello", "pathParameters": null, "queryStringParameters": null, "requestContext": {"accountId": "123456789012", "apiId": "1234567890", "domainName": "127.0.0.1:3000", "extendedRequestId": null, "httpMethod": "GET", "identity": {"accountId": null, "apiKey": null, "caller": null, "cognitoAuthenticationProvider": null, "cognitoAuthenticationType": null, "cognitoIdentityPoolId": null, "sourceIp": "127.0.0.1", "user": null, "userAgent": "Custom User Agent String", "userArn": null}, "path": "/hello", "protocol": "HTTP/1.1", "requestId": "110a774a-e9fc-49bb-b94e-3f1baab320aa", "requestTime": "12/Apr/2023:22:04:17 +0000", "requestTimeEpoch": 1681337057, "resourceId": "123456", "resourcePath": "/hello", "stage": "Prod"}, "resource": "/hello", "stageVariables": null, "version": "1.0"}
2023-04-12 19:04:24,662 | Found one Lambda function with name 'HelloWorldFunction'
2023-04-12 19:04:24,662 | Invoking app.lambdaHandler (nodejs18.x)
2023-04-12 19:04:24,663 | Resolving code path. Cwd=D:\Projects\some-app\.aws-sam\build, CodeUri=D:\Projects\some-app\.aws-sam\build\HelloWorldFunction
2023-04-12 19:04:24,663 | Resolved absolute path to code is D:\Projects\some-app\.aws-sam\build\HelloWorldFunction
2023-04-12 19:04:24,670 | Reuse the created warm container for Lambda function 'HelloWorldFunction'
2023-04-12 19:04:24,676 | Lambda function 'HelloWorldFunction' is already running
2023-04-12 19:04:24,682 | Starting a timer for 3 seconds for function 'HelloWorldFunction'
2023-04-12 19:04:27,695 | Function 'HelloWorldFunction' timed out after 3 seconds
2023-04-12 19:04:28,443 | No response from invoke container for HelloWorldFunction
2023-04-12 19:04:28,443 | Invalid lambda response received: Lambda response must be valid json
2023-04-12 19:04:28 127.0.0.1 - - [12/Apr/2023 19:04:28] "GET /hello HTTP/1.1" 502 -
I have tried a lot of things regarding docker, reinstall AWS CLI and SAM CLI, none worked. I don’t know what to do.
Thank you.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 18 (6 by maintainers)
Was having this issue while running sam local on an M1 MacBook (arm64).
By default SAM pulls an x86-based image to run Lambda functions on.
Updating the architecture to arm64 in the template.yml fixed the issue for me.
Hope this helps!
@felipeoriani Assuming your issue is the same as @tfmeneses, https://github.com/aws/aws-sam-cli/issues/4222 maybe helpful.
Our dockerpy is pretty out of date, I attempted to upgrade before https://github.com/aws/aws-sam-cli/pull/4356 but ran into some potential back-compat issues and never had the time to dig deeper. It could be upgraded will help this but its hard to know because the error is so value.
@felipeoriani It sounds like what broke is your upgrade. My suggestion would be to downgrade docker desktop and see if that resolves the issue.
@felipeoriani Another thing to try is increase the Lambda timeout. That might be causing some issues if (for some reason) the request to the container is taking too long or something. Just noticed that in your output.
I’m using:
aws-cli/2.11.6 Python/3.11.2SAM CLI, version 1.76.04.18.0 (104112)with WSL2To solve my problem I disabled the Hyper-V feature.