Lesson 4 of 4 ยท AWS with Terraform

Databases and serverless

Managed databases reduce operational work but still need network, backup, and access decisions. Lambda runs small event-driven workloads without managing servers. Both need explicit permissions and realistic usage assumptions.

Example

resource "aws_db_instance" "app" {
  engine         = "postgres"
  instance_class = "db.t3.micro"
  allocated_storage = 20
}

Step by step

  1. Keep databases reachable only from the workloads that need them.
  2. Set backup and retention expectations.
  3. Use serverless functions for focused event-driven tasks.
  4. Review cost assumptions for requests and storage.

Common mistakes to avoid

  • Publishing a database endpoint unnecessarily.
  • Treating Lambda as free without considering invocations and duration.