Skip to content

Commit

Permalink
fix(lambda) update python ADOT layer version adding the additional ne…
Browse files Browse the repository at this point in the history
…w 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
  • Loading branch information
randyridgley committed Jul 18, 2023
1 parent cad0635 commit 7284055
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "32.0.0",
"files": {
"da818761c778b9099af670b7379d3db67a8f46572795cf76cc3f7442b341fb86": {
"1e011d502b5efbd34b58f00a70ccf34fb812c6af28ee32ffe796b007503169f1": {
"source": {
"path": "Stack1.template.json",
"packaging": "file"
},
"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}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "32.0.0",
"files": {
"a4d1f60a1bf3af6d4d630d5c0557444ee8d18f93483887409a89dc8f34b228d5": {
"45de98e0bad004888e2b3a349cf7b69b966cff9ba6effb99b03e462c69adae21": {
"source": {
"path": "Stack2.template.json",
"packaging": "file"
},
"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}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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"
Expand All @@ -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": [
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
}
},
"constructInfo": {
"fqn": "aws-cdk-lib.aws_lambda.FunctionBase",
"fqn": "aws-cdk-lib.aws_lambda.Function",
"version": "0.0.0"
}
},
Expand Down Expand Up @@ -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"
]
]
}
Expand All @@ -338,7 +338,7 @@
}
},
"constructInfo": {
"fqn": "aws-cdk-lib.aws_lambda.FunctionBase",
"fqn": "aws-cdk-lib.aws_lambda.Function",
"version": "0.0.0"
}
},
Expand Down Expand Up @@ -501,7 +501,7 @@
}
},
"constructInfo": {
"fqn": "aws-cdk-lib.aws_lambda.FunctionBase",
"fqn": "aws-cdk-lib.aws_lambda.Function",
"version": "0.0.0"
}
},
Expand Down Expand Up @@ -664,7 +664,7 @@
}
},
"constructInfo": {
"fqn": "aws-cdk-lib.aws_lambda.FunctionBase",
"fqn": "aws-cdk-lib.aws_lambda.Function",
"version": "0.0.0"
}
},
Expand Down Expand Up @@ -827,7 +827,7 @@
}
},
"constructInfo": {
"fqn": "aws-cdk-lib.aws_lambda.FunctionBase",
"fqn": "aws-cdk-lib.aws_lambda.Function",
"version": "0.0.0"
}
},
Expand Down Expand Up @@ -1019,7 +1019,7 @@
}
},
"constructInfo": {
"fqn": "aws-cdk-lib.aws_lambda.FunctionBase",
"fqn": "aws-cdk-lib.aws_lambda.Function",
"version": "0.0.0"
}
},
Expand Down Expand Up @@ -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"
]
]
}
Expand All @@ -1182,7 +1182,7 @@
}
},
"constructInfo": {
"fqn": "aws-cdk-lib.aws_lambda.FunctionBase",
"fqn": "aws-cdk-lib.aws_lambda.Function",
"version": "0.0.0"
}
},
Expand Down Expand Up @@ -1345,7 +1345,7 @@
}
},
"constructInfo": {
"fqn": "aws-cdk-lib.aws_lambda.FunctionBase",
"fqn": "aws-cdk-lib.aws_lambda.Function",
"version": "0.0.0"
}
},
Expand Down Expand Up @@ -1508,7 +1508,7 @@
}
},
"constructInfo": {
"fqn": "aws-cdk-lib.aws_lambda.FunctionBase",
"fqn": "aws-cdk-lib.aws_lambda.Function",
"version": "0.0.0"
}
},
Expand Down Expand Up @@ -1671,7 +1671,7 @@
}
},
"constructInfo": {
"fqn": "aws-cdk-lib.aws_lambda.FunctionBase",
"fqn": "aws-cdk-lib.aws_lambda.Function",
"version": "0.0.0"
}
},
Expand Down
27 changes: 26 additions & 1 deletion packages/aws-cdk-lib/aws-lambda/lib/adot-layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions packages/aws-cdk-lib/aws-lambda/test/adot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7284055

Please sign in to comment.