Skip to content

Commit

Permalink
feat(lambda): L2 constructs for SnapStart (#26761)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
roger-zhangg authored Aug 24, 2023
1 parent b1f4e27 commit 356f302
Show file tree
Hide file tree
Showing 15 changed files with 492 additions and 86 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
{
"version": "21.0.0",
"version": "33.0.0",
"files": {
"811c02a1b423ba875c9e41bef2453805f9bd51c7419b5e04664f0e386b7fb4d0": {
"a37d3ef54c18e7738fe5dc008504591bd3b1f14c6a09ee91eac6d55f7ca5ba5f": {
"source": {
"path": "asset.a37d3ef54c18e7738fe5dc008504591bd3b1f14c6a09ee91eac6d55f7ca5ba5f.zip",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "a37d3ef54c18e7738fe5dc008504591bd3b1f14c6a09ee91eac6d55f7ca5ba5f.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"931b3e911bae7029fea07c3a55bc0b5bd8a87b82655f47d331322d9b0245b56f": {
"source": {
"path": "aws-cdk-lambda-1.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "811c02a1b423ba875c9e41bef2453805f9bd51c7419b5e04664f0e386b7fb4d0.json",
"objectKey": "931b3e911bae7029fea07c3a55bc0b5bd8a87b82655f47d331322d9b0245b56f.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@
"Code": {
"ZipFile": "foo"
},
"Description": "version-hash:1786de9fc1bc4cb2fd5b64d612628c6f",
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"MyLambdaServiceRole4539ECB6",
"Arn"
]
},
"Description": "version-hash:1786de9fc1bc4cb2fd5b64d612628c6f",
"Handler": "index.handler",
"Runtime": "nodejs14.x"
},
"DependsOn": [
Expand Down Expand Up @@ -122,13 +122,13 @@
"Type": "AWS::Lambda::Url",
"Properties": {
"AuthType": "NONE",
"Qualifier": "prod",
"TargetFunctionArn": {
"Fn::GetAtt": [
"MyLambdaCCE802FB",
"Arn"
]
},
"Qualifier": "prod"
}
},
"DependsOn": [
"Alias325C5727"
Expand All @@ -141,9 +141,66 @@
"FunctionName": {
"Ref": "Alias325C5727"
},
"Principal": "*",
"FunctionUrlAuthType": "NONE"
"FunctionUrlAuthType": "NONE",
"Principal": "*"
}
},
"MySnapStartLambdaServiceRoleE0F04324": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"MySnapStartLambda8F562E6E": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "a37d3ef54c18e7738fe5dc008504591bd3b1f14c6a09ee91eac6d55f7ca5ba5f.zip"
},
"Description": "version-hash:cb4acf3f2fee0dc7ef3d57cc9e3c231f",
"Handler": "example.Handler::handleRequest",
"Role": {
"Fn::GetAtt": [
"MySnapStartLambdaServiceRoleE0F04324",
"Arn"
]
},
"Runtime": "java11",
"SnapStart": {
"ApplyOn": "PublishedVersions"
}
},
"DependsOn": [
"MySnapStartLambdaServiceRoleE0F04324"
]
}
},
"Parameters": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"21.0.0"}
{"version":"33.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "21.0.0",
"version": "33.0.0",
"testCases": {
"integ.lambda": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"version": "21.0.0",
"version": "33.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
},
"aws-cdk-lambda-1.assets": {
"type": "cdk:asset-manifest",
"properties": {
Expand All @@ -23,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/811c02a1b423ba875c9e41bef2453805f9bd51c7419b5e04664f0e386b7fb4d0.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/931b3e911bae7029fea07c3a55bc0b5bd8a87b82655f47d331322d9b0245b56f.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down Expand Up @@ -93,29 +87,38 @@
"data": "Aliasinvokefunctionurl4CA9917B"
}
],
"/aws-cdk-lambda-1/BootstrapVersion": [
"/aws-cdk-lambda-1/MySnapStartLambda/ServiceRole/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "BootstrapVersion"
"data": "MySnapStartLambdaServiceRoleE0F04324"
}
],
"/aws-cdk-lambda-1/CheckBootstrapVersion": [
"/aws-cdk-lambda-1/MySnapStartLambda/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
"data": "MySnapStartLambda8F562E6E"
}
],
"/aws-cdk-lambda-1/BootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "BootstrapVersion"
}
],
"MyLambdaCurrentVersionE7A382CC1786de9fc1bc4cb2fd5b64d612628c6f": [
"/aws-cdk-lambda-1/CheckBootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "MyLambdaCurrentVersionE7A382CC1786de9fc1bc4cb2fd5b64d612628c6f",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
"data": "CheckBootstrapVersion"
}
]
},
"displayName": "aws-cdk-lambda-1"
},
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
}
}
}
Loading

0 comments on commit 356f302

Please sign in to comment.