0

I'm currently integrating my project with dynamoDB.
I need to create a friendly approach for contributors to run everything locally (docker).
The biggest issue I have is creating tables.

Possibilities I've considered:

  • run migration at the beginning of the startup of my app via C# api
  • create migration endpoint (C#)
  • create a script (AWS CLI)

Maybe something different?

1 Answers1

0

Thanks, Chris Anderson I really like the idea to run production-like setup.
I finally went with terraform because it is cloud agnostic.
For other ppl searching for similar idea here is my starting point configuration :)

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.39"
    }
  }
}

locals {
  environment = "dev"
  table_name  = "shops"
  region      = "eu-central-1"
}

provider "aws" {
  access_key                  = "mock_access_key"
  region                      = local.region
  secret_key                  = "mock_secret_key"
  skip_credentials_validation = true
  skip_metadata_api_check     = true
  skip_requesting_account_id  = true

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

resource "aws_dynamodb_table" "shops-table" {
  name           = local.table_name
  billing_mode   = "PROVISIONED"
  read_capacity  = 2
  write_capacity = 2
  hash_key       = "pk"
  range_key      = "sk"

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

  attribute {
    name = "sk"
    type = "S"
  }
  
  tags = {
    Name        = "${local.table_name}-${local.environment}"
    Environment = local.environment
  }
}