Repository navigation
On every deploy, publish a new Lambda function version - #2676
Conversation
3c6b8be to
49969e0
Compare
eahefnawy
left a comment
There was a problem hiding this comment.
@ryansb Awesome work 🙌 ... just couple of comments about logical IDs. Furthermore, could you add those new logical IDs to the resources guide docs?
Should be G2M afterwards!
There was a problem hiding this comment.
For this one as well, could move the logical ID generation into the naming.js file?
And I'd go with: FunctionNameQualifiedArn for the same reasons above
There was a problem hiding this comment.
I think the function logical ID makes more sense here though. If I just use function names, outputs look like this:
{
"Description": "Current Lambda function version",
"OutputKey": "fooQualifiedArn",
"OutputValue": "arn:aws:lambda:us-east-1:509803855674:function:bandlab-aws-vpc-resources-dev-foo:2"
},
{
"Description": "Lambda function info",
"OutputKey": "FooLambdaFunctionArn",
"OutputValue": "arn:aws:lambda:us-east-1:509803855674:function:bandlab-aws-vpc-resources-dev-foo"
},
IMO, this way (using logical ID) makes more sense:
{
"Description": "Lambda function info",
"OutputKey": "FooLambdaFunctionArn",
"OutputValue": "arn:aws:lambda:us-east-1:509803855674:function:bandlab-aws-vpc-resources-dev-foo"
},
{
"Description": "Current Lambda function version",
"OutputKey": "FooLambdaFunctionQualifiedArn",
"OutputValue": "arn:aws:lambda:us-east-1:509803855674:function:bandlab-aws-vpc-resources-dev-foo:4"
},
There was a problem hiding this comment.
could move the logical ID generation into the naming.js file?
Also I think this name is shorter and expressive enough: {FunctionName}Version{Sha} ... so we add the function name not the function logical ID. This should be enough/short identification because all function names are unique
There was a problem hiding this comment.
Should I instead be using normalizedFunctionName rather than the plain function?
There was a problem hiding this comment.
Yes, so that the first character is capitalized
|
The goal that this PR moves towards is bringing back logging/awareness that used to be in the version-0.x framework. In the old framework, you'd have one function and each stage was an alias. Now each stage has its own stack and thus own group of functions. What I want is to have each stage use an alias, so that logs are version-specific right now, in serverless v1 all logs are tagged under groups named |
d6baead to
549c38f
Compare
pmuens
left a comment
There was a problem hiding this comment.
Hey @ryansb thank you very much for this! 💯
This is a very useful addition! Just looked through the code which looks great!
I tested it successfully on my local machine with the following service:
service: simple-service
provider:
name: aws
runtime: nodejs4.3
functions:
hello:
handler: handler.hello
world:
handler: handler.worldA simple rebase should resolve the conflicts (we've refactored our test structure a little bit).
It should be GTM after that and @eahefnawy second look 👀 .
Having Lambda deploys count as distinct function versions is really helpful for logging, since it cleanly separates out logs between sources. This change adds: - Calculation of SHA256 sums of artifacts - An `AWS::Lambda::Alias` resource based on that SHA - A dependency between each deployed function to its alias - A stack output for each function `LogicalIdQualifiedArn` which is the function ARN with the version appended.
549c38f to
d7a4686
Compare
|
@pmuens Rebase done, thanks! |
|
Thanks @ryansb this works great 🙌 ... I'll merge then make a tiny change in the logical ID to keep it consistent with our pattern. Don't wanna get this PR blocked by that tiny change. Thanks again! |
|
@ryansb Nice feature! I couldn't find a valid use-case, but it kind of troubles me that someone using Serverless from now on will have legacy functions around that are actually invokable … is there a valid use-case that could lead to troubles? Do people need to do something extra e.g. define ARN's with $LATEST so older version can't be invoked --> |
|
For example in case you have an old version of a Lambda that cause a security breach. You probably want to make sure this version is gone for sure. As mentioned here there is a way of deleting a specific version. If that's the worst case then I believe it's good enough to make sure framework users are aware of this feature. Thoughts? |
|
No, they don't need to use a qualified ( There's not a |
|
Is there an option to disable the version creation? |
|
I would also like to know if there is a way to disable it |
|
Right now there isn't. Opened up an issue to track this and discuss an implementation: |
|
Great job @ryansb, thanks for it. I have a question, how can I get the version attribute from |
What did you implement:
This change publishes a Lambda version for each deploy. Now Lambda deploys count as distinct function versions, which is really helpful for logging & monitoring.
How did you implement it:
This change adds:
AWS::Lambda::Aliasresource based on that SHALogicalIdQualifiedArnwhich is thefunction ARN with the version appended.
How can we verify it:
In any serverless project, apply this patch and do a deploy. After the deploy, check in the console for the new function alias. Alternatively, use the CLI command
aws lambda list-versions-by-function --function-name yourservice-stage-functionNameand note that in addition to$LATESTthere's also a pinned version.Todos:
Is this ready for review?: YES