-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lambda): currentVersion, version.addAlias() (#6771)
It is common for AWS services to require an explicit AWS Lambda Version when referencing functions. When an `AWS::Lambda::Version` resource is defined in CloudFormation is captures the AWS Lambda configuration *at the time of the creation of the version resource. This means that if the function's configuration or code is updated, the Version resource will no longer point to the function defined in the stack. To address this, we introduce a property `function.currentVersion` which will create a new AWS::Lambda::Version resource every time the function's configuration changes. This is done by encoding a hash of the function's CloudFormation properties into the logical ID of the version resource. Additionally, this change adds `version.addAlias` which makes it easier to define an AWS Lambda alias for a version. The result is this: fn.currentVersion.addAlias('live'); We employ an approach similar to apigateway's "Deployment" resource in order to implement `currentVersion`: during "prepare", we synthesize the CloudFormation template snippet of the AWS::Lambda::Function resource, calculate an MD5 for it and append it to the logical ID of the version resource. Resolves #6750 Resolves #5334
- Loading branch information
Elad Ben-Israel
authored
Mar 25, 2020
1 parent
5cd2018
commit c94ce62
Showing
12 changed files
with
720 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { CfnResource, Stack } from "@aws-cdk/core"; | ||
import * as crypto from 'crypto'; | ||
import { Function as LambdaFunction } from "./function"; | ||
|
||
export function calculateFunctionHash(fn: LambdaFunction) { | ||
const stack = Stack.of(fn); | ||
|
||
const functionResource = fn.node.defaultChild as CfnResource; | ||
|
||
// render the cloudformation resource from this function | ||
const config = stack.resolve((functionResource as any)._toCloudFormation()); | ||
|
||
const hash = crypto.createHash('md5'); | ||
hash.update(JSON.stringify(config)); | ||
|
||
return hash.digest('hex'); | ||
} | ||
|
||
export function trimFromStart(s: string, maxLength: number) { | ||
const desiredLength = Math.min(maxLength, s.length); | ||
const newStart = s.length - desiredLength; | ||
return s.substring(newStart); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.