Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda doesn't automatically pick up the latest image?

I have a Lambda deployed on AWS. My Lambda is deployed uses a container to run my code. Whenever after we deploy a new image, we have to manually copy paste the URL in Lambda's configuration. Even if in ECR latest image has the URI which is already configured in Lambda, Lambda used the image from when configuration was last manually done. I was wondering if there is a way to automatically have lambda use the latest image that is deployed in ECR ?

Things I have tried:

  1. Keeping the tags and image name same during deployment, so the URI of image stays the same. I then use that URI to configure my Lambda.
  2. Used "latest" as a tag for my image.

Note: Image is being pushed to ECR by Bitbucket.

like image 855
m00s3 Avatar asked Nov 21 '25 04:11

m00s3


1 Answers

This is expected as the Lambda isn't aware a new image was pushed.

For a function defined as a container image, Lambda resolves the image tag to an image digest. In Amazon ECR, if you update the image tag to a new image, Lambda does not automatically update the function.

https://docs.aws.amazon.com/cli/latest/reference/lambda/update-function-code.html#update-function-code


After pushing the image:

docker tag my-image:latest 123456789.dkr.ecr.eu-west-1.amazonaws.com/my-image:latest
docker push 123456789.dkr.ecr.eu-west-1.amazonaws.com/my-image:latest

Also update your Lambda with the new image:

aws lambda update-function-code \
           --function-name my-lambda \
           --image-uri 123456789.dkr.ecr.eu-west-1.amazonaws.com/my-image:latest
like image 72
Stéphane Bruckert Avatar answered Nov 24 '25 03:11

Stéphane Bruckert