Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Last active February 8, 2025 09:13
Show Gist options
  • Save ruanbekker/f5fb3dce64ae1137777df095d0bb6bd1 to your computer and use it in GitHub Desktop.
Save ruanbekker/f5fb3dce64ae1137777df095d0bb6bd1 to your computer and use it in GitHub Desktop.
Deploy DynamoDB Table with Terraform and Localstack

Install Localstack:

$ pip install localstack

Start Localstack:

$ export SERVICES=s3,lambda,dynamodb
$ export DEFAULT_REGION=eu-west-1
$ localstack start

the provider.tf file:

provider "aws" {
  region     = "eu-west-1"

  endpoints {
        dynamodb = "http://localhost:4569"
    }
}

the main.tf file:

resource "aws_dynamodb_table" "mytable" {
    name           = "mytable"
    read_capacity  = 5
    write_capacity = 5
    hash_key       = "Id"
    range_key      = "Timestamp"

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

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

Run terraform:

$ terraform init
$ terraform plan
$ terraform apply
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment