I have deployed my lambda with Terraform. It is pointing successfully to ECR and the image runs with the expected ENTRYPOINT. However, every time I push new code to ECR, I have to go to the web console, click "Deploy New Image" else the lambda runs the old image.
Also, I tried using :latest
as the tag, but that didn't seem to help. I was able to force a new image by uploading :2
, :3
and then manually pointing the lambda at those. If there is a way to use the :latest
tag that would be a nice convenience.
I'd be happier to do this with bash or boto, but no obvious way to do so from my reading of the docs.
This similar question was shut down because lambdas used to not be backed by docker images.
Use the aws cli to update the lambda function.
Assuming you've got a profile or have appropriate credentials set in your environment you can call aws lambda update-function-code
and provide your required image-uri. As you've defined the uri already you can query the function for the value.
aws lambda update-function-code --function-name $MY_FUNC --image-uri $(aws lambda get-function --function-name $MY_FUNC | jq -r '.Code.ImageUri')
I'm using jq to extract the ImageUri but I'm sure there are as many other ways and opinions about how to go about it.
If you have a look at the entire .Code object returned from aws lambda get-function --function-name $MY_FUNC
you can check the sha256 and see that refect your updated function image.
Current docs: AWS CLI update-function-code docs