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: currentVersion Version already exists #28252

Closed
yellowmamba opened this issue Dec 5, 2023 · 5 comments
Closed

aws-lambda: currentVersion Version already exists #28252

yellowmamba opened this issue Dec 5, 2023 · 5 comments
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@yellowmamba
Copy link

yellowmamba commented Dec 5, 2023

Describe the bug

Upgraded aws-cdk-lib to 2.113.0. Now AWS::Lambda::Version will throw this error when the current version already exists.

Expected Behavior

Deployment should succeed like before.

Current Behavior

Throw this error when trying to update the lambda version

Resource handler returned message: "Version already exists: [my-lambda-version-arn]. Please modify the function to create a new version. (Service: Lambda, Status Code: 409)"

Reproduction Steps

Make sure aws-cdk-lib is at 2.113.0.

const lambda = new NodejsFunction(this, "lambda", {...})

const lambdaAlias = new Alias(this, "LambdaAlias", {
  aliasName: "prod",
  version: lambda.currentVersion, // this seems to be the problem
})

myApi.addRoutes({
  integration: new HttpLambdaIntegration("id", lambdaAlias),
  path: "/url",
})

Possible Solution

No response

Additional Information/Context

  • We try to upgradeaws-cdk-lib from 2.84.0 to 2.113.0
  • We replaced @aws-cdk/aws-apigatewayv2-integrations-alpha with aws-cdk-lib/aws-apigatewayv2-integrations for HttpLambdaIntegration because it'd been GA and alpha has now been deprecated.

CDK CLI Version

2.113.0

Framework Version

No response

Node.js Version

v18.17.1

OS

macOS 14.1.1

Language

TypeScript

Language Version

5.1.6

Other information

No response

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

pahud commented Dec 5, 2023

could relate to #27884

const lambdaAlias = new Alias(this, "LambdaAlias", {
  aliasName: "prod",
  version: lambda.currentVersion, // this seems to be the problem
})

Have you tried function.addAlias() to create the alias instead which was introduced in #20034

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Dec 5, 2023
@yellowmamba
Copy link
Author

@pahud it worked today with the code unchanged. I think there's some weirdness with the underlying Lambda api. A colleague was also able to reproduce this intermittent error.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Dec 6, 2023
@yellowmamba
Copy link
Author

Hi @pahud , has there been an update on this issue?

@pahud
Copy link
Contributor

pahud commented Dec 15, 2023

No. Did you mean the code below deployed in 2.84.0 will fail when you upgrade to 2.113.0 ?

const lambda = new NodejsFunction(this, "lambda", {...})

const lambdaAlias = new Alias(this, "LambdaAlias", {
  aliasName: "prod",
  version: lambda.currentVersion, // this seems to be the problem
})

myApi.addRoutes({
  integration: new HttpLambdaIntegration("id", lambdaAlias),
  path: "/url",
})

I just tested the simplified sample below. Deployed in 2.84.0

export class DemoStack extends MyStack {
  constructor(scope: Construct, id: string, props: StackProps) {
    super(scope, id, props);

    const fn = getLambdaFunction(this); // return a dummy lambda func

    new lambda.Alias(this, "LambdaAlias", {
      aliasName: "prod",
      version: fn.currentVersion, // this seems to be the problem
    })
  }
}

Then, upgrade to 2.113.0. Run cdk diff, I didn't see any difference.

Now, I updated the lambda code and run cdk diff again. I saw below:

Resources
[-] AWS::Lambda::Version Func/CurrentVersion FuncCurrentVersion348374EF7ba836ac0b5250e9b7fd41805d4a042a destroy
[+] AWS::Lambda::Version Func/CurrentVersion FuncCurrentVersion348374EFf8af8e354054f8991a63e3b66f5c1d16 
[~] AWS::Lambda::Function Func Func217E03A4 
 └─ [~] Code
     └─ [~] .ZipFile:
         ├─ [-] def handler(_, _): return {"foo": "bar"}
         └─ [+] def handler(_, _): return {"foo": "bar"} 
[~] AWS::Lambda::Alias LambdaAlias LambdaAlias9C15A666 
 └─ [~] FunctionVersion
     └─ [~] .Fn::GetAtt:
         └─ @@ -1,4 +1,4 @@
            [ ] [
            [-]   "FuncCurrentVersion348374EF7ba836ac0b5250e9b7fd41805d4a042a",
            [+]   "FuncCurrentVersion348374EFf8af8e354054f8991a63e3b66f5c1d16",
            [ ]   "Version"
            [ ] ]

And then I run cdk deploy to get it deployed. It works great with no error messages.

@pahud pahud added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Dec 15, 2023
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants