Create a lambda from docker image/In this video we'll learn how to overcome the lambda size limit and deploy a lambda using Docker Image and Amazon ECR. We will create a docker file and build docker image using this docker file. And then push the docker image to AWS ECR and create a lambda using docker image. For this we need to complete below prerequisites first:
Install AWS cli on Windows: • Install AWS CLI on Windows
Install and set up Docker Desktop on Windows: • Install Docker Desktop on Windows
Sample Python:
import sys
def handler(event, context):
return 'Hello from AWS Lambda using Python' + sys.version + '!'
Sample docker file:
FROM public.ecr.aws/lambda/python:3.11
Copy requirements.txt
COPY requirements.txt ${LAMBDA_TASK_ROOT}
Copy function code
COPY lambda_function.py ${LAMBDA_TASK_ROOT}
Install the specified packages
RUN pip install -r requirements.txt
Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "lambda_function.handler" ]
Sample Docker Commands:
1. docker build --platform linux/amd64 -t docker-image:test .
2. aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 111122223333.dkr.ecr.us-east-1.amazonaws.com
3. aws ecr create-repository --repository-name hello-world --image-scanning-configuration scanOnPush=true --image-tag-mutability MUTABLE
4. docker tag docker-image:test 111122223333.dkr.ecr.us-east-1.amazonaws.com/hello-world:latest
5. docker push 111122223333.dkr.ecr.us-east-1.amazonaws.com/hello-world:latest
6. create the function using console
More information can be found in AWS documentation:
https://docs.aws.amazon.com/lambda/la...