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:

  1. Update the definition for GetTheFunnyPhraseText to add DeletionPolicy: "Retain", upload to CloudFormation
  2. Remove GetTheFunnyPhraseText entirely from your template. Upload to CloudFormation. This will not actually delete the underlying Lambda because of the previously added DeletionPolicy
  3. Revert your template back to the previous state in Step #1 (add GetTheFunnyPhraseText back) and change the logical name to GetFunnyPhrase
  4. Start the "Stack Actions" > "Import resources into stack" workflow.
  5. Upload your reverted template (with the changed logical name, still including the DeletionPolicy)
  6. The import process will notice the new GetFunnyPhrase logical name and ask you what actual FunctionName should be mapped to that name. Provide the existing GetFunnyPhrase Lambda name and complete the import.
  7. 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.