IaC Cost Patterns

A collection of patterns and antipatterns for managing cost in IaC files.

Antipattern: AWS - Expensive DynamoDB

AWS DynamoDB tables often use features that carry cost but are not required, especially for infrequently accessed tables.

Context

DynamoDB tables might use provisioned billing mode, have high (>1) read/write capacity, or use global secondary indices. These features carry additional cost and are not always required, especially for infrequently accessed tables.

Solution

Switching to pay-per-request billing mode, reducing provisioned read/write capacity, and removing global secondary indices are ways to cost-optimize DynamoDB tables.

Example

Set billing mode to pay-per-request:

resource "aws_dynamodb_table" "example_table" {
  name         = "HighScores"
  billing_mode = "PAY_PER_REQUEST"

  attribute {
    name = "UserID"
    type = "S"
  }

  attribute {
    name = "Score"
    type = "N"
  }
}

References

Occurrences

Terraform

AWS CloudFormation