Lambda Versioning Issues
Hello Team,
This is regarding the issue which I faced during lambda versioning.
We used AutoPublishAlias in SAM template for versioning/aliasing of lambdas which has a restriction that we cannot provide custom description to versions. Intent is to pass commit id as a description as a correlation id between lambda version and commits which generated the versions.
Resource AWS::Lambda::Version is also not proving to be any help, as on the second execution I cloudformation is failing with the message that "Update to resource type AWS::Lambda::Version is not supported.". Going through several blogs I came to know that for any new version to be published we need to define an addition AWS::Lambda::Version resource. I assume we cannot perform update to Lambda Version as it is immutable resource and we have to create new version each time.
AutoPublishAlias to accept a description will help to put a relational mapping between the lambda version and the stack which created the stack. Or if you can map commit id and display it in lambda console as Tags that will also suffice the purpose.
Many Thanks.
I think we could expose an optional VersionDescription property on Serverless::Function, that would take a description that would only be added to the generated AWS::Lambda::Version resource.
This parameter would be added here to Serverless::Function: https://github.com/awslabs/serverless-application-model/blob/master/samtranslator/model/sam_resources.py#L32
Pass parameter to version: https://github.com/awslabs/serverless-application-model/blob/master/samtranslator/model/sam_resources.py#L98 https://github.com/awslabs/serverless-application-model/blob/master/samtranslator/model/sam_resources.py#L311
Update relevant E2E and unit tests.
Edit: I Think have figured out this now. I needed to set the Description attribute of the LambdaVersion Class. and the method _generate_resource_dict of Resource Class is the one doing the work of creating the Properties dictionary of a resource. After making these changes I am able to pass a VersionDescription parameter to my SAM template and it creates the lambda versions with appropriate Descriptions.
@keetonian I am currently trying to work on this issue. But I am having a bit of a hard time figuring out how does the VesrionDescription parameter will be passed to LambdaVersion class. I tried looking at the class definition of the Resource Class. From what I understood after looking at the class definition is that the attribute parameter is used to pass all the parameters that exist outside of the Properties dictionary. But I am not able to figure out how does the value of property_types dictionary is passed to a resource ( LambdaVersion In this case). Please let me know if I am missing something in my understanding of the flow.
Hi, @keetonian My PR 835 is ready for Review. Please take a look and provide any necessary feedbacks.
Released with SAM v1.11.0!
I've noticed that if only the VersionDescription is updated (without updating CodeUri), changeset contains only modifications to Version and Alias, and its execution fails with
Update to resource type AWS::Lambda::Version is not supported.
Am I doing something wrong?
To fix this, we would need to take the VersionDescription property and add it to the hash that we put in the version resource logical id: https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/model/sam_resources.py#L387
This would force redeployments for everyone using this property, I am not sure if we want to do that at this time. A workaround for now would be to make a change to your CodeUri property, which will force a redeployment of this version resource. If you are using the SAM or AWS CLI to package your lambda function, all this takes is any simple change to your code and this property will change.
@keetonian As far as I've tested, just changing the FunctionName of an AWS::Serverless::Function property does force an update of any lambda. That's how I currently get around my issue #1267. Is there a reason that this FunctionName updating mechanism would not be preferred over using the AWS::Lambda::Version?
The original issue was addressed in https://github.com/awslabs/serverless-application-model/pull/835, and the follow-up question about updating version when VersionDescription changes is covered by https://github.com/aws/serverless-application-model/issues/413; closing.