aws / aws-lambda-base-images

Apache License 2.0
676 stars 110 forks source link

Missing `find` command in `lambda/python:3.12` image #196

Open tlinhart opened 1 month ago

tlinhart commented 1 month ago

I'm trying to decrease my Docker image size by cleaning the cache files after installing the requirements but the build fails due to a missing find command. This is my Dockerfile:

FROM public.ecr.aws/lambda/python:3.12

COPY requirements.txt /tmp
RUN pip install -t ${LAMBDA_TASK_ROOT} -r /tmp/requirements.txt \
 && find ${LAMBDA_TASK_ROOT} -regex '^.*\(__pycache__\|\.py[co]\)$' -delete

COPY lambda_function.py ${LAMBDA_TASK_ROOT}

CMD ["lambda_function.lambda_handler"]

Looking inside the running container, it seems that other usual files are present in /usr/bin.

leandrodamascena commented 1 month ago

Hi @tlinhart! Good to see you here dude! I ran into this same issue like 1 hour ago and was trying to understand what's going on. Up until Python 3.11 Runtime, Lambda images are using Amazon Linux 2 which comes with the findutils package by default, but starting from Python 3.12 it is using Amazon Linux 2023 and it seems that the findutils package is not installed by default.

Python 3.11

➜ docker run --rm -it --entrypoint bash public.ecr.aws/lambda/python:3.11
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
bash-4.2# rpm -qa | grep find
findutils-4.5.11-6.amzn2.x86_64
bash-4.2# 

Python 3.12

➜ docker run --rm -it --entrypoint bash public.ecr.aws/lambda/python:3.12
bash-5.2# rpm -qa |grep find
bash-5.2# 

To solve this problem you can install findutils package in your image, add this line RUN dnf install -y findutils before the pip install line and you'll be able to use the find command.

tlinhart commented 1 month ago

Hey @leandrodamascena! I was a bit surprised that find was not present to be honest :-) Anyway, thanks for your suggestion, will give it a try.