Skip to content

Commit

Permalink
fix(lambda): invalid Version object created from Version.fromVersionA…
Browse files Browse the repository at this point in the history
…rn (#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*
  • Loading branch information
GavinZZ authored Sep 14, 2024
1 parent 386fca3 commit 1726abd
Show file tree
Hide file tree
Showing 12 changed files with 32,687 additions and 2 deletions.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"Resources": {
"FnServiceRoleB9001A96": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"Fn9270CBC0": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": "foo"
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"FnServiceRoleB9001A96",
"Arn"
]
},
"Runtime": "python3.10"
},
"DependsOn": [
"FnServiceRoleB9001A96"
]
},
"Version6A868472": {
"Type": "AWS::Lambda::Version",
"Properties": {
"FunctionName": {
"Ref": "Fn9270CBC0"
}
}
},
"VersionEventInvokeConfig19A99EDA": {
"Type": "AWS::Lambda::EventInvokeConfig",
"Properties": {
"FunctionName": {
"Ref": "Fn9270CBC0"
},
"MaximumEventAgeInSeconds": 3600,
"MaximumRetryAttempts": 0,
"Qualifier": {
"Fn::GetAtt": [
"Version6A868472",
"Version"
]
}
}
}
},
"Outputs": {
"VersionArn": {
"Value": {
"Ref": "Version6A868472"
}
},
"FunctionArn1": {
"Value": {
"Fn::GetAtt": [
"Fn9270CBC0",
"Arn"
]
}
},
"FunctionArn2": {
"Value": {
"Fn::GetAtt": [
"Fn9270CBC0",
"Arn"
]
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1726abd

Please sign in to comment.