You are viewing the preview version of this book
Click here for the full version.

Infrastructure-as-code

Reproducibility is a very desirable feature for any non-trivial application. It means that the same application can be deployed to multiple places and it is reasonably guaranteed that all instances behave the same. It is the foundation for providing developer environments where each developer can spin up their copy of the app in their own environment while still be confident that it works the same as in production.

Besides development, QA is also improved with reproducibility. A test or staging environment can provide a reliable way to test changes before they go live in the production environment. Deploying to staging before production gives in-house testers a chance to evaluate new features and root out regressions before changes reach the clients.

The gold standard of developing cloud-based applications is to have the whole application with all its required infrastructure described in files that are version-controlled and every part of the deployment automated. Clicking around in the AWS console is a good way to discover what is possible in AWS but it's not a good way to produce reliable software.

In this chapter, we'll look into the two major tools for Infrastructure-as-Code in AWS: Terraform and the CDK. Terraform is a 3rd-party tool with a lot of community support, while the CDK is provided by AWS and builds on top of CloudFormation.

Both tools work similarly: the code describes the infrastructure with all the resources and configurations. Then during deployment, they call AWS APIs to match the cloud environment to that desired state. This is the declarative approach: define what you need and the tool figures out what to change to match reality to that.

There is more, but you've reached the end of this preview
Read this and all other chapters in full and get lifetime access to:
  • all future updates
  • full web-based access
  • PDF and Epub versions