我有一个简单的dockerfile,我试图用awscdk部署我的项目,但是当我调用部署的lambda func时,出现了错误
ARG FUNCTION_DIR="/tmp/"
FROM public.ecr.aws/lambda/python:3.10.2023.03.21.20-arm64 as build-image
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Create function directory
RUN mkdir -p ${FUNCTION_DIR}
# Copy handler function
COPY query/*.py ${FUNCTION_DIR}
COPY prompt/*.py ${FUNCTION_DIR}
COPY starter ${FUNCTION_DIR}
COPY requirements-app.txt ${FUNCTION_DIR}
# Install the function's dependencies
RUN pip install --upgrade pip
RUN pip uninstall --yes jupyter
RUN pip install awslambdaric
RUN pip install --target ${FUNCTION_DIR} sentencepiece protobuf
RUN pip install -r ${FUNCTION_DIR}requirements-app.txt
FROM public.ecr.aws/lambda/python:3.10.2023.03.21.20-arm64
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Set working directory to function root directory
WORKDIR ${FUNCTION_DIR}
# Copy in the built dependencies
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
ENTRYPOINT [ "python", "-m", "awslambdaric" ]
# This will get replaced by the proper handler by the CDK script
CMD [ "will_be_replaced" ]
当我部署和调用lambda时
我收到错误:
2023-03-23T13:31:36.066+05:30 /var/lang/bin/python: No module named awslambdaric
2023-03-23T13:31:36.138+05:30 /var/lang/bin/python: No module named awslambdaric
2023-03-23T13:31:36.142+05:30 START RequestId: f3e3d93b-3x4b-4dd6-5db1-2cldb63cdc70 Version: $LATEST
预期:lambda成功运行
1条答案
按热度按时间wqnecbli1#
我认为问题出在安装上。根据documentation,您应该将其安装到
${FUNCTION_DIR}
,因为您需要在多阶段构建期间将此安装复制到第二个容器。因此,它应该看起来像:在我更改awslambdaric安装目标后,我能够使用您的映像调用Lambda函数。