CloudFormation names are the identifiers you give your stacks, and optionally tag onto the resources inside them, so you can find, reference and manage infrastructure reliably. There is no single "set the name" field: a stack gets a name when you create it (and that name cannot be changed later), while resource logical IDs are fixed in the template and physical names are set per resource with properties such as BucketName or FunctionName. If you are only just starting, read the steps below in order, because a mistake in the first decision (stack name) is the one you cannot undo without recreating everything.
What You'll Need
- An AWS account with permission to create and update CloudFormation stacks, plus whatever services the template touches.
- A template file (YAML or JSON) or a stack you can already see in the console, so you have something concrete to name.
- AWS CLI or SDK configured if you plan to script creation, or just the CloudFormation console in the browser.
- A short naming convention agreed in advance, especially if more than one person deploys. Labels in menus can differ slightly by console version and region.
Step-by-Step
- Decide the stack name before you click create. In the console, go to CloudFormation and choose Create stack. The stack name field accepts letters, numbers and hyphens; it must start with a letter and cannot contain spaces, underscores or most punctuation. Use a pattern like
web-prod-apiornetwork-dev: application, environment, then component. Whatever you type here becomes part of the stack's ARN and shows up in every log, tag and CLI command, so spell it deliberately. - Accept that the stack name is permanent. There is no rename. Changing it means creating a new stack from the same template and deleting the old one, which can mean replacing resources. Because of that, put the environment in the name from day one rather than "temp" or "test2".
- Keep logical IDs stable inside the template. Every resource has a logical ID you write yourself, such as
ApiBucketorWebServerSecurityGroup. CloudFormation uses these IDs to match resources across updates. If you rename one, CloudFormation sees a brand-new resource and a deleted one, which typically means downtime and data loss. Treat logical IDs as code: pick a clear name once and leave it. - Set physical names per resource, only where you need one. Logical IDs are internal; the actual name in the AWS service is separate. For S3 you set
BucketName, for LambdaFunctionName, for a security groupGroupName. If you omit these, CloudFormation generates a name that includes the stack name, the logical ID and a random suffix, which is unique and safe but not pretty. - Prefer generated names for most resources. Hard-coding a physical name means the template can only ever be deployed once per account and region, and a failed rollback can leave the name occupied so the next attempt collides. Add a
Nametag instead: tags can be changed freely and are usually what people actually want for billing and searching. UseDeletionPolicyand tags to control behaviour, not fixed names. - Add consistent tags across the stack and its resources. In the console, on the options screen, enter tags such as
Environment,OwnerandCostCenter. CallPropagateAtLaunchstyle propagation where relevant, or set tags in the template'sTagssection so every resource inherits them. This is how you group resources that have ugly generated names. - Reference names safely elsewhere. Do not copy a generated physical name into a script or another stack by hand. Export it with
OutputsandFn::ImportValue, or read it with a parameter. Exported values have their own names, so choose those with the same convention and never remove an export that another stack still imports. - Script it if you deploy often. With the AWS CLI,
aws cloudformation create-stack --stack-name web-prod-api --template-body file://template.yamlmakes the name explicit and repeatable. Keep the name in a variable, or derive it from branch and environment, so nobody types it by hand. - Check the result. After creation, look at the stack's Resources tab and confirm the physical IDs match what you expect. Use the Outputs tab for anything you need to reference, and verify tags appear on the underlying resources, not just on the stack.
Common Mistakes
The most expensive mistake is renaming a logical ID in a live template. CloudFormation will delete and recreate that resource, and for a database or a bucket that can mean lost data. Snapshot or back up first and read the change set before applying. Second is hard-coding physical names for resources that only allow one per account, then wondering why a second deployment in another region or account fails. Third is using a stack name that collides with an existing stack: CloudFormation will refuse to create it, and if you use update instead you may apply the wrong template to the wrong environment. Fourth is putting random suffixes or spaces in names; a space or underscore in a bucket name is rejected by S3 itself, and the error message often points at the resource rather than the name you typed.
Tips
Adopt a fixed pattern such as app-env-component and document it in the repository README so new team members follow it. Keep environment names short and unambiguous: dev, stg, prod. Put the region in a tag rather than the stack name if you deploy the same stack to several regions, and rely on exports plus tags for cross-stack wiring. For anything with a generated name, always expose it through Outputs so nobody has to guess or hunt for it. When a template grows, split it into nested stacks named after the component they own; the parent stack name plus the child name reads clearly in the console.
Troubleshooting
If creation fails immediately with an already-exists error, the name is in use or a hard-coded resource name is taken. Choose a different stack name or remove the fixed physical name and let CloudFormation generate it. If an update wants to replace a resource you did not intend to touch, check whether you renamed a logical ID; revert the rename and use a physical name property instead if you only wanted a cosmetic change. If a rollback leaves a stack in a bad state, look at the Events tab, find the first failed resource and read its status reason before retrying. If an output or export import fails, confirm the export exists in the same region: exports are regional and cannot cross regions. If the console refuses a name, check for spaces, underscores or a leading digit. If you are unsure whether a change is safe, create a change set first; it lists every resource that will be replaced, modified or deleted without doing anything.
Frequently Asked Questions
Can I rename a CloudFormation stack?
No. The stack name is fixed at creation. Create a new stack from the same template and delete the old one, after checking that resources will not be replaced unexpectedly.
What is the difference between a logical ID and a physical name?
The logical ID is the name you write in the template and is used to track the resource across updates. The physical name is what appears in the AWS service, set by properties like BucketName or generated by CloudFormation.
Why does my resource have a random suffix?
You did not specify a physical name, so CloudFormation generated one from the stack name, logical ID and a unique suffix. That is normal and usually preferable.
Should I hard-code names in my template?
Only when a service or external system requires the exact name. Hard-coded names prevent deploying the same template twice in one account and region.
Do stack names need to be unique?
Yes, within an account and region. The same name can exist in different regions, so keep the region in mind when scripting.
How do other stacks use a name from mine?
Export it in Outputs and import it with Fn::ImportValue. Exports must stay in place while another stack still imports them.