AWS CloudFormation
Cloud service · AWS · Updated

AWS CloudFormation

In short

AWS CloudFormation is a service that enables users to model, provision, and manage AWS and third-party application resources in a safe, repeatable, and efficient manner using templates.

Cloud Services Hub →

8 key features of AWS CloudFormation

AWS CloudFormation provides an automated, efficient, and controlled manner for provisioning and managing AWS infrastructure through Infrastructure as Code, enabling the use of JSON or YAML templates for infrastructure modeling, integrated deployment capabilities, and custom resource support.

01
Infrastructure as Code

AWS CloudFormation allows users to model their entire infrastructure and application resources with either JSON or YAML templates. This approach enables version control of infrastructure in the same way as application source code, streamlining the deployment and management of AWS resources.

02
Automated Deployment

CloudFormation automates the provisioning and updating of your infrastructure in a safe, controlled manner, with rollback capabilities. This removes the need for manual operations or custom scripts, making the infrastructure management process both efficient and repeatable.

03
Declarative Programming

With AWS CloudFormation, you declare all your resources and dependencies in a template file, which the service then takes as an input to create and configure all the declared resources automatically, eliminating the need for manual provisioning.

04
Custom Resources

AWS CloudFormation offers the flexibility to create custom resources when existing resources or resource properties cannot fulfill specific requirements. This is achieved by integrating AWS Lambda with CloudFormation, providing a powerful way to extend CloudFormation’s capabilities.

05
Safe and Controlled Updates

CloudFormation provides features like change sets, which show the effects of proposed changes to your infrastructure before implementation. This allows teams to review changes in a controlled environment, minimizing the potential impact on running services or applications.

06
Integrated with AWS Services

CloudFormation is deeply integrated with AWS services, including Amazon EC2, Amazon S3, Amazon RDS, and others, allowing for comprehensive management of a wide range of AWS resources through a single tool.

07
Resource Dependency Management

CloudFormation automatically handles the sequencing of resource provisioning and takes care of dependencies between resources, ensuring that your infrastructure is deployed in an orderly and predictable manner.

08
StackSets

CloudFormation StackSets deploy resources across multiple AWS accounts and AWS Regions.

Where AWS CloudFormation is used

AWS CloudFormation enables infrastructure as code, automated deployments, environment cloning for consistency, custom resource templating for tailored setups, and integrates with AWS configuration management for simplified maintenance and compliance.

  1. 01
    Infrastructure as Code

    AWS CloudFormation allows users to model and provision all their cloud infrastructure resources by using code. This makes it easier to create and manage a collection of related AWS resources, updating and replicating them in an orderly and predictable fashion.

  2. 02
    Automated Deployment

    By using AWS CloudFormation, teams can automate the deployment of AWS resources, ensuring that the infrastructure deployment is repeatable, scalable, and consistent. This reduces manual errors and increases efficiency in deploying applications across various environments.

  3. 03
    Environment Cloning and Consistency

    AWS CloudFormation enables organizations to clone whole cloud environments in a few steps, ensuring consistency across multiple environments. This capability supports disaster recovery strategies, efficient testing of new features, and rapid scaling of operations.

  4. 04
    Custom Resources and Templating

    The service provides a flexible templating language for defining custom AWS and third-party resources, allowing for the creation of specialized environment configurations as needed. This flexibility in defining custom resources makes CloudFormation a powerful tool for building complex, scalable, and tailored infrastructure setups.

  5. 05
    Integrated Configuration Management

    CloudFormation seamlessly integrates with other AWS services for configuration management, such as AWS Config and AWS Systems Manager. This integration allows for the centralized management of resource configurations and compliance, simplifying the maintenance of secure and efficient cloud environments.

How AWS CloudFormation is priced

AWS CloudFormation's pricing models include a free tier for template deployments within service limits and a pay-as-you-go model for AWS resources provisioned using CloudFormation, with no extra charges for the CloudFormation service.

AWS CloudFormation Free Tier

The free tier includes 1,000 handler operations per month per account, shared between Hook and third-party resource provider operations.

Pay-as-you-go Pricing

There is no additional CloudFormation charge for resource providers in the AWS::* and Alexa::* namespaces. Resources provisioned through these providers are billed just as if they had been created manually, with no minimum fees or required upfront commitments.

