CloudFormation is a free AWS service that enables taking declarative code and creating AWS resources configured exactly as declared via templates. Using templates, you can create, update, and delete an entire stack as a single unit, or stacks across multiple AWS accounts and AWS Regions as often as you need without managing resources individually.
CloudFormation best practices & notable features:
- JSON / YAML -Templates can be defined using JSON or YAML. It’s generally best practice to use YAML to define these templates for readability and maintainability purposes.
- Change Sets - When pushing an update to a CloudFormation stack, change sets grant a preview of the changes CloudFormation is going to make before it actually makes them. This allows auditing of changes to infrastructure.
- CloudFormation StackSets - StackSets enable provisioning identical CloudFormation stacks across accounts and across regions. It helps facilitate the management of multiple environments.
- CloudFormation Custom Resources - A Lambda can be placed behind a CloudFormation custom resource to enable arbitrary code execution. Using this, a third party (non-AWS) service could be provisioned within a CloudFormation stack.
Pros of CloudFormation:
- It allows the modeling of infrastructure like a database schema or application.
- One text format (CloudFormation template YAML) is the source of truth for AWS infrastructure (avoid manual changes!).
- It enables safe, repeatable deployments, including rollback support in the event an executed change-set fails.
- It reduces the need for manual actions or custom scripts to provision infrastructure, which complicate the build and release process.