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_cloudfront.experimental): EdgeFunction fails updating when upgrading to cdk v2 #17810

Closed
ChristopheBougere opened this issue Dec 2, 2021 · 4 comments
Assignees
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@ChristopheBougere
Copy link
Contributor

ChristopheBougere commented Dec 2, 2021

What is the problem?

I'm trying to upgrade my app to CDK v2.
I have a cloudfront.experimental.EdgeFunction in my main stack (which is used in substacks). After upgrading everything to V2 and bootstraping again, CloudFormation is failing with the following error:

10:49:44 AM | CREATE_FAILED        | AWS::Lambda::Version  | RestrictAccessEdge...629462996c470bbb91
A version for this Lambda function exists ( 1 ). Modify the function to create a new version.

Reproduction Steps

  1. Create a CDK v1 app with an EdgeFunction in it
  2. Deploy
  3. Upgrade to CDK v2
  4. Deploy

What did you expect to happen?

I was expecting it to deploy without error (as nothing changed in my code, I just upgraded).

The Lambda function shouldn't be created, but just modified.

What actually happened?

The Edge function fails creating. Here is the interesting part of cdk diff I ran before deploying:

Resources
[-] AWS::Lambda::Version RestrictAccessEdgeFunctionCurrentVersionA87D60F494b86fd8435f5dce07302a87028ff01e destroy
[+] AWS::Lambda::Version RestrictAccessEdgeFunction/CurrentVersion RestrictAccessEdgeFunctionCurrentVersionA87D60F47ecea2cf5ada66629462996c470bbb91 
[~] AWS::Lambda::Function RestrictAccessEdgeFunction RestrictAccessEdgeFunction5C4CA0E6 
 ├─ [~] Code
 │   ├─ [~] .S3Bucket:
 │   │   └─ @@ -1,3 +1,1 @@
 │   │      [-] {
 │   │      [-]   "Ref": "AssetParameterse7f76f1b20436e50e6357e4d63dc4c8b238f3a309bbe7ae2557b87198b95e6d5S3Bucket479C8589"
 │   │      [-] }
 │   │      [+] "cdk-hnb659fds-assets-127166862509-us-east-1"
 │   └─ [~] .S3Key:
 │       └─ @@ -1,33 +1,1 @@
 │          [-] {
 │          [-]   "Fn::Join": [
 │          [-]     "",
 │          [-]     [
 │          [-]       {
 │          [-]         "Fn::Select": [
 │          [-]           0,
 │          [-]           {
 │          [-]             "Fn::Split": [
 │          [-]               "||",
 │          [-]               {
 │          [-]                 "Ref": "AssetParameterse7f76f1b20436e50e6357e4d63dc4c8b238f3a309bbe7ae2557b87198b95e6d5S3VersionKey4C291A8A"
 │          [-]               }
 │          [-]             ]
 │          [-]           }
 │          [-]         ]
 │          [-]       },
 │          [-]       {
 │          [-]         "Fn::Select": [
 │          [-]           1,
 │          [-]           {
 │          [-]             "Fn::Split": [
 │          [-]               "||",
 │          [-]               {
 │          [-]                 "Ref": "AssetParameterse7f76f1b20436e50e6357e4d63dc4c8b238f3a309bbe7ae2557b87198b95e6d5S3VersionKey4C291A8A"
 │          [-]               }
 │          [-]             ]
 │          [-]           }
 │          [-]         ]
 │          [-]       }
 │          [-]     ]
 │          [-]   ]
 │          [-] }
 │          [+] "e7f76f1b20436e50e6357e4d63dc4c8b238f3a309bbe7ae2557b87198b95e6d5.zip"
 └─ [~] Metadata
     ├─ [+] Added: .aws:asset:is-bundled
     └─ [+] Added: .aws:asset:original-path
[~] AWS::SSM::Parameter RestrictAccessEdgeFunction/Parameter RestrictAccessEdgeFunctionParameter1F7BBEA8 
 └─ [~] Value
     └─ [~] .Ref:
         ├─ [-] RestrictAccessEdgeFunctionCurrentVersionA87D60F494b86fd8435f5dce07302a87028ff01e
         └─ [+] RestrictAccessEdgeFunctionCurrentVersionA87D60F47ecea2cf5ada66629462996c470bbb91

