What Does CloudFormation Stack Mean?
On This Page
Quick Definition
A CloudFormation Stack is a way to group and manage related AWS resources, like servers and databases, as a single package. You define everything in a template file, and AWS automatically creates or updates all the resources for you. This makes deploying and managing infrastructure faster and more reliable.
Commonly Confused With
A CloudFormation Stack is a live collection of resources managed by the AWS-native IaC service. A Terraform state file is a local or remote file that Terraform uses to map its configuration to the real-world resources it manages. Unlike CloudFormation, Terraform supports multiple cloud providers, and the state file is not a deployment unit in itself.
With CloudFormation, you create a stack from a template, and the stack exists in AWS. With Terraform, you write a configuration, run `terraform apply`, and Terraform creates a state file that keeps track of what it created. The state file is not called a stack.
An Elastic Beanstalk environment is a higher-level abstraction that automatically manages the infrastructure (EC2, load balancer, etc.) for a web application. CloudFormation Stacks give you lower-level control and you define every resource yourself. Elastic Beanstalk uses CloudFormation under the hood to create its stacks, but you interact primarily with the Elastic Beanstalk service.
If you want to quickly deploy a web app without worrying about the infrastructure details, use Elastic Beanstalk. If you need full control over the virtual network, IAM roles, and security groups, use CloudFormation Stacks.
Ansible is a configuration management tool that focuses on installing software and configuring existing servers. CloudFormation is an Infrastructure as Code tool focused on provisioning cloud infrastructure. They can be used together: CloudFormation provisions the servers, and Ansible configures the software on those servers. A stack is not a playbook, and a playbook is not a stack.
A CloudFormation stack creates the EC2 instance and security group. An Ansible playbook then connects to that instance and installs the web server software. You would not use CloudFormation to install software, nor Ansible to create a VPC.
Must Know for Exams
For general IT certifications, especially the AWS Certified Cloud Practitioner, AWS Certified Solutions Architect (Associate and Professional), and the AWS Certified Developer Associate, CloudFormation Stack is a high-frequency topic. It appears in the Infrastructure as Code domain and in questions about automated deployments and resource management.
On the AWS Certified Cloud Practitioner exam, you are expected to understand the basic purpose of CloudFormation and stacks: that they allow you to manage AWS infrastructure as code, that they help with consistency, and that they are an automated way to provision resources. You will likely see multiple-choice questions asking which service is best for templated infrastructure deployment or for ensuring all resources are created in the correct order.
On the Solutions Architect Associate exam, the depth increases. You need to know how stacks use parameters, outputs, and cross-stack references. Scenario-based questions may ask you to design a solution where a web application stack needs to reference a database from another stack. You must recognize that using CloudFormation outputs and Fn::ImportValue is the correct approach to pass information between stacks. Troubleshooting questions might cover why a stack update failed and how to read the stack events to find the root cause.
For the Developer Associate exam, you will see questions about the template structure, intrinsic functions, and how to manage stack updates with change sets. You may be asked to identify which IAM permissions are required for CloudFormation to create resources on your behalf, or how to protect a stack from accidental deletion using stack policies and termination protection.
In all cases, the core concept of a stack as a managed group of resources that can be created, updated, and deleted together is the foundation. Understanding the lifecycle, rollback behavior, and the principle that the template is the single source of truth is the key to answering these questions correctly.
Simple Meaning
Imagine you are building a model house from a kit. The kit comes with a detailed instruction booklet that lists every piece you need, like walls, windows, doors, and roof tiles, and tells you exactly how to put them together. Each time you want to build that house, you follow the same instructions, and you get the same house every time.
A CloudFormation Stack works exactly like that, but for computer infrastructure in the cloud. Instead of a model house, you are building a web application or a database system. Instead of physical pieces, you are using virtual resources like virtual servers, databases, and network settings. The instruction booklet is called a CloudFormation template. It is a text file written in a special format that describes every resource you need and how they connect.
When you tell AWS to use that template, it creates a "stack". The stack is the actual running collection of resources that AWS builds for you based on the template. If you need to change something, you update the template, and AWS updates the stack automatically. If you no longer need the application, you delete the stack, and AWS removes everything it created, so you do not accidentally leave old resources running and costing money.
This is much better than building everything by hand, which is slow and error-prone. With stacks, you can create an entire application environment in minutes, knowing that everything is set up exactly as you specified, every single time.
Full Technical Definition
A CloudFormation Stack is the fundamental deployment unit within AWS CloudFormation, a managed Infrastructure as Code (IaC) service. It represents a live, running collection of AWS resources that are provisioned and managed as a cohesive group based on a declarative template. The template, authored in JSON or YAML format, defines the desired state of the infrastructure. When the template is submitted to CloudFormation, the service interprets it, determines the necessary API calls to the relevant AWS services (such as EC2, RDS, S3, IAM), and orchestrates the creation or update of the resources in the correct order, respecting dependencies.
Every stack has a unique name within an AWS region and account, and all resources within the stack are tagged with a tag that identifies them as belonging to that stack. This enables lifecycle management: any operation on the stack, like update or deletion, applies to all resources within it. Stacks can also reference outputs from other stacks, enabling cross-stack communication and layered architectures. CloudFormation uses change sets to preview the impact of changes before applying them. If an update fails, CloudFormation can automatically roll back to the last known stable state, a feature called stack rollback.
Stacks support parameters, which allow users to pass custom values into the template at creation or update time, making templates reusable across different environments (e.g., dev, test, production). Mappings allow template creators to define lookup tables for region-specific values like AMI IDs. Conditions control whether certain resources are created based on parameter values or environment rules. The intrinsic functions, like Ref and Fn::GetAtt, allow resources to reference each other’s properties, such as an EC2 instance ID or a security group ID, ensuring that the template is self-contained.
In real IT implementations, CloudFormation Stacks are essential for automating multi-tier application deployments. For example, a stack might include a VPC with subnets, an Application Load Balancer, an Auto Scaling group of EC2 instances, an RDS database, and IAM roles. The entire environment can be replicated across multiple regions or accounts by using the same template with different parameters. CloudFormation StackSets extend this capability by allowing a single template to be deployed across multiple accounts and regions from a central administrator account.
Real-Life Example
Think about how a catering company sets up for a large wedding reception. They do not run around randomly placing tables and chairs. Instead, they have a standard setup plan: a dance floor in the center, round tables for guests around the edge, a head table at the front, a buffet line along the side, and specific lighting fixtures above. This setup plan is their template. Each wedding is a different event, but the pattern for the layout remains the same. The catering team just adjusts the number of tables based on the guest count.
In this analogy, a CloudFormation Stack is the actual wedding reception setup at a particular venue. The template is the floor plan, the stack is the physical arrangement of tables, chairs, lights, and buffet stations that are all put up together. If the bride decides to move the buffet line to the other side, the catering team updates the floor plan (the template) and then rearranges everything in the stack (update). When the wedding is over, they tear down the entire setup, just like deleting a stack removes all the resources.
The wedding coordinator is like CloudFormation itself. The coordinator does not personally carry tables but tells the team what to do, in what order, and ensures that everything works together. If the band needs a stage, the coordinator makes sure the stage is set up before the sound system is installed. Similarly, CloudFormation creates a database before the application servers that need it. This coordinated approach prevents chaos and ensures that every wedding (or every application environment) is consistent and runs smoothly.
Why This Term Matters
In practical IT, managing infrastructure manually through the AWS console is quick for a single server but becomes unmanageable and error-prone as environments grow. A CloudFormation Stack addresses this by providing a repeatable, automated, and version-controlled way to deploy infrastructure. This matters because it directly impacts deployment speed, consistency, and cost control.
For example, if you need to set up a development environment that mirrors production, you do not have to manually click through the console fifty times. You simply run the same template with different parameters, and CloudFormation builds the entire environment automatically. This eliminates the risk of misconfigurations, such as accidentally leaving a database publicly accessible. Since the template is code, it can be stored in a version control system like Git, giving teams a clear history of infrastructure changes.
From a cost perspective, stacks make it easy to spin up temporary environments for testing or demos and then delete everything when done. Without stacks, it is common to forget to terminate resources, leading to wasted spending. With stacks, a single delete command removes all associated resources. In large organizations, CloudFormation Stacks are also used to enforce compliance. Security teams can create approved templates that include required encryption settings, logging, and network configurations, and development teams must use those templates, ensuring every stack meets security standards.
How It Appears in Exam Questions
CloudFormation Stack questions on certification exams typically fall into three categories: scenario-based, configuration-based, and troubleshooting-based.
Scenario-based questions present a business requirement and ask which AWS service or feature best meets the need. For example: A company needs to deploy a three-tier web application across multiple environments (dev, test, prod) with consistent configurations. The question might list options like using the AWS Management Console, using shell scripts with the AWS CLI, or using CloudFormation. The correct answer is CloudFormation, because it provides a template-driven, consistent, and automated deployment. The term "stack" itself might be tested as part of the answer, for example, "Create a CloudFormation Stack from a template."
Configuration-based questions give you a snippet of a CloudFormation template or describe a scenario where you need to choose the correct template syntax. You might be shown a YAML template with a resource definition and asked what will happen when the stack is created. For instance: A template defines an EC2 instance and an RDS database, and the EC2 instance has a SecurityGroup property referencing the RDS database. The question asks which of the following is true about stack creation. The correct understanding is that CloudFormation will create the RDS instance first because the EC2 instance depends on it, and then create the EC2 instance.
Troubleshooting-based questions describe a stack that failed to create or update and present a set of log messages or stack events. You may be asked to identify the root cause. For example: A stack creation failed at the step of creating an RDS DB instance, and the error message says "The DB instance already exists." The correct conclusion is that the DB instance name is not unique, and you need to use a parameter to generate unique names. Another question might describe a stack update that succeeded in creating new resources but failed to delete an old resource, leading to rollback. The question asks what you should do to prevent this rollback in the future, and the correct answer is to use a change set first to preview the changes and identify the potential conflict.
Practise CloudFormation Stack Questions
Test your understanding with exam-style practice questions.
Example Scenario
You are a junior cloud administrator at a small company that runs a customer-facing web application. The application uses three main parts: a web server to serve the site, a database to store customer information, and a network setup that allows secure access. Currently, you have one set of these resources running in the AWS cloud, set up manually over several weeks.
One day, your manager says the company needs a separate testing environment that is an exact copy of the production environment but with smaller servers to save money. Doing this manually would take a full day, and you might miss a configuration setting, causing the test environment to behave differently.
Instead, you use AWS CloudFormation. You already have a template file that describes the production environment. You open that template and change the parameter for the server instance size to a smaller type. Then you use the AWS console to create a new stack, providing a name like "test-environment" and the modified template. Within minutes, CloudFormation creates everything: a new VPC with subnets, a web server, and a database, all identical to production except for the smaller servers.
Later, when the testing is done, you delete the stack. CloudFormation removes all the resources it created for that stack-the VPC, the server, the database-ensuring you do not continue paying for unused resources. This scenario shows how a CloudFormation Stack makes environment replication fast, accurate, and easy to clean up. Without it, you would have to manually delete each resource, risking leftover components and forgotten charges.
Common Mistakes
Thinking that deleting a CloudFormation Stack only deletes the template, not the actual resources.
Deleting a CloudFormation Stack deletes ALL the resources that were created as part of that stack. The template itself remains as a file, but the live resources (EC2 instances, databases, etc.) are terminated.
Always remember that the stack is the live collection of resources. Deleting the stack means deleting all those resources. If you want to keep the resources, you must delete the stack carefully or first remove the resources from the stack.
Believing that resource creation order in a stack is random or based on the order in the template.
CloudFormation automatically determines the creation order based on dependencies between resources. If resource A references resource B (e.g., an EC2 instance references a security group), CloudFormation creates resource B first. The order in the template file does not matter.
You do not need to arrange resources in any particular order. Just define the resources and use intrinsic functions like Ref and Fn::GetAtt to establish dependencies. CloudFormation will handle the creation sequence.
Assuming that a stack can be updated manually by changing resources outside of CloudFormation (e.g., logging into the EC2 console and resizing an instance).
If you manually modify a resource that belongs to a stack, the stack becomes out of sync with the template. CloudFormation considers this a "drift." The next time you try to update the stack, CloudFormation may try to revert the manual change or fail because of unexpected state. This undermines the benefit of Infrastructure as Code.
Always manage stack resources through CloudFormation. If you need to change a resource, edit the template and update the stack. Use the Drift Detection feature regularly to check if any manual changes have occurred and correct them by updating the stack.
Thinking that you can reuse the same template to create multiple stacks without any changes, even if the resources have globally unique names (like a bucket name).
Many AWS resources (like S3 bucket names, RDS instance identifiers) must be globally unique. If the template hardcodes a name, the second stack creation will fail because the name is already taken.
Use parameters or the AWS::StackName pseudo-parameter to generate unique names. For example, for an S3 bucket, you can set the bucket name to something like "myapp-bucket-" followed by the stack name or a random string.
Exam Trap — Don't Get Fooled
{"trap":"The exam asks: \"What happens to an EC2 instance that was created as part of a CloudFormation Stack if you terminate it manually using the EC2 console?\" The popular wrong answer is that the instance will be recreated automatically.","why_learners_choose_it":"Learners confuse CloudFormation's desired-state model with Auto Scaling.
In Auto Scaling, terminating an instance triggers the Auto Scaling group to launch a replacement. In CloudFormation, the stack is not monitoring the instance's health. It only manages creation and updates, not runtime health."
,"how_to_avoid_it":"Understand that CloudFormation is a provisioning tool, not a management tool. It ensures the infrastructure is set up as defined in the template at deployment time. Once the stack is created, terminating a resource manually will not automatically cause CloudFormation to recreate it.
However, if you update the stack, CloudFormation will notice the missing resource (if the template still expects it) and will try to recreate it during the update. The better answer is that the resource is simply gone, and the stack enters a \"drifted\" state."
Step-by-Step Breakdown
Author the Template
You write a JSON or YAML file that declares all the AWS resources you need. Each resource is defined with its type (e.g., AWS::EC2::Instance) and properties (e.g., image ID, instance type). You can also include parameters, conditions, and outputs. This template is the blueprint for the stack.
Create the Stack
You submit the template to AWS CloudFormation, either via the console, the CLI, an SDK, or an API. You must provide a stack name and any parameter values that the template requires. CloudFormation then begins orchestrating the resource creation.
Resource Provisioning Orchestration
CloudFormation analyzes the template to determine the correct order of operations. It identifies dependencies between resources and creates them in the necessary sequence. It makes API calls to the respective AWS services on your behalf, using your IAM permissions. For example, it first creates a VPC, then subnets, then security groups, then EC2 instances that depend on those groups.
Stack Lifecycle Management
Once all resources are successfully created, the stack enters the CREATE_COMPLETE state. You can then interact with the resources normally. If you need to update the application, you modify the template and initiate a stack update. CloudFormation creates a change set, which you can review, and then applies the changes, either updating in place or replacing resources as needed.
Deletion and Cleanup
When the stack is no longer needed, you delete it. CloudFormation automatically identifies every resource in the stack and sends the corresponding delete API calls. It respects dependencies and deletes resources in the correct order (e.g., deletes EC2 instances before the VPC). This ensures a clean removal without orphaned resources. The stack then enters the DELETE_COMPLETE state.
Drift Detection (Optional but Important)
Over time, someone might manually modify a resource that belongs to the stack. This creates a drift between the stack's template and the actual configuration. You can run drift detection, which compares the live configuration of each resource to what the template expects. The stack can be in a DRIFTED state, allowing you to take corrective action by updating the stack to align with the template.
Practical Mini-Lesson
In professional practice, CloudFormation Stack management goes far beyond just creating one stack. As a DevOps engineer, you will often work with nested stacks, where a parent stack calls other stacks to create reusable components like a network layer or a database layer. This modular approach mirrors how you write reusable code functions. For example, you might have a "network-stack" template that creates a VPC with public and private subnets, and then your application stack references that stack by using the AWS::CloudFormation::Stack resource type. This allows you to update the network configuration in one place and have all dependent stacks automatically benefit from the change on their next update.
Another key practice is using stack policies. A stack policy is a JSON document that defines which resources can be updated or replaced during a stack update. This is crucial for protecting critical resources like databases. For instance, you can set a policy that prevents RDS database instances from being replaced unless a special override is used. This prevents accidental data loss if someone mistakenly updates the template to change the database engine version without proper testing.
When working with multiple stacks that depend on each other, you must manage cross-stack references carefully. The recommended pattern is to have the stack that provides a resource (e.g., a VPC) output its ID and then have the consuming stack import that value using the Fn::ImportValue function. However, this creates a circular dependency risk if both stacks try to import from each other. In such cases, you can use a parameter to pass the value instead. Being able to diagnose and resolve cross-stack dependency issues during updates is a common real-world troubleshooting task.
One thing that often goes wrong is stack creation timeouts. Some resources, like large RDS databases or complex Lambda functions, take a long time to create. CloudFormation has a default timeout for resource creation, and intermediate failures during a long operation can cause the whole stack to roll back. To handle this, you can set a longer TimeoutInMinutes property in the resource definition. Also, you should always use CloudTrail to log API calls made by CloudFormation during stack operations, so you can audit who initiated a create or update and what actually happened.
Finally, professionals always execute stack updates using change sets. A change set is a preview of the changes that will be made before they are applied. It tells you which resources will be added, modified, replaced, or deleted. This is especially important when deleting a resource that might cause data loss, like an S3 bucket with versioning disabled or an RDS database without a final snapshot. By reviewing a change set, you can catch these dangerous operations before they happen.
Memory Tip
Think of a CloudFormation Stack as a 'group photo' of your AWS resources, create one shot, delete one shot, and everyone in the frame is managed together.
Covered in These Exams
Current Exam Context
Current exam versions that test this topic — use these objectives when studying.
AI-900AI-900 →Related Glossary Terms
A 2-in-1 laptop is a portable computer that can switch between a traditional laptop form and a tablet form, usually by detaching or rotating the keyboard.
The 24-pin motherboard connector is the main power cable that connects the computer's power supply unit (PSU) to the motherboard, supplying electricity to the motherboard and its components.
Two-factor authentication (2FA) is a security method that requires two different types of proof before granting access to an account or system.
A 3D printer is a device that creates physical objects by depositing layers of material based on a digital model.
5G is the fifth generation of cellular network technology, designed to deliver faster speeds, lower latency, and support for many more connected devices than previous generations.
The 8-pin CPU connector is a power cable from the power supply that delivers dedicated electricity to the processor on a computer's motherboard.
802.1Q is the networking standard that allows multiple virtual LANs (VLANs) to share a single physical network link by tagging Ethernet frames with VLAN identification information.
802.1X is a network access control standard that authenticates devices before they are allowed to connect to a wired or wireless network.
Frequently Asked Questions
Can a CloudFormation Stack contain resources from multiple AWS regions?
No, a single CloudFormation Stack is scoped to one region. All resources in a stack must be created in the same region where the stack exists. To deploy the same resources across multiple regions, you would use CloudFormation StackSets or create separate stacks in each region.
What happens if a resource creation fails during stack creation?
CloudFormation will roll back the entire stack. It will automatically delete any resources that were successfully created before the failure. The stack will end in a ROLLBACK_COMPLETE state. You can view the stack events to see the exact error message and fix the issue before retrying.
Can I update a stack without any downtime?
Yes, but it depends on the changes. If you only update properties that allow in-place updates (like modifying a security group rule), there is no downtime. If a resource must be replaced (like changing an EC2 instance type), CloudFormation will create the new resource and then delete the old one, which can cause a brief interruption. You can use features like Auto Scaling groups or rolling updates with Elastic Load Balancing to minimize or eliminate downtime during stack updates.
Is it possible to prevent a stack from being deleted by accident?
Yes, AWS CloudFormation supports termination protection at the stack level. When enabled, any attempt to delete the stack will fail unless termination protection is first disabled. This is a critical safety measure for production stacks.
How do I pass information from one stack to another stack?
Use stack outputs. In the source stack, define an output for the value you want to share (e.g., a VPC ID). Then, in the consuming stack, use the Fn::ImportValue intrinsic function to reference that output. Both stacks must be in the same region, and the consuming stack must be in the same account, or you need to use cross-account parameters or AWS Systems Manager Parameter Store for cross-account scenarios.
Do I need to pay extra for AWS CloudFormation?
No, CloudFormation itself is a free service. You only pay for the AWS resources it creates, such as EC2 instances, RDS databases, or S3 storage. There are no additional charges for using the CloudFormation service to automate the creation and management of those resources.
Can I use CloudFormation to manage resources that were created outside of CloudFormation?
Yes, but it is not straightforward. You can import existing resources into a stack using the CloudFormation resource import feature. The template must exactly match the current configuration of the resource for the import to succeed. This is useful for migrating manually created infrastructure into IaC management.
Summary
A CloudFormation Stack is the live, running collection of AWS resources that are created and managed as a single unit from a declarative template. This IaC concept is central to automating cloud infrastructure, ensuring that environments are consistent, repeatable, and easy to tear down. For IT certification candidates, understanding stacks is crucial for passing AWS exams, particularly those at the Associate and Professional levels.
The key exam takeaway is that a stack is not the template itself but the group of resources that result from it. You must remember that all resources in a stack are managed together, create, update, and delete operations apply to the entire group. The ordering of resource creation is based on dependencies, not the template order, and manual changes to stack resources cause drift, which undermines the principle of Infrastructure as Code.
In real-world practice, CloudFormation Stacks enable rapid environment provisioning, reduce human error, and provide a clear audit trail. They support advanced features like nested stacks, cross-stack references, stack policies, and change sets, all of which are important for managing complex, production-grade architectures. By mastering the stack concept, you not only prepare for certification exams but also gain a foundational skill for modern cloud operations and DevOps workflows.