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
It is wise to separate the image storage from the deployment process. I propose using semver for versioning the docker images. https://semver.org/
Then you can store the version number for the lambda docker image in a variable in terraform and pass it to your lambda module.
Of course this will be an extra step of running terraform apply
for deployment, but this will lock down the state of your system and will make it easier to reproduce the environment state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With