# https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/ ARG RUNTIME_VERSION="3.9" ARG DISTRO_VERSION="3.15" # Stage 1 - bundle base image + runtime FROM python:${RUNTIME_VERSION}-alpine${DISTRO_VERSION} AS python-alpine # Install GCC (Alpine uses musl but we compile and link dependencies with GCC) RUN apk upgrade -U --available --no-cache && \ apk add --no-cache \ libstdc++ # Stage 2 - build function and dependencies FROM python-alpine AS build-image # Install aws-lambda-cpp build dependencies RUN apk upgrade -U --available --no-cache && \ apk add --no-cache \ build-base \ libtool \ autoconf \ automake \ libexecinfo-dev \ make \ cmake \ libcurl \ libffi-dev \ openssl-dev # cargo # Install requirements COPY requirements.txt requirements.txt RUN export MAKEFLAGS="-j$(nproc)" && \ pip install -r requirements.txt --target /app # Install our app COPY app.py /app # Stage 3 - final runtime image FROM python-alpine as release WORKDIR /app COPY --from=build-image /app /app ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ] CMD [ "app.handler" ] # Tests FROM release as test # Get aws-lambda run time emulator ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/local/bin/aws-lambda-rie RUN chmod 0755 /usr/local/bin/aws-lambda-rie && \ mkdir -p tests # Install pytest RUN pip install pytest --target /app COPY pytest.ini /app # Add our tests ADD tests /app/tests # Disable AWS API calls ENV RESOLVE_ACCOUNT="false" # Run tests RUN python -m pytest --capture=tee-sys tests