我正在建立一个lambda去噪音频文件。Python soundfile使用libsndfile文件系统依赖项,这是我通过apt在我的DockerFile中安装的。容器在本地运行得很好,但是当我在部署到lambda之后运行它时,它显示"errorMessage":"sndfile library not fine“,"errorType":"OSError",。这是我的Dockerfile,
# Define global args
ARG FUNCTION_DIR="/home/app"
ARG RUNTIME_VERSION="3.7"
# Stage 1 - bundle base image + runtime
# Grab a fresh copy of the image and install GCC if not installed ( In case of debian its already installed )
FROM python:${RUNTIME_VERSION} AS python-3.7
# Stage 2 - build function and dependencies
FROM python-3.7 AS build-image
# Install aws-lambda-cpp build dependencies ( In case of debian they're already installed )
RUN apt-get update && apt-get install -y \
g++ \
make \
cmake \
unzip \
libcurl4-openssl-dev
# Include global args in this stage of the build
ARG FUNCTION_DIR
ARG RUNTIME_VERSION
# Create function directory
RUN mkdir -p ${FUNCTION_DIR}
# Copy handler function
COPY app/requirements.txt ${FUNCTION_DIR}/app/requirements.txt
# Optional – Install the function's dependencies
RUN python${RUNTIME_VERSION} -m pip install -r ${FUNCTION_DIR}/app/requirements.txt --target ${FUNCTION_DIR}
# Install Lambda Runtime Interface Client for Python
# RUN python${RUNTIME_VERSION} -m pip install awslambdaric --target ${FUNCTION_DIR}
# Stage 3 - final runtime image
# Grab a fresh copy of the Python image
FROM python-3.7
# 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}
# Install librosa system dependencies
RUN apt-get update -y && apt-get install -y \
libsndfile1 \
ffmpeg
# (Optional) Add Lambda Runtime Interface Emulator and use a script in the ENTRYPOINT for simpler local runs
# ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/bin/aws-lambda-rie
# COPY entry.sh /
COPY app ${FUNCTION_DIR}/app
ENV NUMBA_CACHE_DIR=/tmp
RUN ln -s /usr/lib/x86_64-linux-gnu/libsndfile.so.1 /usr/local/bin/libsndfile.so.1
# enable below for local testing
# COPY events ${FUNCTION_DIR}/events
# COPY .env ${FUNCTION_DIR}
# RUN chmod 755 /usr/bin/aws-lambda-rie /entry.sh
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
CMD [ "app.handler.lambda_handler" ]下面是我的lambda配置
{
"FunctionName": "DenoiseAudio",
"FunctionArn": "arn:aws:lambda:us-east-1:xxxx:function:DenoiseAudio",
"Role": "arn:aws:iam::xxxx:role/lambda-s3-role",
"CodeSize": 0,
"Description": "",
"Timeout": 120,
"MemorySize": 128,
"LastModified": "2021-01-25T13:41:00.000+0000",
"CodeSha256": "84ae6e6e475cad50ae5176d6176de09e95a74d0e1cfab3df7cf66a41f65e4e19",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "43c6e7c4-27a8-4c6d-8c32-c1e074d40a62",
"State": "Active",
"LastUpdateStatus": "Successful",
"PackageType": "Image",
"ImageConfigResponse": {}
}发布于 2021-08-02 12:55:41
现在已经解决了。事实证明错误日志是错误的。发生这种情况是因为lambda没有分配足够的内存。一旦我分配了足够的内存,问题就消失了。
发布于 2021-01-28 02:57:26
看起来您并不是从包含runtime interface client的亚马逊网络服务托管base images构建的。看起来您也没有手动添加它。我的建议是从Python3.7或Python3.8基础镜像开始(这两个镜像都找到了here)。然后根据需要添加其他库。我还鼓励您查看AWS SAM实现对Lambda函数的容器镜像支持。它会让你的生活更轻松:)。你可以在这里找到它的视频演示:https://youtu.be/3tMc5r8gLQ8?t=1390。
如果您仍然想从头开始构建映像,请查看文档,这些文档将指导您完成找到的需求here。
https://stackoverflow.com/questions/65886454
复制相似问题