Skip to content

Commit 20c990c

Browse files
committed
Migrate Lambda functions to ARM64, upgrade dependencies
Now that AWS Lambda SnapStart supports ARM64, we can migrate our Lambda functions from x86 to ARM64 to take advantage of lower hardware costs and performance improvements without losing the significant cold start reduction advantage of SnapStart. Ref: https://aws.amazon.com/about-aws/whats-new/2024/07/aws-lambda-snapstart-java-functions-arm64-architecture/ Update our base AWS Lambda Function component to use the ARM64 architecture for all functions. Upgrade CDK dependencies to the latest stable versions.
1 parent 49888ab commit 20c990c

10 files changed

Lines changed: 294 additions & 162 deletions

cdk.json

Lines changed: 60 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,73 @@
1717
]
1818
},
1919
"context": {
20-
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
21-
"@aws-cdk/core:checkSecretUsage": true,
22-
"@aws-cdk/core:target-partitions": [
23-
"aws",
24-
"aws-cn"
25-
],
26-
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
27-
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
28-
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
29-
"@aws-cdk/aws-iam:minimizePolicies": true,
30-
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
31-
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
32-
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
33-
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
34-
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
35-
"@aws-cdk/core:enablePartitionLiterals": true,
36-
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
37-
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
38-
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
39-
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
40-
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
41-
"@aws-cdk/aws-route53-patters:useCertificate": true,
42-
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
43-
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
44-
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
4520
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
46-
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
47-
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
48-
"@aws-cdk/aws-redshift:columnId": true,
49-
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
50-
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
21+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
5122
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
52-
"@aws-cdk/aws-kms:aliasNameRef": true,
53-
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
54-
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
55-
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
56-
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
57-
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
58-
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
59-
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
23+
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
24+
"@aws-cdk/aws-appsync:appSyncGraphQLAPIScopeLambdaPermissions": true,
6025
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
61-
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
62-
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
26+
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
27+
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
6328
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
29+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
30+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
6431
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true,
6532
"@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true,
66-
"@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
67-
"@aws-cdk/aws-eks:nodegroupNameAttribute": true,
33+
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
34+
"@aws-cdk/aws-dynamodb:resourcePolicyPerReplica": false,
35+
"@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault": true,
6836
"@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
37+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
38+
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
39+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
40+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
41+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
42+
"@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions": true,
6943
"@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
70-
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false
44+
"@aws-cdk/aws-ecs-patterns:secGroupsDisablesImplicitOpenListener": true,
45+
"@aws-cdk/aws-ecs-patterns:uniqueTargetGroupIds": true,
46+
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
47+
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
48+
"@aws-cdk/aws-eks:nodegroupNameAttribute": true,
49+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
50+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
51+
"@aws-cdk/aws-iam:minimizePolicies": true,
52+
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
53+
"@aws-cdk/aws-kms:aliasNameRef": true,
54+
"@aws-cdk/aws-kms:applyImportedAliasPermissionsToPrincipal": true,
55+
"@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
56+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
57+
"@aws-cdk/aws-lambda:useCdkManagedLogGroups": true,
58+
"@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": true,
59+
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
60+
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
61+
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
62+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
63+
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
64+
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
65+
"@aws-cdk/aws-redshift:columnId": true,
66+
"@aws-cdk/aws-route53-patters:useCertificate": true,
67+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
68+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
69+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
70+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
71+
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
72+
"@aws-cdk/core:checkSecretUsage": true,
73+
"@aws-cdk/core:enablePartitionLiterals": true,
74+
"@aws-cdk/core:explicitStackTags": true,
75+
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
76+
"@aws-cdk/core:target-partitions": [
77+
"aws",
78+
"aws-cn"
79+
],
80+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
81+
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false,
82+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
83+
"@aws-cdk/pipelines:reduceAssetRoleTrustScope": true,
84+
"@aws-cdk/pipelines:reduceCrossAccountActionRoleTrustScope": true,
85+
"@aws-cdk/pipelines:reduceStageRoleTrustScope": true,
86+
"@aws-cdk/s3-notifications:addS3TrustKeyPolicyForSnsSubscriptions": true,
87+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true
7188
}
7289
}

