Skip to content

Commit 1726abd

Browse files
authored
fix(lambda): invalid Version object created from Version.fromVersionArn (#31433)
### Issue # (if applicable) Closes #29813 ### Reason for this change The current `lambda.Version.fromVersionArn` will incorrectly create the lambda function arn with the version qualifier. This is incorrect behaviour and cause CFN deployment failures. ### Description of changes If the version arn is an unresolved token, use intrinsics to join the first 7 components. Otherwise, split the array and join the first 7 components directly. ### Description of how you validated changes All new and existing tests should pass. New integration tests added with assertions. ### Checklist - [ ] 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 386fca3 commit 1726abd

File tree

12 files changed

+32687
-2
lines changed

12 files changed

+32687
-2
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-lambda/test/integ.lambda-version-arn.js.snapshot/asset.3cef2cdbb46b3821e641ffb8b9af9731af5f7e4a9e857ab633dbcd9023de724d.bundle/index.js

+31,546
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-version-arn.js.snapshot/cdk.out

+1
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-version-arn.js.snapshot/integ.json

+12
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-version-arn.js.snapshot/lambda-version-arn.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
"Resources": {
3+
"FnServiceRoleB9001A96": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"AssumeRolePolicyDocument": {
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": "lambda.amazonaws.com"
13+
}
14+
}
15+
],
16+
"Version": "2012-10-17"
17+
},
18+
"ManagedPolicyArns": [
19+
{
20+
"Fn::Join": [
21+
"",
22+
[
23+
"arn:",
24+
{
25+
"Ref": "AWS::Partition"
26+
},
27+
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
28+
]
29+
]
30+
}
31+
]
32+
}
33+
},
34+
"Fn9270CBC0": {
35+
"Type": "AWS::Lambda::Function",
36+
"Properties": {
37+
"Code": {
38+
"ZipFile": "foo"
39+
},
40+
"Handler": "index.handler",
41+
"Role": {
42+
"Fn::GetAtt": [
43+
"FnServiceRoleB9001A96",
44+
"Arn"
45+
]
46+
},
47+
"Runtime": "python3.10"
48+
},
49+
"DependsOn": [
50+
"FnServiceRoleB9001A96"
51+
]
52+
},
53+
"Version6A868472": {
54+
"Type": "AWS::Lambda::Version",
55+
"Properties": {
56+
"FunctionName": {
57+
"Ref": "Fn9270CBC0"
58+
}
59+
}
60+
},
61+
"VersionEventInvokeConfig19A99EDA": {
62+
"Type": "AWS::Lambda::EventInvokeConfig",
63+
"Properties": {
64+
"FunctionName": {
65+
"Ref": "Fn9270CBC0"
66+
},
67+
"MaximumEventAgeInSeconds": 3600,
68+
"MaximumRetryAttempts": 0,
69+
"Qualifier": {
70+
"Fn::GetAtt": [
71+
"Version6A868472",
72+
"Version"
73+
]
74+
}
75+
}
76+
}
77+
},
78+
"Outputs": {
79+
"VersionArn": {
80+
"Value": {
81+
"Ref": "Version6A868472"
82+
}
83+
},
84+
"FunctionArn1": {
85+
"Value": {
86+
"Fn::GetAtt": [
87+
"Fn9270CBC0",
88+
"Arn"
89+
]
90+
}
91+
},
92+
"FunctionArn2": {
93+
"Value": {
94+
"Fn::GetAtt": [
95+
"Fn9270CBC0",
96+
"Arn"
97+
]
98+
}
99+
}
100+
},
101+
"Parameters": {
102+
"BootstrapVersion": {
103+
"Type": "AWS::SSM::Parameter::Value<String>",
104+
"Default": "/cdk-bootstrap/hnb659fds/version",
105+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
106+
}
107+
},
108+
"Rules": {
109+
"CheckBootstrapVersion": {
110+
"Assertions": [
111+
{
112+
"Assert": {
113+
"Fn::Not": [
114+
{
115+
"Fn::Contains": [
116+
[
117+
"1",
118+
"2",
119+
"3",
120+
"4",
121+
"5"
122+
],
123+
{
124+
"Ref": "BootstrapVersion"
125+
}
126+
]
127+
}
128+
]
129+
},
130+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
131+
}
132+
]
133+
}
134+
}
135+
}

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

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)