-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add versioning to continuous deployment model #41
Comments
We are aware of this issue. SAM doesn't support Lambda function versioning yet. |
I'm having the same issue after finallybgetting my pipeline working. Should we be able to use cfn native lambda support to version lambdas as a workaround? |
@stuartstevenson yes you can use CFN native lambda resource as a workaround |
Thank you for the response @sanathkr. I have just tested out a CFN template with a function, version and alias resource and when I updated the function the version remained the same. I realise now I have made some large and incorrect assumptions, namely that CFN has the same feature set and behaviour of the API, and the lambda version was doing some magic under the hood. I'm pondering if it would not be too much effort to create a custom resource to check the state of the codesha against the last version, and if it varies then update |
A Lambda version is an immutable resource which is created by AWS::Lambda::Version CFN resource type. To create a new Lambda version, you need to add a new AWS::Lambda::Version resource to your CFN template with a different resource name. This behavior makes it hard for SAM to automatically create versions for you. SAM template should somehow automatically store all earlier version resources |
This article published on the 20th is a nice example of how to build a full CD pipeline using SAM https://aws.amazon.com/blogs/compute/continuous-deployment-for-serverless-applications/. Interestingly it doesn't use versions or aliases. I've noticed that Serverless works in a similar way of creating an api and lambda per 'stage'. Is the aim with SAM to use Versions and Aliases instead of duplicating resources? |
Versions & Aliases are powerful tools to help you build a production service on Lambda. SAM certainly wants to explore the possibility of supporting it |
@jabalsad I ran into the same difficulty and resolved it by implementing custom actions in CodePipeline for versioning and aliasing the Lambda Functions that are created/updated by my CloudFormation changeset executions. I published the functions on GitHub but have not yet had time to add documentation or write up a blog post about them. In case they help you in the meantime: https://github.com/qblu/codepipeline-lambda-versioner They both use this parent package which provides a generic way to build CodePipeline custom actions as Node functions: https://github.com/qblu/codepipeline-custom-action |
@sanathkr I recently ran into this same issue. Is there an updated ETA on when versioning and aliases will be addressed in SAM? Thanks! |
@sanathkr I am also looking versioning and alias in SAM, wondering does these functionalities are supported by SAM now |
Seems like SAM could implement updating Lambda Versions and Aliases the same way it handles ApiGateway Deployments, by generating a new unique logical id each time. |
Any ETA on the feature-request? |
@lafiosca But that means earlier versions will be deleted, which is undesirable. I don't have an ETA yet. We are working with CloudFormation to find a workaround to the problem I described earlier. |
@sanathkr why would the old versions need to be deleted? Seems like we just publish a new version and then re-point the API resource to use these. I really like the approach described in https://stackoverflow.com/a/41455577/2962507 (1st option), similar to what @lafiosca described. I.e. we DON'T use the inconvenient
Elsewhere in the template, we can refer both to the function Arn attribute, as well as the new Version attribute (which can actually be set to Are there any show stoppers for this? Seems like a simple enough approach that is both directly implementable using existing CloudFormation capabilities (e.g. custom resources), and doesn't break existing behavior. |
@sanathkr I haven't thought this through fully yet, but would DeletionPolicy: Retain help with that? |
@dinvlad Yeah, custom resources will solve the "I want to always point to latest version" problem. But if you want to track and point to multiple versions, the template definition becomes less intuitive. Instead of GUID, we can use Lambda function's CodeSHA if you want to auto-publish on every change. |
Agreed, a code hash would be preferable. I actually ended up calculating and passing it to my template as a parameter. |
+1. The SHA-256 code hash is how others like Terraform calculate changes. |
It's clunky, but I managed to solve this issue this way: AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Resources:
SomeFunction:
Type: "AWS::Serverless::Function"
Properties:
FunctionName: !Sub "${AWS::StackName}-someFunc"
Handler: "index.handler"
CodeUri: "."
Runtime: "nodejs6.10"
MemorySize: 256
Timeout: 5
Environment:
Variables:
ANOTHER_FUNC_VERSION: !Sub "${AnotherFunctionV2.Version}"
Policies:
- AWSLambdaBasicExecutionRole
AnotherFunction:
Type: "AWS::Serverless::Function"
Properties:
FunctionName: !Sub "${AWS::StackName}-anotherFunc"
Handler: "magic.handler"
CodeUri: "."
Runtime: "nodejs6.10"
MemorySize: 256
Timeout: 5
Policies:
- AWSLambdaBasicExecutionRole
AnotherFunctionV2:
Type: "AWS::Lambda::Version"
Properties:
FunctionName: !Ref AnotherFunction So in this scenario, |
This is now available in SAM. Checkout: https://github.com/awslabs/serverless-application-model/releases/tag/1.3.0 |
@sanathkr Thank you (and the team) for your hard work on this!! This is absolutely invaluable. PS: Hope you didn't actually relocate to Alaska.. 😉 |
Lol we didn't :) |
Kudos! Looking forward to exploring this stuff in the coming days! |
Guys, thanx for releasing versioning with SAM. Can I have some help with what is the better way to add policies allowing Lambda versioning to corresponding role? Simple adding Do I get it right that SAM will not manage it automatically? |
nicely done @sanathkr! |
@quarryman if u manually attach these roles to your CloudFormationWorker role, it will be able to work. |
Hi, is it possible to set Lambda version "FunctionVersione123abc456": {
"Type": "AWS::Lambda::Version",
"DeletionPolicy": "Retain",
"Properties": {
"FunctionName": {
"Ref": "Function"
}
}
}, Something like |
Hi,
Uncertain where best to propose this question, but this seems like a good place to start. I've been playing with automatically deploying lambda functions using this serverless application model + cloudformation, based off this document [1]. One thing I've noticed is that with every change set that code pipeline creates in cloudformation, I don't get a new version of the lambda function. How do you propose I add some kind of versioning (perhaps correlated with the
CodeUri
) to the cloudformation change set?I appreciate your input on the matter.
[1] http://docs.aws.amazon.com/lambda/latest/dg/automating-deployment.html
The text was updated successfully, but these errors were encountered: