aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(aws-cloudfront): changing Function name breaks deployment

Open flavioleggio opened this issue 3 years ago • 8 comments

What is the problem?

When a CloudFront Function is created with a specific value in the functionName attribute, changing it afterwards breaks the deployment with this error: Resource handler returned message: "Resource of type 'AWS::CloudFront::Function' with identifier 'MyFunction' was not found."

Reproduction Steps

Create and deploy a stack with a function and specify a functionName

const rewriteFunction = new Function(this, "RewriteFunction", {
  code: FunctionCode.fromInline(`function handler(event) {  return request; }`),
  functionName: "MyFunction",
});

Change the function name and deploy again

const rewriteFunction = new Function(this, "RewriteFunction", {
  code: FunctionCode.fromInline(`function handler(event) {  return request; }`),
  functionName: "MyFunctionWithANewName",
});

What did you expect to happen?

This change should require a resource replacement (as one cannot really change a function name after it is created), creating a new Function with that name and then removing the old Function.

What actually happened?

The error Resource handler returned message: "Resource of type 'AWS::CloudFront::Function' with identifier 'MyFunctionWithANewName' was not found." is thrown during the second deploy.

CDK CLI Version

2.10.0

Framework Version

2.10.0

Node.js Version

v16.13.0

OS

Linux

Language

Typescript

Language Version

4.1.3

Other information

No response

flavioleggio avatar Feb 17 '22 11:02 flavioleggio

Hey @flavioleggio,

Thank you for reporting this! In this case this was born of a misunderstanding, but we appreciate any and all reports that could help improve the CDK in the future.

To clear up the misunderstanding. This is a problem with how Cloudformation handles resource Logical IDs. Because LogicalIDs are the root level unique identifiers within Cloudformation, when one is changed and the new template deployed, cloudformation views it as a deletion of the resource with the original logicalID and the creation of a new resource with the new logicalID. This can break update deployment. The best way to resolve this conflict is to delete the original stack and redeploy the update as a new stack, or to unblock with renameLogicalId().

I hope this helps resolve your issue!

NGL321 avatar Feb 21 '22 04:02 NGL321

Hi @NGL321,

Thank you for your support on this. I still don’t get why this is an issue with LogicalIDs though. In my example scenario the Function’s construct ID RewriteFunction is the same in the second deploy: the only change is the functionName attribute.

flavioleggio avatar Feb 21 '22 08:02 flavioleggio

I've found the same behavior as you. This is an issue with the way CloudFormation handles the functionName attribute. Typically, changing the name of a CfnResource will cause a resource replacement. However in this case, it causes no interruption

Reported internally to Cfn team. Tracking: V528982041

peterwoodworth avatar Feb 22 '22 23:02 peterwoodworth

Making a change to the logical ID at the same time as changing the physical name is the recommended workaround to trigger a resource replacement

peterwoodworth avatar Feb 23 '22 17:02 peterwoodworth

Closing - Ticket has been addressed internally. Please let me know if you continue to run into this issue

peterwoodworth avatar Jun 21 '22 22:06 peterwoodworth

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

github-actions[bot] avatar Jun 21 '22 22:06 github-actions[bot]

@peterwoodworth thanks for reporting this to the internal CFN team. However, I've experienced the issue no later than yesterday and it still seems that there are no fix deployed at the moment. See issue https://github.com/getlift/lift/issues/247#issuecomment-1208195082 for additional information.

Can you help on the matter ?

fredericbarthelet avatar Aug 09 '22 13:08 fredericbarthelet

You're right, I can still reproduce this. I'll bring this back up with the service team

peterwoodworth avatar Aug 09 '22 18:08 peterwoodworth

I'm experiencing the same issue. Any feedback from the service team?

Changing the Logical ID simultaneously with the physical one worked for me.

redaLaanait avatar Oct 10 '22 18:10 redaLaanait

Ok it should be fixed now. I was able to test this and it works. Please feel free anyone to ping me again if you run into any errors

peterwoodworth avatar Dec 20 '22 21:12 peterwoodworth

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

github-actions[bot] avatar Dec 20 '22 21:12 github-actions[bot]

I had the same issue now

MrBahur avatar Mar 31 '24 13:03 MrBahur