The method of providing and controlling your cloud resources using a template file that is both machine- and human-readable is known as “infrastructure as code.” AWS CloudFormation is the pre-built option for infrastructure as code in AWS cloud development.
You may describe the resources you wish to build on your AWS account using AWS CloudFormation, and then ask AWS CloudFormation to turn this description into reality. As an illustration, the following YAML template fragment illustrates how to construct an AWS ECS service resource:
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’
This template is used by AWS CloudFormation, which is then in charge of establishing, updating, and removing the resources on your AWS account in accordance with its specifications. CloudFormation will generate a new resource on your account if you add a new resource to the file. Any matching resources that already exist will be updated or replaced if you change a resource using CloudFormation. Additionally, if you remove a resource from the template, your AWS account will be cleaned up and the resource will be deleted.
Infrastructure as code benefits
The advantages of infrastructure as code are numerous:
Visibility: A template for infrastructure as code acts as a very clear guide to the resources that are on your account and their settings. To verify the parameters, you don’t need to go to the online console.
Stability: Things might become unstable if you unintentionally alter the wrong option or delete the incorrect resource in the web interface. This problem is solved in part by infrastructure as code, especially when it is integrated with version control software like Git.
Scalability: When you create infrastructure as code, you can reuse it repeatedly. This makes it much simpler to horizontally grow because one well-written template may serve as the foundation for several services, in numerous locations all over the world.
Security: Infrastructure as code once more provides you with a uniform framework for how to deploy your architecture.
You may reuse an architecture that has been effectively protected repeatedly and be sure that every released version is using the same settings.
Transactional: CloudFormation starts resources on your AWS account, generates them, and then waits for them to stabilise. If there is a problem, it may smoothly roll the infrastructure back to a previously known good state. It confirms that provisioning was successful.