-
Notifications
You must be signed in to change notification settings - Fork 5
/
example_aws-dynamodb_delete-table.go
42 lines (37 loc) · 1.43 KB
/
example_aws-dynamodb_delete-table.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"github.com/btnguyen2k/prom"
"math/rand"
"time"
)
func awsDynamodbDeleteIndexAndWait(adc *prom.AwsDynamodbConnect, table, index string) {
err := adc.DeleteGlobalSecondaryIndex(nil, table, index)
fmt.Printf(" Drop GSI [%s] on table [%s]: %e\n", table, index, err)
time.Sleep(1 * time.Second)
for status, err := adc.GetGlobalSecondaryIndexStatus(nil, table, index); status != "" && err == nil; {
fmt.Printf(" GSI [%s] on table [%s] status: %v - %e\n", table, index, status, err)
time.Sleep(1 * time.Second)
status, err = adc.GetGlobalSecondaryIndexStatus(nil, table, index)
}
}
func awsDynamodbDeleteTableAndWait(adc *prom.AwsDynamodbConnect, table string) {
result, err := adc.DeleteTable(nil, table)
fmt.Printf(" Drop table [%s]: %v - %e\n", table, result, err)
time.Sleep(1 * time.Second)
for status, err := adc.GetTableStatus(nil, table); status != "" && err == nil; {
fmt.Printf(" Table [%s] status: %v - %e\n", table, status, err)
time.Sleep(1 * time.Second)
status, err = adc.GetTableStatus(nil, table)
}
}
func main() {
rand.Seed(time.Now().UnixNano())
adc := createAwsDynamodbConnect("ap-southeast-1")
defer adc.Close()
fmt.Println("-== Delete Table and GSI ==-")
awsDynamodbDeleteIndexAndWait(adc, "test1", awsDynamodbIndexName)
awsDynamodbDeleteTableAndWait(adc, "test1")
awsDynamodbDeleteIndexAndWait(adc, "test2", awsDynamodbIndexName)
awsDynamodbDeleteTableAndWait(adc, "test2")
}