lib/constructs/CustomLambdaFunction.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { PolicyStatement } from 'aws-cdk-lib/aws-iam';
2-
import { Function, FunctionProps } from 'aws-cdk-lib/aws-lambda';
2+
import { Architecture, Function, FunctionProps } from 'aws-cdk-lib/aws-lambda';
33
import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';
44
import { Construct } from 'constructs';
55

66
export interface CustomLambdaFunctionProps extends FunctionProps {}
77

88
/**
99
* Custom Lambda function that extends the default AWS Lambda Function construct with default configurations.
10-
*
10+
*
1111
* Project configurations:
1212
* - Standardize AWS CloudWatch log group names and expiration policies, expiring after 18 months.
1313
* - Grant the Lambda function permissions to emit custom CloudWatch metrics.
@@ -16,6 +16,7 @@ export class CustomLambdaFunction extends Function {
1616
constructor(scope: Construct, readonly id: string, readonly props: CustomLambdaFunctionProps) {
1717
super(scope, id, {
1818
...props,
19+
architecture: Architecture.ARM_64,
1920
logGroup: new LogGroup(scope, `${id}LogGroup`, {
2021
logGroupName: `${id}-ApplicationLogs`,
2122
retention: RetentionDays.EIGHTEEN_MONTHS

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
"devDependencies": {
1717
"@types/jest": "^29.5.14",
1818
"@types/node": "^20.12.7",
19-
"aws-cdk": "~2.1010.0",
19+
"aws-cdk": "~2.1031.1",
2020
"jest": "^29.7.0",
2121
"ts-jest": "^29.2.6",
2222
"ts-node": "^10.9.2",
2323
"typescript": "~5.4.5"
2424
},
2525
"dependencies": {
26-
"aws-cdk-lib": "~2.190",
27-
"cdk-monitoring-constructs": "^9.2.0",
26+
"aws-cdk-lib": "~2.221",
27+
"cdk-monitoring-constructs": "^9.16.0",
2828
"constructs": "^10.4.2"
2929
}
3030
}

test/stacks/__snapshots__/CodePipelineStack.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ exports[`CodePipelineStack creates the expected CloudFormation template from CDK
2727
"Arn",
2828
],
2929
},
30-
"Runtime": "nodejs20.x",
30+
"Runtime": "nodejs22.x",
3131
"Timeout": 900,
3232
},
3333
"Type": "AWS::Lambda::Function",

test/stacks/__snapshots__/ConsentExpiryProcessorStack.test.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ exports[`ConsentManagementApiStack creates the expected CloudFormation template
1616
"ConsentExpiryProcessorLambdaServiceRole855DC305",
1717
],
1818
"Properties": {
19+
"Architectures": [
20+
"arm64",
21+
],
1922
"Description": "Consent Expiry Processor Lambda",
2023
"Handler": "com.consentframework.consentexpiryprocessor.ConsentExpiryProcessor::handleRequest",
2124
"LoggingConfig": {

test/stacks/__snapshots__/ConsentHistoryApiStack.test.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ exports[`ConsentHistoryApiStack creates the expected CloudFormation template fro
550550
"UpdateReplacePolicy": "Retain",
551551
},
552552
"ConsentHistoryAPIGatewayDeployment": {
553+
"Metadata": {
554+
"aws:cdk:do-not-refactor": true,
555+
},
553556
"Properties": {
554557
"Description": "Consent History API, see documentation at https://consent-management-platform.github.io/consent-history-api-models/v1/docs.html",
555558
"RestApiId": {
@@ -587,6 +590,9 @@ exports[`ConsentHistoryApiStack creates the expected CloudFormation template fro
587590
"ConsentHistoryApiLambdaServiceRoleA0D24C3A",
588591
],
589592
"Properties": {
593+
"Architectures": [
594+
"arm64",
595+
],
590596
"Description": "Consent History API Lambda",
591597
"Handler": "com.consentframework.consenthistory.api.ConsentHistoryApiService::handleRequest",
592598
"LoggingConfig": {

test/stacks/__snapshots__/ConsentHistoryProcessorStack.test.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ exports[`ConsentHistoryProcessorStack creates the expected CloudFormation templa
1616
"ConsentHistoryProcessorLambdaServiceRoleE9DE128F",
1717
],
1818
"Properties": {
19+
"Architectures": [
20+
"arm64",
21+
],
1922
"Description": "Consent History Processor Lambda",
2023
"Environment": {
2124
"Variables": {

0 commit comments

Comments
 (0)