add the old snippet md files
This commit is contained in:
parent
fc0dd204c7
commit
bcf8313a4b
110 changed files with 3048 additions and 0 deletions
62
old_snippets/wipe-dynamodb-via-terraform.md
Normal file
62
old_snippets/wipe-dynamodb-via-terraform.md
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
---
|
||||
title: "wipe dynamodb table via terraform"
|
||||
date: 2021-09-17T13:38:32+02:00
|
||||
draft: false
|
||||
snippet_types:
|
||||
- dynamodb
|
||||
- aws
|
||||
- terraform
|
||||
---
|
||||
|
||||
Recently I came across the problem of how to wipe a dynamodb table.
|
||||
I though there would be an ui button for this or at lease an api/sdk method
|
||||
but from what I found the only way it to individually delete the items by key. This
|
||||
method can be batched up to 10 items per call but is still very slow and incurs write
|
||||
costs.
|
||||
|
||||
Since I'm used Terraform to create the table in the first place I thought I'll just destroy it
|
||||
and remake it... Then came the problem of not wanting to destroy everything but simply remake the
|
||||
table. After some digging in Terraform docs I found a pretty clean solution.
|
||||
|
||||
|
||||
**main.tf**
|
||||
|
||||
```
|
||||
module "dynamodb_table" {
|
||||
source = "terraform-aws-modules/dynamodb-table/aws"
|
||||
|
||||
name = "poverty-line-county-gps-map"
|
||||
hash_key = "id"
|
||||
stream_enabled = false
|
||||
|
||||
attributes = [
|
||||
{
|
||||
name = "id"
|
||||
type = "S"
|
||||
}
|
||||
]
|
||||
|
||||
tags = {
|
||||
Terraform = "true"
|
||||
Project = "poverty_line"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In this case I wanted to remake "poverty-line-county-gps-map". To find out what
|
||||
exactly it is called I ran terraform state:
|
||||
|
||||
```shell
|
||||
$ terraform state list
|
||||
aws_sqs_queue.dead_letter_queue
|
||||
aws_sqs_queue.terraform_queue
|
||||
module.dynamodb_table.aws_dynamodb_table.this[0]
|
||||
```
|
||||
|
||||
from here the resource can be remake like:
|
||||
|
||||
```shell
|
||||
$ terraform apply -replace="module.dynamodb_table.aws_dynamodb_table.this[0]"
|
||||
```
|
||||
|
||||
Happy times remaking things. 👋
|
||||
Loading…
Add table
Add a link
Reference in a new issue