如何使用“python:alpine”构建自定义映像以与 AWS Lambda 一起使用?

use*_*542 1 docker dockerfile aws-lambda alpine-linux

本页介绍如何使用“python:buster”创建与 Lambda 一起使用的 Docker 映像

https://docs.aws.amazon.com/lambda/latest/dg/images-create.html#images-create-from-alt

我想对“python:alpine”做同样的事情

但在尝试安装“libcurl4-openssl-dev”时遇到问题


有人成功构建了用于 lambda 的“python:alpine”图像吗?

小智 6

这个软件包“libcurl4-openssl-dev”属于 debian/ubuntu 系列,它不存在于 Alpine linux 发行版中,仅作为 libcurl 存在。顺便说一句,您可以从这里搜索 Alpine 软件包https://pkgs.alpinelinux.org/packages

如果您想使用 ALPINE 实现自定义 Lambda Python 运行时,那么此 Dockerfile 可能有用。我做了一些小小的修改以适应 alpine linux 世界。

# Define function directory
ARG FUNCTION_DIR="/function"

FROM python:alpine3.12 AS python-alpine 
RUN apk add --no-cache \
    libstdc++

FROM python-alpine as build-image

# Install aws-lambda-cpp build dependencies
RUN apk add --no-cache \
    build-base \
    libtool \ 
    autoconf \ 
    automake \ 
    libexecinfo-dev \ 
    make \
    cmake \ 
    libcurl

# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Create function directory
RUN mkdir -p ${FUNCTION_DIR}

# Copy function code
COPY app/* ${FUNCTION_DIR}

# Install the runtime interface client
RUN python -m pip install --upgrade pip
RUN python -m pip install \
        --target ${FUNCTION_DIR} \
        awslambdaric

# Multi-stage build: grab a fresh copy of the base image
FROM python-alpine

# 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 build image dependencies
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}

ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
CMD [ "app.handler" ]
Run Code Online (Sandbox Code Playgroud)