We have multiple AWS stacks for our application (dev, test, prod, etc). These are all created with Cloud Formation templates. Some bright person before me decided to use a different template for the prod stack to the rest. I'd like to consolidate to only having one Cloud Formation template.
I've done a file comparison between the two templates and the only difference is the Logical ID of the RDS instance. So we have something like this:
"MyDbInstanceDev": {
"Type": "AWS::RDS::DBInstance",
"Properties": {
"AllocatedStorage": "200",
"CopyTagsToSnapshot" : true,
"DBInstanceClass": "db.m3.medium",
Verses:
"MyDbInstance": {
"Type": "AWS::RDS::DBInstance",
"Properties": {
"AllocatedStorage": "200",
"CopyTagsToSnapshot" : true,
"DBInstanceClass": "db.m3.medium",
If I change the logical ID from "MyDbInstanceDev" to "MyDbInstance" though, cloud formation thinks that I want to delete the existing RDS instance and create a new one in the stacks where the original template had a the old logical ID.
Is there some way I can change the logical ID and make all my stacks have the same template without losing the DB?
No. You cannot do that using CFT as CFT maintains the state of stack (you can't see it though). Even if you rename the DBInstance, you will face problems down the road if you try to delete the stack.
You can use DBInstanceIdentifier as parameter and every time you want to create the DB, you create a new stack deployment and not update stack. Logical Id of the CFT resource does not have much significance unless you are auto naming the resources.
To fix your existing deployments, do this:
MyDbInstanceDev.RestoreFromDBSnapshotIdentifier in
MyDbInstance CFT.DBSnapshotIdentifier property to MyDbInstance and set it conditionally if RestoreFromDBSnapshotIdentifier is not blank.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With