|
| 1 | +# First stage: setting the base image |
| 2 | +ARG PYTHON_VERSION="" |
| 3 | + |
| 4 | +FROM public.ecr.aws/lambda/python:${PYTHON_VERSION} AS base_build |
| 5 | + |
| 6 | +# Second stage: building the layer |
| 7 | +FROM base_build |
| 8 | + |
| 9 | +ARG PYTHON_VERSION="" |
| 10 | +ARG PACKAGE_SUFFIX="" |
| 11 | + |
| 12 | +USER root |
| 13 | +WORKDIR /tmp |
| 14 | + |
| 15 | +# PACKAGE_SUFFIX = '[all]==2.0.0' |
| 16 | +# PACKAGE_SUFFIX = '[all] @ git+https://github.com/awslabs/aws-lambda-powertools-python@v2' |
| 17 | +# PACKAGE_SUFFIX = '[all]' |
| 18 | +# PACKAGE_SUFFIX = '=='2.0.0' |
| 19 | +# PACKAGE_SUFFIX = ' @ git+https://github.com/awslabs/aws-lambda-powertools-python@v2' |
| 20 | +# PACKAGE_SUFFIX = '' |
| 21 | + |
| 22 | +# PYTHON_VERSION = 3.8, 3.9, 3.10, 3.11, and 3.12 |
| 23 | + |
| 24 | +# Installing libs based on base image; We must use dnf for AL2023 (Python 3.12+) |
| 25 | +COPY install_libraries.sh . |
| 26 | +RUN ls -la |
| 27 | +RUN chmod a+x /tmp/install_libraries.sh |
| 28 | +RUN /bin/sh /tmp/install_libraries.sh |
| 29 | + |
| 30 | +# Install cython to generate native code |
| 31 | +RUN pip install --upgrade pip wheel && pip install --upgrade cython |
| 32 | +# Optimize binary size and strip debugging symbols for optimum size |
| 33 | +RUN CFLAGS="-Os -g0 -s" pip install -t /asset/python "aws-lambda-powertools${PACKAGE_SUFFIX}" |
| 34 | + |
| 35 | +# Removing nonessential files |
| 36 | +RUN cd /asset/python && \ |
| 37 | + # remove boto3 and botocore (already available in Lambda Runtime) |
| 38 | + rm -rf boto* && \ |
| 39 | + # remove boto3 dependencies |
| 40 | + rm -rf s3transfer* *dateutil* urllib3* six* jmespath* && \ |
| 41 | + # remove debugging symbols |
| 42 | + find . -name '*.so' -type f -exec strip "{}" \; && \ |
| 43 | + # remove tests |
| 44 | + find . -wholename "*/tests/*" -type f -delete && \ |
| 45 | + # remove python bytecode |
| 46 | + find . -regex '^.*\(__pycache__\|\.py[co]\)$' -delete |
0 commit comments