Renaming Resource in CloudFormation Template
Now that CloudFormation import is available it's technically possible to do this, although it's tedious.
Here's what you'd need to do:
- Update the definition for
GetTheFunnyPhraseText
to addDeletionPolicy: "Retain"
, upload to CloudFormation - Remove
GetTheFunnyPhraseText
entirely from your template. Upload to CloudFormation. This will not actually delete the underlying Lambda because of the previously addedDeletionPolicy
- Revert your template back to the previous state in Step #1 (add
GetTheFunnyPhraseText
back) and change the logical name toGetFunnyPhrase
- Start the "Stack Actions" > "Import resources into stack" workflow.
- Upload your reverted template (with the changed logical name, still including the
DeletionPolicy
) - The import process will notice the new
GetFunnyPhrase
logical name and ask you what actualFunctionName
should be mapped to that name. Provide the existingGetFunnyPhrase
Lambda name and complete the import. - Finally, you can re-upload your template and remove the
DeletionPolicy
A tedious process for sure, but technically possible if you really don't want to delete the existing resource.
No! Renaming a resource's logical name is not possible in Cloud Formation.
As you tested as well, CloudFormation sees it as the removal of the old resource and creation of the new one. This is so because the logical resource IDs are bound to the physical IDs of the resources by CloudFormation after creation. But for CloudFormation template language, it only recognizes the logical ID while parsing the template so any changes to that would mean the resource associated to it is going to be changed.
In some resource types though you can set the physical IDs yourself by using certain name properties which are resource-specific, for example a resource AWS::RDS::DBInstance
may have a property DBInstanceIdentifier
which will be the physical name of the db instance itself.