[英]Unable to run lambda in docker image
I currently have an AWS Lambda that I've been working on that I would like to build and run from a docker image.我目前有一个 AWS Lambda,我一直在研究它,我想从 docker 图像构建和运行它。 I'm using the
aws-lambda-node:16
image as my base image.我使用
aws-lambda-node:16
图像作为我的基本图像。 But I can't seem to get the docker image to properly pick up the handler from my javascript file to run the lambda.但我似乎无法获得 docker 图像以从我的 javascript 文件中正确选取处理程序来运行 lambda。
I have tested the lambda's execution outside the docker image with lambda-local and the lambda runs fine in my local environment.我已经使用lambda-local测试了 lambda 在 docker 图像之外的执行,并且 lambda 在我的本地环境中运行良好。 It just seems that something is up with the docker container.
似乎 docker 容器出了问题。
My Dockerfile:我的 Dockerfile:
FROM amazon/aws-lambda-nodejs:16
COPY dist/blacklist-ips/app.js ${LAMBDA_TASK_ROOT}
COPY package.json pnpm-lock.yaml ${LAMBDA_TASK_ROOT}/
RUN npm i -g pnpm && pnpm install --production
CMD [ "app.handle" ]
My Webpack config:我的 Webpack 配置:
import { resolve } from 'path';
import { default as webpack } from 'webpack';
import TerserPlugin from 'terser-webpack-plugin';
const config = (env: any, argv: any): webpack.Configuration => {
return {
mode: env.production ? 'production' : 'development',
entry: {
'blacklist-ips': resolve(__dirname, 'src', 'blacklist-ips', 'blacklist-ips.ts')
},
output: {
path: resolve(__dirname, 'dist'),
filename: '[name]/app.js',
libraryTarget: 'commonjs2'
},
devtool: false,
target: 'node',
externals: [
'@aws-sdk/client-cloudwatch-logs',
'@aws-sdk/client-wafv2',
'luxon',
'tslib'
],
resolve: {
extensions: [ '.ts', '.js', '.json' ]
},
module: {
rules: [
{
test: /.ts$/,
loader: 'ts-loader'
}
]
},
optimization: {
minimize: env.production,
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
mangle: false
}
})
]
}
}
}
export default config;
My handler function is being properly exported in the webpack bundle:我的处理程序 function 正在 webpack 包中正确导出:
const handler = async () => {
...lambda logic
};
exports.handler = handler;
I'm stumped as to why it's not working correctly with the Docker container...我很困惑为什么它不能与 Docker 容器一起正常工作......
Your CMD
is app.handle
while your function name is handler
.你的
CMD
是app.handle
而你的 function 名字是handler
。 You should change the CMD
to be app.handler
.您应该将
CMD
更改为app.handler
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.