CodePark/ questions / Availability, scaling, IaC & cost
START PRACTICINGPRACTICE
Backend question · Cloud & AWS › Availability, scaling, IaC & cost

Why define AWS infrastructure as code instead of clicking in the console? Compare CloudFormation, CDK and Terraform.

const queue = new sqs.Queue(this, "Jobs", {
  visibilityTimeout: Duration.minutes(5),
  deadLetterQueue: { queue: dlq, maxReceiveCount: 5 },
});
queue.grantConsumeMessages(workerTaskRole);

Infrastructure as code (IaC) means you describe your servers, queues and databases in code files instead of creating them by hand. Console clicks give you none of these benefits:

  • Reproducible environments: staging and production come from the same code.
  • Review: changes go through pull requests.
  • History: you can see who changed what.
  • Drift detection: you can find manual changes that differ from the code.
  • Fast rebuilds: you can rebuild after a disaster, or create a test environment quickly.

CloudFormation is AWS's own engine. You declare resources in YAML or JSON templates. It manages stacks (groups of resources), creation order and rollback. You do not need to manage a separate state file.

CDK (Cloud Development Kit) lets you write TypeScript that synthesizes (generates) CloudFormation templates. It gives you higher-level building blocks called constructs. For example, the snippet creates a queue with a DLQ (dead-letter queue, where failed messages go). It also grants a least-privilege consume policy in one line.

Terraform uses its own language, HCL. It works with many providers, not only AWS. It shows a plan of changes before it applies them. It tracks resources in a state file. Teams must store this file remotely and lock it, so two people cannot change it at the same time.

  • IaC gives reproducible environments, code review, history, drift detection and disaster recovery.
  • CloudFormation is native to AWS, uses stacks with rollback, and has no state file to manage.
  • CDK turns TypeScript constructs into CloudFormation and adds helpers like grant methods.
  • Terraform uses HCL, works with many providers, shows a plan and keeps a state file.
  • Terraform state needs remote storage and locking when a team shares it.