-
Notifications
You must be signed in to change notification settings - Fork 1.2k
1.13.1: Invalid lambda response received: Lambda response must be valid json #2436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
is there any workaround available? how do I downgrade? |
|
Can confirm we are experiencing this. It did not occur in versions |
I'm getting the same error while trying to complete official tutorial: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-hello-world.html. Downgrading to |
Getting the same error as well. Looks like a known bug. Any resolution will be really helpful. Error notes attached below... Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET] Mounting C:\Users\rekharamesh\sai-sam-model.aws-sam\build\HelloWorldFunction as /var/task:ro,delegated inside runtime container Mounting C:\Users\rekharamesh\sai-sam-model.aws-sam\build\HelloWorldFunction as /var/task:ro,delegated inside runtime container |
I am having the same error 🤷♂️ |
So I was doing some digging on #2436 and I think they are both related. So between 1.12 and 1.13, we changed how we communicate with the container. In 1.12, we just execute the container to run the code. With 1.13, we updated to use This is why SAM CLI cannot communicate with the local function. I need to do some deeper investigation to see how we can get around this docker limitation. I am not trilled to have to move back to executing the container. Communicating over http gives us much more control and allows us to integrate nicely with This only appears to break for the host network, so if you drop the |
Workarounds:
Use cases
Docker network host only works on Linux, so we are interested in hearing the use-cases to make sure we understand what kind of workloads will be impacted. |
@sriram-mv here is the extract from the Makefile on one of my projects: # Start local AWS API Gateway replica for API calls testing.
local-api: local-build wait-db-readiness
@echo 'Use "make stop-local-api" to stop the API.'
@# The "host" network should be used to connect to
@# the database, defined in Docker Compose.
sam local start-api --port 4004 --docker-network host --skip-pull-image --debug & Should also work with the network the Docker Compose creates for the stack. Didn't test but think it should. Edit: Dec 13, 2020: It does not work. sam local start-api --port 4004 --docker-network SANITIZED_default --skip-pull-image --debug &
curl -X POST http://127.0.0.1:4004/api/v1/app/add
Will try changing the DB connection host too. As you see the convenience is already lost. Edit 2: does not work. Unable to connect to a database provided by Docker Compose from the host. |
We're getting the same 502 response on We've been forced to fall back to Is there any information I can provide about our setup to help with this? |
@BR0kEN- You are trying to connect to localhost but the container is not on that network. You should be using |
@jfuss Well, yeah, that can work but why should I not be using the |
@BR0kEN- SAM CLI need to publish a port in order to communicate to the container. Docker disallows this on host. Further more, Docker has documentation that states the host network driver is only supported on Linux: https://docs.docker.com/network/host/. On Mac and Windows, host means the docker vm not your machine. This is why we recommended to use a different network as this still allows us to publish a port for our communication and customers can still do communication within that docker network for whatever they need (though this may require different configuration of your endpoints in the local mode). Please see #2436 (comment) and #2436 (comment) from above. |
I'm using aws-sam-cli inside a docker conatiner and still can't get it working. Basically I want to run
Running such
I've tried to run it in non-host network, but no success yet. |
getting the same thing. can anyone help ? |
I am seeing this error when using Postman. If I access http://127.0.0.1:3000/ via the browser, everything works fine (at least, for the GET method) but attempting a basic GET for http://127.0.0.1:3000/ via Postman results in this error in the console in VS Code (where I am running EDIT - This is using v1.15.0 |
I am getting this error too on browser or postman. Mac BigSur 11.1 |
It seems that the suggested workarounds of providing a non-host To replicate this, put the following files into an AWS SAM project root:
FROM amazon/aws-cli:2.1.28
ARG AWS_SAM_CLI_VERSION=1.19.1
RUN yum -y update && \
yum install -y python3 && \
python3 -m pip --disable-pip-version-check install aws-sam-cli==${AWS_SAM_CLI_VERSION}
ENTRYPOINT [ "" ] and version: "3.7"
services:
testcase:
build: .
working_dir: $PWD
command: sam local start-api --template template.yaml --host 0.0.0.0 -v $PWD
ports:
- 3000:3000
volumes:
- '$PWD:$PWD'
- '/var/run/docker.sock:/var/run/docker.sock' Now run the application locally: docker-compose up Hitting any of your API endpoints will result in a 502 BAD GATEWAY response with the error message This is pretty disruptive for us. We use Docker to ensure that all team members, and the CI server, use exactly the same version of the AWS SAM CLI binaries. The CLI project updates frequently enough that attempting to keep everyone in sync would be a bit of a nightmare. Our solution at the moment is to pin our version at 1.12, the last version before this defect, but this can't last. We will very soon need to upgrade to 1.17 for HTTP API Payload v2 support. |
It looks like the Docker aspect of this issue is already covered in #2492. |
Same issue here with |
Maybe something could be done now for Linux with the support of |
Could someone summarize a workaround for Linux? I tried using the docker0 IP without success ... |
My bad here. I managed to solve this. Total oversight. Change const docClient = new dynamoDb.DocumentClient({
endpoint: 'http://localhost:8000',
}); const docClient = new dynamoDb.DocumentClient({
region: 'localhost',
endpoint: 'http://dynamo-local:8000',
accessKeyId: 'ml6ifq',
secretAccessKey: 'sw7vjzh',
convertEmptyValues: true,
}); |
Close the issue since we released two options |
I'm having the same problem with multiple autogenerated lambda functions from |
@xazhao Can you please give an example for Linux? |
I'm having this issue on Linux as well. |
i would also like an example for Linux... I can't get it to work |
I am facing this issue on linux 21.10 and sam 1.46. Unable to run lambda in local with connection to localhost postgres server. |
Is there any solution / workaround for linux ? |
I was able to connect to |
I have dockerized SAM following similar posts above and the command worked after using this suggestion!!! thank you!!! sam local start-api -p 3000 --host 0.0.0.0 --docker-network aws_backend --container-host host.docker.internal |
i start sam cli in docker container with
It still does not work. Im on MacOS |
did you require to create the docker network ?
Above error confirms its a network. from above it says to create docker network, do we have to create a new network everytime with the new container id? |
This happened to me when I was trying to send invalid data type to my lambda function. Check that first. |
In my case, the error occurred because I had selected |
Uh oh!
There was an error while loading. Please reload this page.
Description:
sam local start-api
stopped triggering Lambda by HTTP request. Downgrading to1.12.0
gives the expected result.Steps to reproduce:
Observed result:
Expected result:
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --version
: 1.13.1The text was updated successfully, but these errors were encountered: