Skip to content

aws_lambda: Version.fromVersionArn creates invalid Version object #29813

@rehos

Description

@rehos

Describe the bug

The version object created by Version.fromVersionArn is created with a lambda property that still contains the version qualifier in its function url. Which can cause CloudFormation deployment errors. For example when you create a lambda alias from it and then try to use that alias fro a lambda function url.

Expected Behavior

I expect Version.fromVersionArn to create the equivalent object as Version.fromVersionAttributes when referencing the same version.

The following test when using Version.fromVersionAttributes succeeds:

import {
    Stack,
    aws_lambda as lambda,
} from 'aws-cdk-lib';

test('lambda.Version.fromVersionAttributes generates Version with correct lambda property', () => {
    const stack = new Stack();
    const version = lambda.Version.fromVersionAttributes(stack, 'ExampleVersion', {
        lambda: lambda.Function.fromFunctionArn(stack, 'Examplelambda', 'arn:aws:lambda:eu-central-1:123456789012:function:ExampleLambda'),
        version: '13',
    });

    expect(version.version).toStrictEqual('13') // Ok
    expect(version.lambda.functionArn).toStrictEqual('arn:aws:lambda:eu-central-1:123456789012:function:ExampleLambda') // Ok
})

Current Behavior

However the following test when using Version.fromVersionArn fails because the version qualifier is not stripped from the arn:

import {
    Stack,
    aws_lambda as lambda,
} from 'aws-cdk-lib';

test('lambda.Version.fromVersionArn generates Version with correct lambda property', () => {
    const stack = new Stack();
    const version = lambda.Version.fromVersionArn(stack, 'ExampleVersion', 'arn:aws:lambda:eu-central-1:123456789012:function:ExampleLambda:13');

    expect(version.version).toStrictEqual('13') // Ok
    expect(version.lambda.functionArn).toStrictEqual('arn:aws:lambda:eu-central-1:123456789012:function:ExampleLambda') // Not Ok
})

Reproduction Steps

Run the above tests

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.137.0

Framework Version

No response

Node.js Version

v20.11.0

OS

macOS Sonoma 14.4.1

Language

TypeScript

Language Version

Typescript (5.4.5)

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-lambdaRelated to AWS LambdabugThis issue is a bug.effort/smallSmall work item – less than a day of effortp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions