Issue
I have a small app (just testing it out for now) written in typescript and I would like to deploy to lambda. I have followed the official tutorial for href="https://docs.aws.amazon.com/lambda/latest/dg/images-create.html" rel="nofollow noreferrer">creating lambda container images in AWS official guide. I have only changed the location of the handler to src/index.ts
When I run curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'
I get curl: (56) Recv failure: Connection reset by peer
.
Dockerfile
FROM public.ecr.aws/lambda/nodejs:14
COPY . ${LAMBDA_TASK_ROOT}
# Install NPM dependencies for function
RUN npm install
RUN npm run build
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "dist/index.handler" ]
package.json
{
...
"scripts": {
"build": "tsc",
"start": "yarn run build && node dist/index.js",
"lint": "eslint . --ext .ts",
"test": "jest"
},
...
"dependencies": {
...
"typescript": "^4.5.4"
},
"devDependencies": {
"@types/node": "14",
"jest": "^27.4.5"
}
}
src/index.ts
export const handler = (event, context, callback) => {
console.log("It ran");
return callback(null, {
statusCode: 200,
message: "Hello",
body: "Hello"
})
}
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"declaration": true,
},
"lib": ["es2015"]
}
From my understanding AWS container images uses aws-lambda-runtime-interface-emulator. Visiting their github page theres literally nothing regarding debugging. No way to get the logs, no way to understand what is running or not.
From this answer it looks like that the app inside the container doesn't have a port assigned to it, but then again, no way to debug or see logs.
When I deploy the function to aws lambda and test it, it works as expected:
Question
How can I debug what is going on? Why am I receiving a curl: (56) Recv failure: Connection reset by peer
?
Solution
The problem was that when building the image I mapped port 9000
to 8000
when the container application binds to 8080
. It solved the issue by changing:
docker run -p 9000:8000 xxxx
to
docker run -p 9000:8080 xxxx
Answered By - null Answer Checked By - Candace Johnson (WPSolving Volunteer)