user10664542
user10664542

Reputation: 1316

How to build a custom image using 'python:alpine' for use with AWS Lambda?

This page describes creating a Docker image for use with Lambda using 'python:buster'

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

I would like to do the same with 'python:alpine'

but get problems when trying to install 'libcurl4-openssl-dev'


Has anyone successfully built a 'python:alpine' image for use in lambda?

Upvotes: 1

Views: 2878

Answers (1)

Burak Cansizoglu
Burak Cansizoglu

Reputation: 174

This package "libcurl4-openssl-dev" belongs to debian/ubuntu family which is not exist in Alpine linux distro but as only libcurl. Btw you can search Alpine packages from here https://pkgs.alpinelinux.org/packages

If you want to achieve a custom Lambda Python runtime with ALPINE then this Dockerfile might useful. I did slight modifications to fit into the alpine linux world.

# 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" ]

Upvotes: 7

Related Questions