Skip to content

Commit ced7a46

Browse files
pahudmoelasmar
authored andcommitted
revert: "fix(lambda): version.fromVersionArn creates invalid Version object" (#30003)
### Issue # (if applicable) Revert #29820 Closes #30002 ### Reason for this change ### Description of changes ### Description of how you validated changes ### Checklist - [x] 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 2699ffd commit ced7a46

File tree

3 files changed

+1
-39
lines changed

3 files changed

+1
-39
lines changed

packages/aws-cdk-lib/aws-lambda/lib/function.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -671,18 +671,7 @@ export class Function extends FunctionBase {
671671
* in the same account and region as the stack you are importing it into.
672672
*/
673673
public static fromFunctionArn(scope: Construct, id: string, functionArn: string): IFunction {
674-
/**
675-
* If the functionArn has a trailing version or alias (more than 7 parts when split by ":",
676-
* we trim off the trailing version/alias to retrieve the real functionArn.
677-
* See lambda resource ARN format here: https://docs.aws.amazon.com/lambda/latest/dg/lambda-api-permissions-ref.html
678-
*/
679-
const parts = functionArn.split(':');
680-
if (parts.length > 7) {
681-
const _functionArn = parts.slice(0, 7).join(':');
682-
return Function.fromFunctionAttributes(scope, id, { functionArn: _functionArn });
683-
} else {
684-
return Function.fromFunctionAttributes(scope, id, { functionArn });
685-
}
674+
return Function.fromFunctionAttributes(scope, id, { functionArn });
686675
}
687676

688677
/**

packages/aws-cdk-lib/aws-lambda/test/function.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -397,30 +397,6 @@ describe('function', () => {
397397
expect(imported.functionName).toEqual('ProcessKinesisRecords');
398398
});
399399

400-
test('fromFunctionArn with verionArn as the input', () => {
401-
// GIVEN
402-
const stack2 = new cdk.Stack();
403-
404-
// WHEN
405-
const imported = lambda.Function.fromFunctionArn(stack2, 'Imported', 'arn:aws:lambda:us-east-1:123456789012:function:ProcessKinesisRecords:1');
406-
407-
// THEN
408-
expect(imported.functionArn).toEqual('arn:aws:lambda:us-east-1:123456789012:function:ProcessKinesisRecords');
409-
expect(imported.functionName).toEqual('ProcessKinesisRecords');
410-
});
411-
412-
test('fromFunctionArn with trailing alias as the input', () => {
413-
// GIVEN
414-
const stack2 = new cdk.Stack();
415-
416-
// WHEN
417-
const imported = lambda.Function.fromFunctionArn(stack2, 'Imported', 'arn:aws:lambda:us-east-1:123456789012:function:ProcessKinesisRecords:TEST');
418-
419-
// THEN
420-
expect(imported.functionArn).toEqual('arn:aws:lambda:us-east-1:123456789012:function:ProcessKinesisRecords');
421-
expect(imported.functionName).toEqual('ProcessKinesisRecords');
422-
});
423-
424400
test('Function.fromFunctionName', () => {
425401
// GIVEN
426402
const stack = new cdk.Stack();

packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ describe('lambda version', () => {
1515
// WHEN
1616
const version = lambda.Version.fromVersionArn(stack, 'Version', 'arn:aws:lambda:region:account-id:function:function-name:version');
1717

18-
expect(version.version).toStrictEqual('version');
19-
expect(version.lambda.functionArn).toStrictEqual('arn:aws:lambda:region:account-id:function:function-name');
20-
2118
new cdk.CfnOutput(stack, 'ARN', { value: version.functionArn });
2219
new cdk.CfnOutput(stack, 'Name', { value: version.functionName });
2320

0 commit comments

Comments
 (0)