-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(lambda): function version ignores layer version changes #20150
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
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
6061750
start
kaizencc ca89e1a
more progress
kaizencc 6562425
add feature flag to lock lambda layer order
kaizencc 5bb2c19
layer stuff
kaizencc c5af8f5
merge
kaizencc 97f7f8c
revive branch and fix test
kaizencc 144b38d
bake layer version into function version hash
kaizencc 2bac2c9
add docstring
kaizencc 5d45ae6
Merge branch 'master' into conroy/lambdalayer
kaizencc 78fd23b
update test to better capture old behavior
kaizencc 56db632
update integ tests
kaizencc a050989
Merge branch 'master' into conroy/lambdalayer
kaizencc 68d06b3
Merge branch 'master' of https://github.com/aws/aws-cdk into conroy/l…
kaizencc 3f62785
Merge branch 'master' into conroy/lambdalayer
Naumel 4e6b561
Merge branch 'master' into conroy/lambdalayer
kaizencc 0068a22
functionversionupgrade aspect
kaizencc 8df2619
Merge branch 'master' of https://github.com/aws/aws-cdk into conroy/l…
kaizencc d850443
update integ tests and generalize functionversionupgrade
kaizencc 404fcd3
add documentation
kaizencc 594a590
Merge branch 'conroy/lambdalayer' of https://github.com/aws/aws-cdk i…
kaizencc dc4a0d2
fix for imported layers
kaizencc 757ef2d
update triggers test
kaizencc a0a617b
update cloudfront snapshots
kaizencc 5967433
update codedeploy snapshots
kaizencc 3404aa3
Merge branch 'master' into conroy/lambdalayer
kaizencc 47f7115
make layers internal api
kaizencc 3be936f
readme updates
kaizencc 72a3197
bake version arn into layer hash
kaizencc de03832
Merge branch 'master' into conroy/lambdalayer
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
packages/@aws-cdk/aws-cloudfront/test/distribution-lambda.integ.snapshot/cdk.out
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| {"version":"17.0.0"} | ||
| {"version":"20.0.0"} |
This file contains hidden or 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
4 changes: 2 additions & 2 deletions
4
packages/@aws-cdk/aws-cloudfront/test/distribution-lambda.integ.snapshot/integ.json
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
2 changes: 1 addition & 1 deletion
2
packages/@aws-cdk/aws-codedeploy/test/lambda/deployment-group.integ.snapshot/cdk.out
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| {"version":"17.0.0"} | ||
| {"version":"20.0.0"} |
4 changes: 2 additions & 2 deletions
4
packages/@aws-cdk/aws-codedeploy/test/lambda/deployment-group.integ.snapshot/integ.json
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,8 +6,10 @@ import * as kms from '@aws-cdk/aws-kms'; | |
| import * as logs from '@aws-cdk/aws-logs'; | ||
| import * as sns from '@aws-cdk/aws-sns'; | ||
| import * as sqs from '@aws-cdk/aws-sqs'; | ||
| import { Annotations, ArnFormat, CfnResource, Duration, Fn, Lazy, Names, Size, Stack, Token } from '@aws-cdk/core'; | ||
| import { Annotations, ArnFormat, CfnResource, Duration, FeatureFlags, Fn, IAspect, IConstruct, Lazy, Names, Size, Stack, Token } from '@aws-cdk/core'; | ||
| import { LAMBDA_RECOGNIZE_LAYER_VERSION } from '@aws-cdk/cx-api'; | ||
| import { Construct } from 'constructs'; | ||
| import { AliasOptions, Alias } from './alias'; | ||
| import { Architecture } from './architecture'; | ||
| import { Code, CodeConfig } from './code'; | ||
| import { ICodeSigningConfig } from './code-signing-config'; | ||
|
|
@@ -26,7 +28,6 @@ import { Runtime } from './runtime'; | |
| // keep this import separate from other imports to reduce chance for merge conflicts with v2-main | ||
| // eslint-disable-next-line | ||
| import { LogRetentionRetryOptions } from './log-retention'; | ||
| import { AliasOptions, Alias } from './alias'; | ||
| import { addAlias } from './util'; | ||
|
|
||
| /** | ||
|
|
@@ -637,10 +638,10 @@ export class Function extends FunctionBase { | |
|
|
||
| public readonly permissionsNode = this.node; | ||
|
|
||
|
|
||
| protected readonly canCreatePermissions = true; | ||
|
|
||
| private readonly layers: ILayerVersion[] = []; | ||
| /** @internal */ | ||
| public readonly _layers: ILayerVersion[] = []; | ||
|
|
||
| private _logGroup?: logs.ILogGroup; | ||
|
|
||
|
|
@@ -777,7 +778,7 @@ export class Function extends FunctionBase { | |
| zipFile: code.inlineCode, | ||
| imageUri: code.image?.imageUri, | ||
| }, | ||
| layers: Lazy.list({ produce: () => this.layers.map(layer => layer.layerVersionArn) }, { omitEmpty: true }), // Evaluated on synthesis | ||
| layers: Lazy.list({ produce: () => this.renderLayers() }), // Evaluated on synthesis | ||
| handler: props.handler === Handler.FROM_IMAGE ? undefined : props.handler, | ||
| timeout: props.timeout && props.timeout.toSeconds(), | ||
| packageType: props.runtime === Runtime.FROM_IMAGE ? 'Image' : undefined, | ||
|
|
@@ -909,7 +910,7 @@ export class Function extends FunctionBase { | |
| */ | ||
| public addLayers(...layers: ILayerVersion[]): void { | ||
| for (const layer of layers) { | ||
| if (this.layers.length === 5) { | ||
| if (this._layers.length === 5) { | ||
| throw new Error('Unable to add layer: this lambda function already uses 5 layers.'); | ||
| } | ||
| if (layer.compatibleRuntimes && !layer.compatibleRuntimes.find(runtime => runtime.runtimeEquals(this.runtime))) { | ||
|
|
@@ -920,8 +921,7 @@ export class Function extends FunctionBase { | |
| // Currently no validations for compatible architectures since Lambda service | ||
| // allows layers configured with one architecture to be used with a Lambda function | ||
| // from another architecture. | ||
|
|
||
| this.layers.push(layer); | ||
| this._layers.push(layer); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1050,6 +1050,18 @@ Environment variables can be marked for removal when used in Lambda@Edge by sett | |
| this.role?.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('CloudWatchLambdaInsightsExecutionRolePolicy')); | ||
| } | ||
|
|
||
| private renderLayers() { | ||
| if (!this._layers || this._layers.length === 0) { | ||
| return undefined; | ||
| } | ||
|
|
||
| if (FeatureFlags.of(this).isEnabled(LAMBDA_RECOGNIZE_LAYER_VERSION)) { | ||
| this._layers.sort(); | ||
| } | ||
|
|
||
| return this._layers.map(layer => layer.layerVersionArn); | ||
| } | ||
|
|
||
| private renderEnvironment() { | ||
| if (!this.environment || Object.keys(this.environment).length === 0) { | ||
| return undefined; | ||
|
|
@@ -1269,3 +1281,23 @@ function undefinedIfNoKeys<A>(struct: A): A | undefined { | |
| const allUndefined = Object.values(struct).every(val => val === undefined); | ||
| return allUndefined ? undefined : struct; | ||
| } | ||
|
|
||
| /** | ||
| * Aspect for upgrading function versions when the feature flag | ||
| * provided feature flag present. This can be necessary when the feature flag | ||
| * changes the function hash, as such changes must be associated with a new | ||
| * version. This aspect will change the function description in these cases, | ||
| * which "validates" the new function hash. | ||
| */ | ||
| export class FunctionVersionUpgrade implements IAspect { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added this Aspect that should help users update their existing lambdas |
||
| constructor(private readonly featureFlag: string, private readonly enabled=true) {} | ||
|
|
||
| public visit(node: IConstruct): void { | ||
| if (node instanceof Function && | ||
| this.enabled === FeatureFlags.of(node).isEnabled(this.featureFlag)) { | ||
| const cfnFunction = node.node.defaultChild as CfnFunction; | ||
| const desc = cfnFunction.description ? `${cfnFunction.description} ` : ''; | ||
| cfnFunction.addPropertyOverride('Description', `${desc}version-hash:${calculateFunctionHash(node)}`); | ||
| } | ||
| }; | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated this readme