Skip to content

Commit

Permalink
Use EFS for libs
Browse files Browse the repository at this point in the history
  • Loading branch information
abarciauskas-bgse committed Nov 6, 2023
1 parent 314cb81 commit fc3059c
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions infrastructure/aws/lambda/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,18 @@ COPY titiler/ titiler/
# we have to force using old package version that seems `almost` compatible with Lambda env botocore
# https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
RUN pip install --upgrade pip
RUN pip install . "mangum>=0.10.0" "botocore==1.29.76" "aiobotocore==2.5.0" -t /asset --no-binary pydantic
RUN pip install . "mangum>=0.10.0" "botocore==1.29.76" "aiobotocore==2.5.0" -t /mnt/efs/libraries --no-binary pydantic

# Reduce package size and remove useless files
RUN cd /asset && find . -type f -name '*.pyc' | while read f; do n=$(echo $f | sed 's/__pycache__\///' | sed 's/.cpython-[0-9]*//'); cp $f $n; done;
RUN cd /asset && find . -type d -a -name '__pycache__' -print0 | xargs -0 rm -rf
RUN cd /asset && find . -type f -a -name '*.py' -print0 | xargs -0 rm -f
RUN find /asset -type d -a -name 'tests' -print0 | xargs -0 rm -rf
RUN rm -rdf /asset/numpy/doc/ /asset/bin /asset/geos_license /asset/Misc
RUN rm -rdf /asset/boto3*
RUN rm -rdf /asset/botocore*
RUN rm -rdf /asset/pyyaml*
RUN rm -rdf /asset/partd*
RUN rm -rdf /asset/MarkupSafe*
RUN rm -rdf /asset/zipp*
RUN rm -rdf /asset/jmespath*
RUN rm -rdf /asset/idna*
RUN rm -rdf /asset/cligj*
RUN cd /mnt/efs/libraries && find . -type f -name '*.pyc' | while read f; do n=$(echo $f | sed 's/__pycache__\///' | sed 's/.cpython-[0-9]*//'); cp $f $n; done;
RUN cd /mnt/efs/libraries && find . -type d -a -name '__pycache__' -print0 | xargs -0 rm -rf
RUN cd /mnt/efs/libraries && find . -type f -a -name '*.py' -print0 | xargs -0 rm -f
RUN find /mnt/efs/libraries -type d -a -name 'tests' -print0 | xargs -0 rm -rf
RUN rm -rdf /mnt/efs/libraries/numpy/doc/ /mnt/efs/libraries/bin /mnt/efs/libraries/geos_license /mnt/efs/libraries/Misc
RUN rm -rdf /mnt/efs/libraries/boto3*
RUN rm -rdf /mnt/efs/libraries/botocore*
ENV PYTHONPATH=/mnt/efs/libraries

COPY infrastructure/aws/lambda/handler.py /asset/handler.py
COPY infrastructure/aws/lambda/handler.py /mnt/efs/libraries/handler.py

CMD ["echo", "hello world"]

0 comments on commit fc3059c

Please sign in to comment.