We can see that a / has been added in the AWS::Lambda::Version logical ID, I wonder if that is the cause.

CDK CLI Version

2.0.0 (build 4b6ce31)

Framework Version

2.0.0

Node.js Version

v14.16.0

OS

macOS 12.0.1

Language

Typescript

Language Version

3.9.7

Other information

No response

@ChristopheBougere ChristopheBougere added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 2, 2021
@github-actions github-actions bot added the @aws-cdk/aws-cloudfront Related to Amazon CloudFront label Dec 2, 2021
@encron
Copy link
Contributor

encron commented Dec 5, 2021

I seemed to have the exact same issue, although using the NodejsFunction construct for my Lambda@Edge functions. I then read about this part https://docs.aws.amazon.com/cdk/api/latest/docs/aws-lambda-readme.html#currentversion-updated-hashing-logic, where it talks about a bug that would try to create a new version although the code wasn't actually changed but like in this case, only the metadata was updated. So I added the feature flag (@aws-cdk/aws-lambda:recognizeVersionProps) and also added the minify: true flag to my bundling options to actually "change" the code and produce a new version and that seems to have solved it.

I might be wrong, but my guess is that I was only encountering this bug now since previously my functions' metadata or tags were never updated, or only updated when the code itself also changed. Not sure if this is also what is happening in your case, but thought it might be useful to share :)

@ChristopheBougere
Copy link
Contributor Author

Thank you so much for pointing me to this @encron
After adding the @aws-cdk/aws-lambda:recognizeVersionProps it worked like a charm.
I also had to fix a dependency conflict between 2 stacks, which I did by following this solution.

@njlynch As this feature flag is pretty new (I think?), and as the migration guide advice us to drop all the feature flags, it might be a good thing to add this error to the Troubleshooting section of the migration guide? Otherwise, we can close this issue.

Thanks again @encron 🙏

njlynch added a commit that referenced this issue Dec 6, 2021

Verified

This commit was signed with the committer’s verified signature.
yyx990803 Evan You
The `@aws-cdk/aws-lambda:recognizeVersionProps` feature flag has always had the
"future" behavior set to "true", meaning any new projects get the flag set to
true. All of these style flags were intended to default to true as well for v2,
but this one was missed. The end result is that users who have created a new v1
project anytime in the last ~6 months, and then upgrade to v2, actually
experience a _downgrade_ in behavior if following the offical migration guide
(which instructs users to delete all feature flags).

This change fixes the behavior to work as intended. Users who wish to opt out
can continue to set `@aws-cdk/aws-lambda:recognizeVersionProps` to false in
their `cdk.json`.

fixes #17810
@njlynch
Copy link
Contributor

njlynch commented Dec 6, 2021

Thanks for the bug report, @ChristopheBougere !

This is a regression in behavior with V2. The intent was that any feature flag that was previously set to "true" for new projects, was automatically handled as "true" by default in v2 (without needing the flag to be set). Somehow this one got lost in the shuffle and reverted back to v1 behavior, where the flag needs to be explicitly set. I've created a fix (#17866), which should (🤞 ) go out with the next v2 release.

mergify bot pushed a commit that referenced this issue Dec 7, 2021
…ly (#17866)

The `@aws-cdk/aws-lambda:recognizeVersionProps` feature flag has always had the
"future" behavior set to "true", meaning any new projects get the flag set to
true. All of these style flags were intended to default to true as well for v2,
but this one was missed. The end result is that users who have created a new v1
project anytime in the last ~6 months, and then upgrade to v2, actually
experience a _downgrade_ in behavior if following the offical migration guide
(which instructs users to delete all feature flags).

This change fixes the behavior to work as intended. Users who wish to opt out
can continue to set `@aws-cdk/aws-lambda:recognizeVersionProps` to false in
their `cdk.json`.

fixes #17810


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@njlynch njlynch closed this as completed Dec 7, 2021
@github-actions
Copy link

github-actions bot commented Dec 7, 2021

⚠️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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

3 participants