From 72840557b72ebe88a22b08ea0ee2ff5fad5c41e2 Mon Sep 17 00:00:00 2001 From: Randy Ridgley Date: Tue, 18 Jul 2023 18:44:15 +0000 Subject: [PATCH] fix(lambda) update python ADOT layer version adding the additional new layers and update LATEST to 1.18. There might be a better way to keep these up to date but I could not find an approrpiate way to dynamically add Adot versions --- .../Stack1.assets.json | 4 +- .../Stack1.template.json | 2 +- .../Stack2.assets.json | 4 +- .../Stack2.template.json | 2 +- .../manifest.json | 58 +------------------ .../integ.lambda-adot.js.snapshot/tree.json | 24 ++++---- .../aws-cdk-lib/aws-lambda/lib/adot-layers.ts | 27 ++++++++- .../aws-cdk-lib/aws-lambda/test/adot.test.ts | 32 ++++++++++ 8 files changed, 78 insertions(+), 75 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack1.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack1.assets.json index 7c4a95ce08042..c02b32ab9a840 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack1.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack1.assets.json @@ -1,7 +1,7 @@ { "version": "32.0.0", "files": { - "da818761c778b9099af670b7379d3db67a8f46572795cf76cc3f7442b341fb86": { + "1e011d502b5efbd34b58f00a70ccf34fb812c6af28ee32ffe796b007503169f1": { "source": { "path": "Stack1.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "da818761c778b9099af670b7379d3db67a8f46572795cf76cc3f7442b341fb86.json", + "objectKey": "1e011d502b5efbd34b58f00a70ccf34fb812c6af28ee32ffe796b007503169f1.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack1.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack1.template.json index c9b23bd17ce83..e4cdf818a89a7 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack1.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack1.template.json @@ -179,7 +179,7 @@ { "Ref": "AWS::Region" }, - ":901920570463:layer:aws-otel-python-amd64-ver-1-13-0:1" + ":901920570463:layer:aws-otel-python-amd64-ver-1-18-0:2" ] ] } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack2.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack2.assets.json index 6752713291eea..359267ab7abf7 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack2.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack2.assets.json @@ -1,7 +1,7 @@ { "version": "32.0.0", "files": { - "a4d1f60a1bf3af6d4d630d5c0557444ee8d18f93483887409a89dc8f34b228d5": { + "45de98e0bad004888e2b3a349cf7b69b966cff9ba6effb99b03e462c69adae21": { "source": { "path": "Stack2.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "a4d1f60a1bf3af6d4d630d5c0557444ee8d18f93483887409a89dc8f34b228d5.json", + "objectKey": "45de98e0bad004888e2b3a349cf7b69b966cff9ba6effb99b03e462c69adae21.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack2.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack2.template.json index ebcf7448ac457..a2f2184183646 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack2.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/Stack2.template.json @@ -182,7 +182,7 @@ { "Ref": "AWS::Region" }, - ":901920570463:layer:aws-otel-python-amd64-ver-1-13-0:1" + ":901920570463:layer:aws-otel-python-amd64-ver-1-18-0:2" ] ] } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/manifest.json index ea4102575a0a7..1de152555a3ca 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/manifest.json @@ -17,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}/da818761c778b9099af670b7379d3db67a8f46572795cf76cc3f7442b341fb86.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/1e011d502b5efbd34b58f00a70ccf34fb812c6af28ee32ffe796b007503169f1.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -140,33 +140,6 @@ "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } - ], - "MyFunc6ServiceRoleCDDBC2C6": [ - { - "type": "aws:cdk:logicalId", - "data": "MyFunc6ServiceRoleCDDBC2C6", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } - ], - "MyFunc6ServiceRoleDefaultPolicyC4D4BF55": [ - { - "type": "aws:cdk:logicalId", - "data": "MyFunc6ServiceRoleDefaultPolicyC4D4BF55", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } - ], - "MyFunc60D944984": [ - { - "type": "aws:cdk:logicalId", - "data": "MyFunc60D944984", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } ] }, "displayName": "Stack1" @@ -187,7 +160,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}/a4d1f60a1bf3af6d4d630d5c0557444ee8d18f93483887409a89dc8f34b228d5.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/45de98e0bad004888e2b3a349cf7b69b966cff9ba6effb99b03e462c69adae21.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -304,33 +277,6 @@ "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } - ], - "MyFunc6ServiceRoleCDDBC2C6": [ - { - "type": "aws:cdk:logicalId", - "data": "MyFunc6ServiceRoleCDDBC2C6", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } - ], - "MyFunc6ServiceRoleDefaultPolicyC4D4BF55": [ - { - "type": "aws:cdk:logicalId", - "data": "MyFunc6ServiceRoleDefaultPolicyC4D4BF55", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } - ], - "MyFunc60D944984": [ - { - "type": "aws:cdk:logicalId", - "data": "MyFunc60D944984", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } ] }, "displayName": "Stack2" diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/tree.json index 5db219ef20619..1aace82f92764 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-adot.js.snapshot/tree.json @@ -167,7 +167,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_lambda.FunctionBase", + "fqn": "aws-cdk-lib.aws_lambda.Function", "version": "0.0.0" } }, @@ -312,7 +312,7 @@ { "Ref": "AWS::Region" }, - ":901920570463:layer:aws-otel-python-amd64-ver-1-13-0:1" + ":901920570463:layer:aws-otel-python-amd64-ver-1-18-0:2" ] ] } @@ -338,7 +338,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_lambda.FunctionBase", + "fqn": "aws-cdk-lib.aws_lambda.Function", "version": "0.0.0" } }, @@ -501,7 +501,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_lambda.FunctionBase", + "fqn": "aws-cdk-lib.aws_lambda.Function", "version": "0.0.0" } }, @@ -664,7 +664,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_lambda.FunctionBase", + "fqn": "aws-cdk-lib.aws_lambda.Function", "version": "0.0.0" } }, @@ -827,7 +827,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_lambda.FunctionBase", + "fqn": "aws-cdk-lib.aws_lambda.Function", "version": "0.0.0" } }, @@ -1019,7 +1019,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_lambda.FunctionBase", + "fqn": "aws-cdk-lib.aws_lambda.Function", "version": "0.0.0" } }, @@ -1156,7 +1156,7 @@ { "Ref": "AWS::Region" }, - ":901920570463:layer:aws-otel-python-amd64-ver-1-13-0:1" + ":901920570463:layer:aws-otel-python-amd64-ver-1-18-0:2" ] ] } @@ -1182,7 +1182,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_lambda.FunctionBase", + "fqn": "aws-cdk-lib.aws_lambda.Function", "version": "0.0.0" } }, @@ -1345,7 +1345,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_lambda.FunctionBase", + "fqn": "aws-cdk-lib.aws_lambda.Function", "version": "0.0.0" } }, @@ -1508,7 +1508,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_lambda.FunctionBase", + "fqn": "aws-cdk-lib.aws_lambda.Function", "version": "0.0.0" } }, @@ -1671,7 +1671,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_lambda.FunctionBase", + "fqn": "aws-cdk-lib.aws_lambda.Function", "version": "0.0.0" } }, diff --git a/packages/aws-cdk-lib/aws-lambda/lib/adot-layers.ts b/packages/aws-cdk-lib/aws-lambda/lib/adot-layers.ts index 0a90489c0caac..4587d21117c93 100644 --- a/packages/aws-cdk-lib/aws-lambda/lib/adot-layers.ts +++ b/packages/aws-cdk-lib/aws-lambda/lib/adot-layers.ts @@ -253,7 +253,32 @@ export class AdotLambdaLayerPythonSdkVersion extends AdotLambdaLayerVersion { * The latest layer version available in this CDK version. New versions could * introduce incompatible changes. Make sure to test them before deploying to production. */ - public static readonly LATEST = new AdotLambdaLayerPythonSdkVersion('1.13.0'); + public static readonly LATEST = new AdotLambdaLayerPythonSdkVersion('1.18.0'); + + /** + * Version 1.18.0 + */ + public static readonly V1_18_0 = new AdotLambdaLayerPythonSdkVersion('1.18.0'); + + /** + * Version 1.17.0 + */ + public static readonly V1_17_0 = new AdotLambdaLayerPythonSdkVersion('1.17.0'); + + /** + * Version 1.16.0 + */ + public static readonly V1_16_0 = new AdotLambdaLayerPythonSdkVersion('1.16.0'); + + /** + * Version 1.15.0 + */ + public static readonly V1_15_0 = new AdotLambdaLayerPythonSdkVersion('1.15.0'); + + /** + * Version 1.14.0 + */ + public static readonly V1_14_0 = new AdotLambdaLayerPythonSdkVersion('1.14.0'); /** * Version 1.13.0 diff --git a/packages/aws-cdk-lib/aws-lambda/test/adot.test.ts b/packages/aws-cdk-lib/aws-lambda/test/adot.test.ts index 6f73bbc26f8df..eeb383c162b01 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/adot.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/adot.test.ts @@ -37,6 +37,38 @@ describe('ADOT Lambda Layer', () => { }); }); + describe('when the Python ADOT version is specified', () => { + + let fn: lambda.Function; + + beforeEach(() => { + const app = new cdk.App(); + const stack = new cdk.Stack(app, 'stack', { env: { region: 'us-west-2' } }); + const bucket = new s3.Bucket(stack, 'CodeBucket'); + fn = new lambda.Function(stack, 'Function', { + code: lambda.Code.fromBucket(bucket, 'mock_key'), + handler: 'index.handler', + runtime: lambda.Runtime.PYTHON_3_10, + }); + }); + + test('is added properly when the region information is available at synthesis time', () => { + const layerArn = lambda.AdotLambdaLayerPythonSdkVersion.V1_18_0.layerArn(fn.stack, fn.architecture); + + expect(layerArn).toEqual( + 'arn:aws:lambda:us-west-2:901920570463:layer:aws-otel-python-wrapper-amd64-ver-1-18-0:1', + ); + }); + + test('is added properly when using "LATEST" version', () => { + const layerArn = lambda.AdotLambdaLayerPythonSdkVersion.LATEST.layerArn(fn.stack, fn.architecture); + + expect(layerArn).toEqual( + 'arn:aws:lambda:us-west-2:901920570463:layer:aws-otel-python-wrapper-amd64-ver-1-18-0:1', + ); + }); + }); + describe('when the stack region is not supported', () => { test('throws error if the region is not supported', () => { const app = new cdk.App();