Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_lambda: Version.fromVersionArn creates invalid Version object #29813

Closed
rehos opened this issue Apr 12, 2024 · 5 comments · Fixed by #29820 or #31433
Closed

aws_lambda: Version.fromVersionArn creates invalid Version object #29813

rehos opened this issue Apr 12, 2024 · 5 comments · Fixed by #29820 or #31433
Assignees
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@rehos
Copy link

rehos commented Apr 12, 2024

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

@rehos rehos added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 12, 2024
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Apr 12, 2024
@pahud
Copy link
Contributor

pahud commented Apr 12, 2024

Yes, it should be a tiny fix here

const lambda = Function.fromFunctionArn(scope, `${id}Function`, versionArn);

@pahud pahud added p1 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Apr 12, 2024
@pahud pahud self-assigned this Apr 12, 2024
@mergify mergify bot closed this as completed in #29820 Apr 12, 2024
mergify bot pushed a commit that referenced this issue Apr 12, 2024
…29820)

### Issue # (if applicable)

Closes #29813

### Reason for this change

improve the fromFunctionArn()  to better handle the input ARN

### Description of changes

fromFunctionArn() does not handle the ARN correctly if the input ARN has trailing version or alias.

### Description of how you validated changes

See unit tests

### 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*
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@aaythapa
Copy link
Contributor

aaythapa commented May 6, 2024

Re opening this issue since the PR that fixed this was reverted

Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

1 similar comment
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
4 participants