Registry Extension Handler Operations

Third-party resource providers outside AWS::* and Alexa::*, and custom Hooks outside AWS::*, incur charges of $0.0009 per billable handler operation. Handler execution beyond the first 30 seconds per operation costs $0.00008 per additional second. Managed Hooks in the AWS::* namespace have no additional CloudFormation Hooks charge.

Data Transfer

Data transfer is billed at standard AWS data transfer rates.

Services AWS CloudFormation works with

Amazon EC2Amazon EC2

Provides resizable compute capacity in the cloud. CloudFormation can launch and manage instances, volumes, and networking configurations.

Amazon S3Amazon S3

Object storage built to store and retrieve any amount of data. CloudFormation uses S3 buckets to store templates and can manage bucket policies, configurations, and events.

Amazon RDSAmazon RDS

Managed relational database service. CloudFormation can create, modify, and delete database instances, clusters, and subnet groups.

Amazon VPCAmazon VPC

Virtual Private Cloud to provision logically isolated sections of AWS. CloudFormation can manage VPCs, subnets, route tables, gateways, and security groups.

Amazon CloudWatchAmazon CloudWatch

Monitoring and observability service. CloudFormation can create alarms, log groups, and log streams, and configure metric-based actions.

Amazon API GatewayAmazon API Gateway

CloudFormation provisions API Gateway REST, HTTP, and WebSocket APIs, including routes, integrations, authorizers, deployments, and stages. Templates can connect an API to its Lambda functions and configure the required permissions.

Amazon AppFlowAmazon AppFlow

CloudFormation creates AppFlow flows and connector profiles, defining data sources, destinations, field mappings, and flow triggers in templates.

Amazon AthenaAmazon Athena

CloudFormation provisions Athena workgroups, data catalogs, named queries, and prepared statements. Workgroup settings can enforce query-result locations and query usage controls.

Amazon AuroraAmazon Aurora

CloudFormation provisions Aurora DB clusters, database instances, parameter groups, and subnet groups, managing their dependencies within a stack.

Amazon Aurora ServerlessAmazon Aurora Serverless

CloudFormation configures Aurora Serverless databases through RDS cluster and instance resources. Templates can specify Serverless v2 capacity ranges and serverless database instance classes.

What is AWS CloudFormation

3 min read

Amazon Web Services (AWS) CloudFormation is a powerful tool designed to give developers and IT professionals an easy way to create and manage a collection of related AWS resources. 

At its core, CloudFormation provides a user-friendly way to automate the deployment and management of infrastructure and applications within the cloud, saving time and reducing the potential for human error. By treating infrastructure as code, CloudFormation enables users to model their entire infrastructure in text files or templates, which can be version-controlled, reused, and shared among team members. 

CloudFormation templates are written in either JSON or YAML format, making them both human-readable and machine-readable. These templates describe all the AWS resources needed for a project, including their properties and relationships to one another. For instance, a template might define a network stack that includes an Amazon VPC, subnets, a security group, and an EC2 instance. Once a template is created, CloudFormation automates the provisioning and updating of the specified resources in an orderly and predictable fashion. This automation extends to managing dependencies between resources, ensuring that they are created, updated, or deleted in the correct sequence. 

CloudFormation and CDK also offer express mode, which completes stack operations when resource configuration is confirmed as applied rather than waiting for extended stabilization checks such as traffic readiness, region propagation, and resource cleanup.

One of the key benefits of using AWS CloudFormation is its ability to manage the entire lifecycle of resources. With CloudFormation, users can easily update their infrastructure in a controlled and predictable way. CloudFormation offers drift-aware change sets that compare an IaC template with the actual state of infrastructure and can bring drifted resources in line with their template definitions. This approach minimizes disruptions to running applications and services. CloudFormation also supports the concept of stacks, which are collections of AWS resources that are managed as a single unit. This means that all the resources defined in a stack are treated together, allowing users to easily replicate their infrastructure for different environments such as development, testing, and production. 

If an error occurs during deployment of a change set, CloudFormation automatically rolls back to the last known working state.

Furthermore, CloudFormation provides detailed status reports, which help users track the progress of operations and troubleshoot any issues that arise during the deployment or management of their resources. Another significant advantage of using CloudFormation is its integration with other AWS services and third-party tools. This integration facilitates the automation of complex deployments that involve multiple interdependent services and applications. 

