Infrastructure as code is the process of provisioning and managing your cloud resources by writing a template file that is both human readable, and machine consumable. For AWS cloud development the built-in choice for infrastructure as code is AWS CloudFormation.
Using AWS CloudFormation you can write a description of the resources that you want to create on your AWS account, and then ask AWS CloudFormation to make this description into reality. For example the following YAML template snippet describes an AWS ECS service resource to create:
Service: Type: 'AWS::ECS::Service' DependsOn: 'ServiceDiscoveryService' Properties: ServiceName: 'app' Cluster: 'production' DeploymentConfiguration: MaximumPercent: 200 MinimumHealthyPercent: 75 DesiredCount: 5 TaskDefinition: !Ref 'TaskDefinition' ServiceRegistries: - RegistryArn: !GetAtt ServiceDiscoveryService.Arn ContainerPort: 3000 ContainerName: 'myapp'
AWS CloudFormation takes this template and then assumes the responsibility of creating, updating, and deleting resources on your AWS account according to what is described in the template. If you add a new resource to the file CloudFormation will create that resource on your account. If you update a resource CloudFormation will either update or replace any existing matching resources. And if you remove a resource from the template it will be cleaned up and removed from your AWS account.
Infrastructure as code brings a lot of benefits: