(aws-cloudfront): changing Function name breaks deployment
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
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!
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.
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
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
Closing - Ticket has been addressed internally. Please let me know if you continue to run into this issue
⚠️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.
@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 ?
You're right, I can still reproduce this. I'll bring this back up with the service team
I'm experiencing the same issue. Any feedback from the service team?
Changing the Logical ID simultaneously with the physical one worked for me.
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
⚠️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.
I had the same issue now