Skip to content

Commit 356f302

Browse files
authored
feat(lambda): L2 constructs for SnapStart (#26761)
Closes #23153 - Support SnapStart on L2 constructs by setting `snapStart: lambda.SnapStartConfig.ON_PUBLISHED_VERSIONS`. This value will be converted to `SnapStart: {ApplyOn: 'PublishedVersions',}` in template. - Supports checking limitation stated in [SnapStart](https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html) except for Provisioned Concurrency which is at version level and can't be checked with function level props. - This PR is heavily inspired by [PR](#23196) from @DeerajTheepshi and [discussion](#23153 (comment)) in the issue, Thank you ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b1f4e27 commit 356f302

15 files changed

+492
-86
lines changed
Binary file not shown.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda.js.snapshot/aws-cdk-lambda-1.assets.json

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
{
2-
"version": "21.0.0",
2+
"version": "33.0.0",
33
"files": {
4-
"811c02a1b423ba875c9e41bef2453805f9bd51c7419b5e04664f0e386b7fb4d0": {
4+
"a37d3ef54c18e7738fe5dc008504591bd3b1f14c6a09ee91eac6d55f7ca5ba5f": {
5+
"source": {
6+
"path": "asset.a37d3ef54c18e7738fe5dc008504591bd3b1f14c6a09ee91eac6d55f7ca5ba5f.zip",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "a37d3ef54c18e7738fe5dc008504591bd3b1f14c6a09ee91eac6d55f7ca5ba5f.zip",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
},
17+
"931b3e911bae7029fea07c3a55bc0b5bd8a87b82655f47d331322d9b0245b56f": {
518
"source": {
619
"path": "aws-cdk-lambda-1.template.json",
720
"packaging": "file"
821
},
922
"destinations": {
1023
"current_account-current_region": {
1124
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "811c02a1b423ba875c9e41bef2453805f9bd51c7419b5e04664f0e386b7fb4d0.json",
25+
"objectKey": "931b3e911bae7029fea07c3a55bc0b5bd8a87b82655f47d331322d9b0245b56f.json",
1326
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1427
}
1528
}

packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda.js.snapshot/aws-cdk-lambda-1.template.json

+63-6
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@
5858
"Code": {
5959
"ZipFile": "foo"
6060
},
61+
"Description": "version-hash:1786de9fc1bc4cb2fd5b64d612628c6f",
62+
"Handler": "index.handler",
6163
"Role": {
6264
"Fn::GetAtt": [
6365
"MyLambdaServiceRole4539ECB6",
6466
"Arn"
6567
]
6668
},
67-
"Description": "version-hash:1786de9fc1bc4cb2fd5b64d612628c6f",
68-
"Handler": "index.handler",
6969
"Runtime": "nodejs14.x"
7070
},
7171
"DependsOn": [
@@ -122,13 +122,13 @@
122122
"Type": "AWS::Lambda::Url",
123123
"Properties": {
124124
"AuthType": "NONE",
125+
"Qualifier": "prod",
125126
"TargetFunctionArn": {
126127
"Fn::GetAtt": [
127128
"MyLambdaCCE802FB",
128129
"Arn"
129130
]
130-
},
131-
"Qualifier": "prod"
131+
}
132132
},
133133
"DependsOn": [
134134
"Alias325C5727"
@@ -141,9 +141,66 @@
141141
"FunctionName": {
142142
"Ref": "Alias325C5727"
143143
},
144-
"Principal": "*",
145-
"FunctionUrlAuthType": "NONE"
144+
"FunctionUrlAuthType": "NONE",
145+
"Principal": "*"
146146
}
147+
},
148+
"MySnapStartLambdaServiceRoleE0F04324": {
149+
"Type": "AWS::IAM::Role",
150+
"Properties": {
151+
"AssumeRolePolicyDocument": {
152+
"Statement": [
153+
{
154+
"Action": "sts:AssumeRole",
155+
"Effect": "Allow",
156+
"Principal": {
157+
"Service": "lambda.amazonaws.com"
158+
}
159+
}
160+
],
161+
"Version": "2012-10-17"
162+
},
163+
"ManagedPolicyArns": [
164+
{
165+
"Fn::Join": [
166+
"",
167+
[
168+
"arn:",
169+
{
170+
"Ref": "AWS::Partition"
171+
},
172+
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
173+
]
174+
]
175+
}
176+
]
177+
}
178+
},
179+
"MySnapStartLambda8F562E6E": {
180+
"Type": "AWS::Lambda::Function",
181+
"Properties": {
182+
"Code": {
183+
"S3Bucket": {
184+
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
185+
},
186+
"S3Key": "a37d3ef54c18e7738fe5dc008504591bd3b1f14c6a09ee91eac6d55f7ca5ba5f.zip"
187+
},
188+
"Description": "version-hash:cb4acf3f2fee0dc7ef3d57cc9e3c231f",
189+
"Handler": "example.Handler::handleRequest",
190+
"Role": {
191+
"Fn::GetAtt": [
192+
"MySnapStartLambdaServiceRoleE0F04324",
193+
"Arn"
194+
]
195+
},
196+
"Runtime": "java11",
197+
"SnapStart": {
198+
"ApplyOn": "PublishedVersions"
199+
}
200+
},
201+
"DependsOn": [
202+
"MySnapStartLambdaServiceRoleE0F04324"
203+
]
147204
}
148205
},
149206
"Parameters": {
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"21.0.0"}
1+
{"version":"33.0.0"}

packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda.js.snapshot/integ.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "21.0.0",
2+
"version": "33.0.0",
33
"testCases": {
44
"integ.lambda": {
55
"stacks": [

packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda.js.snapshot/manifest.json

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
{
2-
"version": "21.0.0",
2+
"version": "33.0.0",
33
"artifacts": {
4-
"Tree": {
5-
"type": "cdk:tree",
6-
"properties": {
7-
"file": "tree.json"
8-
}
9-
},
104
"aws-cdk-lambda-1.assets": {
115
"type": "cdk:asset-manifest",
126
"properties": {
@@ -23,7 +17,7 @@
2317
"validateOnSynth": false,
2418
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
2519
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
26-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/811c02a1b423ba875c9e41bef2453805f9bd51c7419b5e04664f0e386b7fb4d0.json",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/931b3e911bae7029fea07c3a55bc0b5bd8a87b82655f47d331322d9b0245b56f.json",
2721
"requiresBootstrapStackVersion": 6,
2822
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2923
"additionalDependencies": [
@@ -93,29 +87,38 @@
9387
"data": "Aliasinvokefunctionurl4CA9917B"
9488
}
9589
],
96-
"/aws-cdk-lambda-1/BootstrapVersion": [
90+
"/aws-cdk-lambda-1/MySnapStartLambda/ServiceRole/Resource": [
9791
{
9892
"type": "aws:cdk:logicalId",
99-
"data": "BootstrapVersion"
93+
"data": "MySnapStartLambdaServiceRoleE0F04324"
10094
}
10195
],
102-
"/aws-cdk-lambda-1/CheckBootstrapVersion": [
96+
"/aws-cdk-lambda-1/MySnapStartLambda/Resource": [
10397
{
10498
"type": "aws:cdk:logicalId",
105-
"data": "CheckBootstrapVersion"
99+
"data": "MySnapStartLambda8F562E6E"
100+
}
101+
],
102+
"/aws-cdk-lambda-1/BootstrapVersion": [
103+
{
104+
"type": "aws:cdk:logicalId",
105+
"data": "BootstrapVersion"
106106
}
107107
],
108-
"MyLambdaCurrentVersionE7A382CC1786de9fc1bc4cb2fd5b64d612628c6f": [
108+
"/aws-cdk-lambda-1/CheckBootstrapVersion": [
109109
{
110110
"type": "aws:cdk:logicalId",
111-
"data": "MyLambdaCurrentVersionE7A382CC1786de9fc1bc4cb2fd5b64d612628c6f",
112-
"trace": [
113-
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
114-
]
111+
"data": "CheckBootstrapVersion"
115112
}
116113
]
117114
},
118115
"displayName": "aws-cdk-lambda-1"
116+
},
117+
"Tree": {
118+
"type": "cdk:tree",
119+
"properties": {
120+
"file": "tree.json"
121+
}
119122
}
120123
}
121124
}

0 commit comments

Comments
 (0)