AWS CloudFormation
AWS CloudFormation is an AWS Infrastructure as Code (IaC) platform that orchestrates the creation and updating of AWS service resources.
CloudFormation is based on the concept of "Stacks", which define a collection of infrastructure that can be managed together. CloudFormation Stacks are defined as CloudFormation Templates, written in YAML or JSON text files. To create stacks, the AWS command line (update-stack
) or AWS Web console can be used to upload configuration files. These configuration files are used to create infrastructure by the CloudFormation service.
Advantages
- CloudFormation is a mature service, first launched in 2011.
- AWS uses CloudFormation as a foundational service for other products, including Serverless Application Model (SAM), and CDK, which both leverage it as their underlying technology.
- Many example templates are available, including templates from AWS.
- Teams that use products that leverage CloudFormation like SAM, Serverless Framework or CDK will benefit from an understanding of CloudFormation, even if they don't use it directly.
Disadvantages
- CloudFormation is relatively verbose, a lot of it can be required to deliver a solution in contrast to CDK.
- Remote execution can make CloudFormation problems harder to debug.
- CloudFormation's drift detection is weak compared to Terraform. For example, if resources are deleted or changed manually using the AWS console, CloudFormation will not recreate or update resources automatically.
- CloudFormation execution can be slower to start and complete than tools that use the AWS APIs directly, such as Terraform. CloudFormation execution is managed by AWS — it can sometimes take a few minutes for a process to start.
- Fewer manual state management options can make "wedged" stacks harder to unwedge.
- CloudFormation template syntax constructs are less familiar to many programmers than Terraform's HashiCorp Configuration Language (HCL).
- IDE autocomplete and other features are relatively under-developed compared to CDK and Terraform.
- The YAML format commonly used in CloudFormation is prone to indentation errors which are difficult to spot compared to alternatives such as HCL and CDK.
Compared to CDK
- CDK provides higher-level constructs that make it easier to create reusable components and reduce the amount of configuration required to deliver common functionality.
- CDK is written using a standard programming language such as TypeScript or Go. This allows the language's package ecosystem such as npm or Go modules to be used to share reusable functionality.
Compared to Terraform
- Terraform's HCL is significantly more powerful and elegant than CloudFormation's YAML (or JSON) templates.
- CloudFormation is limited to operating on AWS resources, whereas Terraform has integrations with a wide variety of providers.
- State management is done by CloudFormation
- This means you don't have to configure and manage state separately.
- This also means you cannot configure and manage state when using CloudFormation. Terraform allows the editing of state, which can sometimes be useful when your infrastructure has gotten stuck in an undesirable configuration.
- There is now a way to import existing resources into CloudFormation stacks.