Skip to content

Commit b4377a5

Browse files
authored
feat(lambda): add SnapStart support for arm64 functions (#30898)
### Issue # (if applicable) Closes #30899. ### Reason for this change Lambda released SnapStart support for arm64 functions: https://aws.amazon.com/about-aws/whats-new/2024/07/aws-lambda-snapstart-java-functions-arm64-architecture/ ### Description of changes Allow configuring SnapStart on arm64 functions. ### Description of how you validated changes ```yarn test``` ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 230b56b commit b4377a5

File tree

10 files changed

+241
-28
lines changed

10 files changed

+241
-28
lines changed

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

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,66 @@
201201
"DependsOn": [
202202
"MySnapStartLambdaServiceRoleE0F04324"
203203
]
204+
},
205+
"MySnapStartLambdaArmServiceRole731A8472": {
206+
"Type": "AWS::IAM::Role",
207+
"Properties": {
208+
"AssumeRolePolicyDocument": {
209+
"Statement": [
210+
{
211+
"Action": "sts:AssumeRole",
212+
"Effect": "Allow",
213+
"Principal": {
214+
"Service": "lambda.amazonaws.com"
215+
}
216+
}
217+
],
218+
"Version": "2012-10-17"
219+
},
220+
"ManagedPolicyArns": [
221+
{
222+
"Fn::Join": [
223+
"",
224+
[
225+
"arn:",
226+
{
227+
"Ref": "AWS::Partition"
228+
},
229+
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
230+
]
231+
]
232+
}
233+
]
234+
}
235+
},
236+
"MySnapStartLambdaArmEDD3F420": {
237+
"Type": "AWS::Lambda::Function",
238+
"Properties": {
239+
"Architectures": [
240+
"arm64"
241+
],
242+
"Code": {
243+
"S3Bucket": {
244+
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
245+
},
246+
"S3Key": "a37d3ef54c18e7738fe5dc008504591bd3b1f14c6a09ee91eac6d55f7ca5ba5f.zip"
247+
},
248+
"Description": "version-hash:522e22f485651f1644be7e317c07836f",
249+
"Handler": "example.Handler::handleRequest",
250+
"Role": {
251+
"Fn::GetAtt": [
252+
"MySnapStartLambdaArmServiceRole731A8472",
253+
"Arn"
254+
]
255+
},
256+
"Runtime": "java21",
257+
"SnapStart": {
258+
"ApplyOn": "PublishedVersions"
259+
}
260+
},
261+
"DependsOn": [
262+
"MySnapStartLambdaArmServiceRole731A8472"
263+
]
204264
}
205265
},
206266
"Parameters": {

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 21 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 127 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,12 @@ new lambda.Function(stack, 'MySnapStartLambda', {
4545
snapStart: lambda.SnapStartConf.ON_PUBLISHED_VERSIONS,
4646
});
4747

48+
new lambda.Function(stack, 'MySnapStartLambdaArm', {
49+
code: lambda.Code.fromAsset(path.join(__dirname, 'handler-snapstart.zip')),
50+
handler: 'example.Handler::handleRequest',
51+
runtime: lambda.Runtime.JAVA_21,
52+
architecture: lambda.Architecture.ARM_64,
53+
snapStart: lambda.SnapStartConf.ON_PUBLISHED_VERSIONS,
54+
});
55+
4856
app.synth();

packages/aws-cdk-lib/aws-lambda/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ managing concurrency.
967967

968968
## Lambda with SnapStart
969969

970-
SnapStart is currently supported only on Java 11/Java 17 runtime. SnapStart does not support provisioned concurrency, the arm64 architecture, Amazon Elastic File System (Amazon EFS), or ephemeral storage greater than 512 MB. After you enable Lambda SnapStart for a particular Lambda function, publishing a new version of the function will trigger an optimization process.
970+
SnapStart is currently supported only on Java 11 and later [Java managed runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). SnapStart does not support provisioned concurrency, Amazon Elastic File System (Amazon EFS), or ephemeral storage greater than 512 MB. After you enable Lambda SnapStart for a particular Lambda function, publishing a new version of the function will trigger an optimization process.
971971

972972
See [the AWS documentation](https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html) to learn more about AWS Lambda SnapStart
973973

packages/aws-cdk-lib/aws-lambda/lib/function.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ Environment variables can be marked for removal when used in Lambda@Edge by sett
15541554
return undefined;
15551555
}
15561556

1557-
// SnapStart does not support arm64 architecture, Amazon Elastic File System (Amazon EFS), or ephemeral storage greater than 512 MB.
1557+
// SnapStart does not support Amazon Elastic File System (Amazon EFS), or ephemeral storage greater than 512 MB.
15581558
// SnapStart doesn't support provisioned concurrency either, but that's configured at the version level,
15591559
// so it can't be checked at function set up time
15601560
// SnapStart supports the Java 11 and Java 17 (java11 and java17) managed runtimes.
@@ -1565,10 +1565,6 @@ Environment variables can be marked for removal when used in Lambda@Edge by sett
15651565
throw new Error(`SnapStart currently not supported by runtime ${props.runtime.name}`);
15661566
}
15671567

1568-
if (props.architecture == Architecture.ARM_64) {
1569-
throw new Error('SnapStart is currently not supported on Arm_64');
1570-
}
1571-
15721568
if (props.filesystem) {
15731569
throw new Error('SnapStart is currently not supported using EFS');
15741570
}

packages/aws-cdk-lib/aws-lambda/test/function.test.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,16 +3429,29 @@ describe('function', () => {
34293429
})).toThrowError('SnapStart currently not supported by runtime nodejs18.x');
34303430
});
34313431

3432-
test('arm64 validation for snapStart', () => {
3432+
test('arm64 function using snapStart', () => {
34333433
const stack = new cdk.Stack();
3434-
3435-
expect(() => new lambda.Function(stack, 'MyLambda', {
3434+
//WHEN
3435+
new lambda.Function(stack, 'MyLambda', {
34363436
code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')),
34373437
handler: 'example.Handler::handleRequest',
34383438
runtime: lambda.Runtime.JAVA_11,
34393439
architecture: lambda.Architecture.ARM_64,
34403440
snapStart: lambda.SnapStartConf.ON_PUBLISHED_VERSIONS,
3441-
})).toThrowError('SnapStart is currently not supported on Arm_64');
3441+
});
3442+
3443+
//THEN
3444+
Template.fromStack(stack).hasResource('AWS::Lambda::Function', {
3445+
Properties:
3446+
{
3447+
Handler: 'example.Handler::handleRequest',
3448+
Runtime: 'java11',
3449+
Architectures: ['arm64'],
3450+
SnapStart: {
3451+
ApplyOn: 'PublishedVersions',
3452+
},
3453+
},
3454+
});
34423455
});
34433456

34443457
test('EFS validation for snapStart', () => {
@@ -3463,7 +3476,7 @@ describe('function', () => {
34633476
})).toThrowError('SnapStart is currently not supported using EFS');
34643477
});
34653478

3466-
test('arm64 validation for snapStart', () => {
3479+
test('ephemeral storage limit validation for snapStart', () => {
34673480
const stack = new cdk.Stack();
34683481

34693482
expect(() => new lambda.Function(stack, 'MyLambda', {

0 commit comments

Comments
 (0)