The situation is that I have a load of aws lambda functions (using node js 8.10) that all do something very different and they're all deployed using CloudFormation.
They all share a few functions which are very complex.
At the moment, if the common code changes, which is fairly frequent, I replicate the common code between each of the projects (including source control) and then redeploy each of the functions. This has always felt wrong.
Now we have lambda layers - yay! or yay?
Great, so now I can maintain the code in a single repo - tick But the rest of the process is not really any better and possibly worse...
If I put the layer in a CloudFormation template and export the ARN for import into the lambda function templates then the exported ARN is only ever for version 1 of the layer.
I could form the ARN without the version using the Sub function and then add the version in the lamda function CloudFormation templates. But, whenever there's a change to the common code, I'd still need to update all downstream lambda function CloudFormation templates to add the latest version.
I could script it but it's still a massive PITA and doesn't really save much effort. I'd need to get the latest of each lambda function project update the version number, commit back to the repo, pr, merge, blah blah blah.
Is there no other way of always using the latest version of a layer?
The process of adding dependencies to an AWS Lambda consists of two steps. First, we have to install the dependencies in the source code directory. Later, we have to package our lambda function into a zip file that also contains all of the dependency files.
To change the runtime, you create a new container image. When you use a . zip file archive for the deployment package, you choose a runtime when you create the function. To change the runtime, you can update your function's configuration.
You can't change the configuration (which includes environment variables) or function code in a published Lambda function version. To change the environment variables of a published Lambda function version, you must first change the current, unpublished function version ($LATEST). Then, publish a new function version.
Using Serverless to deploy and CloudFormation Outputs can help with this situation.
resources:
Outputs:
MYOUTPUTNAME:
Value:
Ref: MYLAYERLambdaLayer # LambdaLayer is a required suffix
functions:
...other required function keys in serverless
layers:
- ${cf:NAME_OF_STACK.MYOUTPUTNAME}
sls deploy --force
). Redeploying just the function will not update the output reference.Note: if you use Output Export Names, you will run into an error redeploying the layer service as the current version is referenced. Therefore, it's better to use a reference to the stack output which doesn't cause this error.
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