【发布时间】:2022-01-06 11:51:21
【问题描述】:
我有一个用 typescript 编写的小应用程序(现在只是测试一下),我想部署到 lambda。我遵循了 AWS 官方指南中creating lambda container images 的官方教程。我只是将处理程序的位置更改为src/index.ts
当我运行curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}' 时,我得到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"]
}
据我了解,AWS 容器映像使用 aws-lambda-runtime-interface-emulator。访问他们的 github 页面几乎没有关于调试的内容。无法获取日志,无法了解正在运行的内容。
从这个answer看来,容器内的应用程序没有分配给它的端口,但话又说回来,无法调试或查看日志。
当我将该函数部署到 aws lambda 并对其进行测试时,它按预期工作:
问题
如何调试正在发生的事情?为什么我会收到curl: (56) Recv failure: Connection reset by peer?
【问题讨论】:
标签: amazon-web-services docker curl aws-lambda