Bradley Kirton's Blog

Published on May 30, 2024

Go home

Building python site-packages for AWS lambda environments

https://docs.docker.com/engine/reference/commandline/build/#output

requirements.prod.txt

requests

Dockerfile

FROM public.ecr.aws/lambda/python:3.11 as build-stage

WORKDIR /

RUN pip install -U pip==24.0 wheel==0.43.0
COPY requirements.prod.txt requirements.prod.txt
RUN python -m pip wheel -r requirements.prod.txt --wheel-dir wheels
RUN python -m pip install --target site-packages wheels/*

FROM scratch as export-stage
COPY --from=build-stage /site-packages /
docker build --output type=local,dest=out .
 tree -L 1 out  
out
├── bin
├── certifi
├── certifi-2024.2.2.dist-info
├── charset_normalizer
├── charset_normalizer-3.3.2.dist-info
├── idna
├── idna-3.7.dist-info
├── requests
├── requests-2.32.3.dist-info
├── urllib3
└── urllib3-2.2.1.dist-info