So I'm often making serverless Python programs on AWS Lambda, and often I need to add dependencies. You can add these using a zip file or a Dockerfile (see aws documentation). Now I think a zip file works just fine, but a Dockerfile is of course a much newer and more advanced technology. However I'm can't really think of any advantages that it offers for this specific usecase.
Which do you prefer and why?
Example zip pipeline:
pip install --target ./package requests boto3 bs4
cd package; zip -r ../stonksoverflow.zip .
cd ..; zip -g stonksoverflow.zip lambda_function.py
aws lambda create-function --function-name lambda_function --zip-file fileb://stonksoverflow.zip --handler lambda_function.lambda_handler --runtime python3.8 --role arn:aws:iam::123456789:role/stonksoverflow
Example Docker pipeline:
FROM public.ecr.aws/lambda/python:3.8
RUN pip3 install requests bs4 boto3
COPY lambda_function.py ${LAMBDA_TASK_ROOT}
CMD [ "stonksoverflow.handler" ]
aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 123456789.dkr.ecr.eu-west-1.amazonaws.com
docker tag stonksoverflow:latest 331730032056.dkr.ecr.eu-west-1.amazonaws.com/stonksoverflow:latest
docker push 123456789.dkr.ecr.eu-west-1.amazonaws.com/wstonksoverflow:latest