Closed felipeoriani closed 1 year ago
I'm getting the same error when I'm running locally using Docker. I can't run the "helloWorld" from sam init/build.
Yesterday It was running. Today I installed a Windows Update/Docker Desktop update and it doesn't work more.
@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.
@jfuss Thank you very much! It works for me.
@tfmeneses can you share the versions you are using for Windows, AWS CLI, AWS SAM and Docker? I will try it later, thank you!
I'm using:
aws-cli/2.11.6 Python/3.11.2
SAM CLI, version 1.76.0
4.18.0 (104112)
with WSL2To solve my problem I disabled the Hyper-V feature.
@jfuss it did not work for me. I downgrade some versions here, and currently using:
aws-cli/2.11.11 Python/3.11.2 Windows/10 exe/AMD64 prompt/off
1.76.0
4.18.0
18.15.0
I created a new app with sam init
using HelloWorld Template for nodejs18.x and Typescript and still got the same error:
2023-04-13 23:45:13 Press CTRL+C to quit
Invoking app.lambdaHandler (nodejs18.x)
Reuse the created warm container for Lambda function 'HelloWorldFunction'
Lambda function 'HelloWorldFunction' is already running
Function 'HelloWorldFunction' timed out after 3 seconds
No response from invoke container for HelloWorldFunction
Invalid lambda response received: Lambda response must be valid json
If you have any other suggestions, I would appreciate it. Thank you.
@felipeoriani Are you able to run any containers locally? Trying to see if this is only a SAM CLI issue running containers or a wider system thing going on.
Yes, it looks fine on my machine. I am running mysql:8 on my machine. I can make more tests if you want. I have Hyper-V disabled on my Windows.
Something I want to try is using WSL2 here. I will prepare a new instance for WSL2 and install AWS CLI and SAM CLI, sharing the docker instance to check if it looks fine.
@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 have tried to set the 30 seconds, but still got the same error. I am thinking it is something on my machine, but I really don't know what. It was working one day, and after I deployed at AWS it was not working on the next day anymore. I know it is weird, but this is the only thing I have done differently. Thanks @jfuss
Hi @felipeoriani ,
I've tried to re-produce this issue on a Win11 machine with brand new docker installation using WSL2 (installed newest Docker Desktop which is 4.19) and newest SAM CLI (v1.83). And I got it working without any issues.
While installing Docker Desktop, it warned me to update WSL2 to latest kernel (suggested me to run wsl --update
command), you might give it a try for your case.
As @jfuss mentioned and from the command output that you have provided, your invocation times out;
Lambda function 'HelloWorldFunction' is already running
Function 'HelloWorldFunction' timed out after 3 seconds
No response from invoke container for HelloWorldFunction
You might try re-installing the Docker engine, or running docker system prune -a
(this command will remove all the images, containers, volumes on your local system, so please don't use it if you have containers or volumes running with critical information) to clean up installation.
Please let us know if any of this works or if you can provide other information for your error.
Closing due to inactivity. Feel free to re-open if your issue isn't resolved.
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
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.
Architectures:
- arm64
Hope this helps!
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.
This should be raised as a separate 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.
That's solve my problem.
Mac
Could you help me understand what was the fix for this issue?
I tried to use the code from this tutorial and as presented here it should be possible to set the content type.
Is this still an option? If so, do you maybe know why it still expects JSON format even if I specified 'text/plain'
template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sam-app
Sample SAM Template for sam-app
Globals:
Function:
Timeout: 3
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello-world/
Handler: app.lambdaHandler
Runtime: nodejs20.x
Architectures:
- arm64
Events:
HelloWorld:
Type: Api
Properties:
Path: /hello
Method: get
app.mjs
export const lambdaHandler = awslambda.streamifyResponse(
async (event, responseStream, context) => {
responseStream.setContentType('text/plain');
responseStream.write('Hello, world!');
responseStream.end();
}
);
Logs
denislapadatovic@Deniss-MacBook-Pro sam-app % sam local start-api
Initializing the lambda functions containers.
Local image is up-to-date
Using local image: public.ecr.aws/lambda/nodejs:20-rapid-arm64.
Mounting /Users/denislapadatovic/Desktop/sam-app/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated, inside runtime container
Containers Initialization is done.
Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
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
2024-09-10 19:38:04 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
2024-09-10 19:38:04 Press CTRL+C to quit
Invoking app.lambdaHandler (nodejs20.x)
Reuse the created warm container for Lambda function 'HelloWorldFunction'
Lambda function 'HelloWorldFunction' is already running
END RequestId: 7de61b37-fb7d-421f-b4c3-97f233b6184f
REPORT RequestId: 7de61b37-fb7d-421f-b4c3-97f233b6184f Init Duration: 0.03 ms Duration: 50.11 ms Billed Duration: 51 ms Memory Size: 128 MB Max Memory Used: 128 MB
Invalid lambda response received: Lambda response must be valid json
2024-09-10 19:38:15 127.0.0.1 - - [10/Sep/2024 19:38:15] "GET /hello HTTP/1.1" 502 -
2024-09-10 19:38:15 127.0.0.1 - - [10/Sep/2024 19:38:15] "GET /favicon.ico HTTP/1.1" 403 -
Response
EDIT:
Versions (MacOS):
EDIT 2:
I tried using the AWS Quick Start application template: 9 - Lambda Response Streaming
and got the same result.
EDIT 3:
I tried invoking the Lambda function directly and this is working.
Code:
export const lambdaHandler = awslambda.streamifyResponse(
async (event, responseStream, context) => {
responseStream.setContentType('application/json');
responseStream.write(JSON.stringify({ body: { message: 'Hello, world!' } }));
responseStream.end();
}
);
Command:
sam local invoke "HelloWorldFunction" -e events/event.json
Response:
START RequestId: 6fe77a4c-aade-4e70-b4b4-654a930c9af0 Version: $LATEST
END RequestId: 5267f267-5caf-4692-b53e-b9ca59babd99
REPORT RequestId: 5267f267-5caf-4692-b53e-b9ca59babd99 Init Duration: 0.02 ms Duration: 42.73 ms Billed Duration: 43 ms Memory Size: 128 MB Max Memory Used: 128 MB
{"body": {"message": "Hello, world!"}}
But I still need to figure out how to make it work with API Gateway since when I run the code with sam local start-api
Output:
Lambda function 'HelloWorldFunction' is already running
START RequestId: 8dfe35dc-e450-40f8-b025-66555079a277 Version: $LATEST
END RequestId: a65f9345-1706-46ee-a3c1-54b1bb8a3193
REPORT RequestId: a65f9345-1706-46ee-a3c1-54b1bb8a3193 Init Duration: 0.04 ms Duration: 62.78 ms Billed Duration: 63 ms Memory Size: 128 MB Max Memory Used: 128 MB
No Content-Type given. Defaulting to 'application/json'.
2024-09-11 18:22:55 127.0.0.1 - - [11/Sep/2024 18:22:55] "GET / HTTP/1.1" 200 -
2024-09-11 18:22:55 127.0.0.1 - - [11/Sep/2024 18:22:55] "GET /favicon.ico HTTP/1.1" 403 -
Browser:
So I can see the output in the browser, but it is still strange to me why I see No Content-Type given. Defaulting to 'application/json'.
even if I set it responseStream.setContentType('application/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:It started happening after I deployed at AWS with
sam deploy
- I don't know if it breaked because of this.Steps to reproduce:
sam init
and select the HelloWorld Template with nodejs18/typescript, or .NET 6, or python, does not matter the stack.sam build
- build succeed.sam local start-api
and try to access thehttp://127.0.0.1:3000/hello
route and got the error.Observed result:
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)
Add --debug flag to command you are running
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.