CloudFormation registry extensions use CREATE, UPDATE, DELETE, READ, or LIST handler operations for resource types, and CREATE, UPDATE, or DELETE handler operations for Hook types.

In addition, CloudFormation is backed by the vast ecosystem of AWS, providing users with a comprehensive set of tools and services to manage their infrastructure efficiently. In summary, AWS CloudFormation is an indispensable tool for individuals and organizations looking to automate the deployment and management of their infrastructure on AWS. Its approach to infrastructure as code, combined with powerful templating, lifecycle management, and integration capabilities, makes CloudFormation an essential component of modern cloud computing practices. By leveraging CloudFormation, users can achieve greater efficiency, reliability, and scalability in their cloud-based applications and services.

Concepts related to AWS CloudFormation

AWS CloudFormation exam questions

Real practice exam questions on AWS CloudFormation, with the correct answer and its explanation. Answer them with every option in the exam simulator.

CLF-C02

A company maintains separate resource configuration files for its development and production environments. Both environments require the same network and security design, but production needs larger compute and database resources. Engineers spend time applying each design change to both files, and the files sometimes become inconsistent. Which approach would reduce this maintenance effort while preserving the required capacity differences?

Show answerCORRECT ANSWER

Maintain one AWS CloudFormation template and supply environment-specific parameters for compute and database sizes during deployment.

A parameterized template provides one reusable infrastructure design while allowing each environment to use appropriate resource sizes. This reduces duplicate maintenance and the risk of inconsistent changes.

MLA-C02

A company separates its ML approval application and compute provisioning platform into two AWS accounts. The approval application publishes custom events to an Amazon EventBridge custom event bus in the application account. Each event includes an approval status, an environment, and a workload ID.

The architecture requires these events to be forwarded to a custom event bus in the platform account so that multiple independent consumers can use them. Only events with approvalStatus equal to APPROVED and environment equal to production must start an existing AWS Step Functions workflow that provisions GPU resources through AWS CloudFormation. Both accounts are in the same AWS Region, and no cross-account permissions are currently configured.

Which solution meets these requirements?

Show answerCORRECT ANSWER

Forward the application events to the platform custom event bus by using a rule with an IAM role that allows events:PutEvents on that bus. Add a resource policy to the platform bus allowing the application account to send events. On the platform bus, create a rule that matches the required approval status and environment and targets the workflow by using a role that allows states:StartExecution.

Cross-account forwarding requires permission to send events and authorization on the receiving event bus. A rule on the receiving custom bus can filter the event detail fields and start the local workflow by using a target execution role with states:StartExecution permission.

SAP-C03

A company uses an AWS CloudFormation StackSet with self-managed permissions to deploy a security baseline from a tooling account in us-east-1 to 30 application accounts. Deployments to us-east-1 and eu-west-1 succeed. The company must extend the same StackSet to ap-east-1, a Region that is disabled by default.

The company has enabled ap-east-1 in all participating accounts and verified that account activation and IAM propagation are complete. The StackSet administration role trusts only cloudformation.amazonaws.com and permits sts:AssumeRole on the designated execution roles. Each target execution role trusts the administration role and has all permissions required by the template. The pipeline has the required CloudFormation and iam:PassRole permissions. No SCPs, permissions boundaries, or explicit denies restrict the deployment.

The company must retain self-managed permissions and continue deploying to the existing Regions. Which change is required before deploying stack instances to ap-east-1?

Show answerCORRECT ANSWER

Add cloudformation.ap-east-1.amazonaws.com to the administration role's trust policy alongside cloudformation.amazonaws.com, allowing sts:AssumeRole.

Self-managed StackSet deployments into a Region that is disabled by default require the administration role to trust that Region's regional CloudFormation service principal. Adding cloudformation.ap-east-1.amazonaws.com enables the required assumption while retaining the existing principal for deployments to the other Regions.

Practice AWS CloudFormation in a full exam

Questions on AWS CloudFormation in each practice exam, with every answer option and an explanation for each:

Start a free practice exam

Learn AWS CloudFormation in lessons

28 short lessons on AWS CloudFormation in 9 certification courses.

and 22 more lessons

Open the lessons

AWS architecture icons are the property of Amazon Web Services. BlowStack is not affiliated with or endorsed by AWS.