Reputation: 23
We provision our infrastructure through Terraform and have set up an AWS Lambda along with a Layer to hold its dependencies (we are not using any frameworks like Serverless or SAM). We are using an alias to specify which Lambda version we are invoking. Currently I am working through creating a CI/CD pipeline, using the aws lambda
CLI, and running into an issues.
Consider the scenario where we remove certain code from the Lambda function and remove a dependency from the Layer in the same MR/PR. When merging, we package up the function code and the dependency code into zip files and push them to S3. Now when deploying these changes the current steps are:
However, between steps 3.) and 4.) there is a point were the alias is pointing to the old function code (with the removed dependency still there) but the new Layer (with the dependency removed). This is far from ideal. However, swapping the steps gives a similar issue where the Lambda and Layer are not aligned.
Has anyone else had a similar issue and managed to overcome it? Spinning up a temporary Lambda during this deployment phase (however this would involve modifying the Terraform)?
Can you update layers of a Lambda without affecting the alias?
Upvotes: 2
Views: 2671
Reputation: 2203
Considering you are using GitHubActions.
appleboy/[email protected]
to deploy your lambdatheserverfault/[email protected]
Which is pretty much convenient way to update your lambda layers and also refresh all the dependant lambdas to point to this latest published layer version. You can find the documentation here and Github Marketplace.Otherwise you can use the custom scripts:
aws lambda publish-layer-version
to publish layeraws lambda update-function-code
to update functionaws lambda update-function-configuration
to update the layer to the latest version.However, consider looking at theserverfault/[email protected]
. It takes care of N-number of lambdas without having to write any iterations and custom scripts.
Upvotes: 0
Reputation: 390
After updating the Lambda Function code itself, use Lambda Function Versions to move between versions behind the alias.
New Steps:
You may have to publish an initial version of the function to start this process.
Upvotes: 5