-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddb_create_table.go
63 lines (57 loc) · 1.43 KB
/
ddb_create_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
// https://aws.amazon.com/ko/getting-started/hands-on/design-a-database-for-a-mobile-app-with-dynamodb/4/
import (
"context"
"encoding/json"
"fmt"
"log"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
)
func main() {
const tableName = "new-table"
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
log.Fatal(err)
}
client := dynamodb.NewFromConfig(cfg)
params := &dynamodb.CreateTableInput{
TableName: aws.String(tableName),
AttributeDefinitions: []types.AttributeDefinition{
{
AttributeName: aws.String("PK"),
AttributeType: types.ScalarAttributeTypeS,
},
{
AttributeName: aws.String("SK"),
AttributeType: types.ScalarAttributeTypeS,
},
},
KeySchema: []types.KeySchemaElement{
{
AttributeName: aws.String("PK"),
KeyType: types.KeyTypeHash,
},
{
AttributeName: aws.String("SK"),
KeyType: types.KeyTypeRange,
},
},
ProvisionedThroughput: &types.ProvisionedThroughput{
ReadCapacityUnits: aws.Int64(5),
WriteCapacityUnits: aws.Int64(5),
},
}
output, err := client.CreateTable(context.TODO(), params)
// /*for debug*/
if output != nil {
jsonOutput, _ := json.MarshalIndent(output, "", "\t")
fmt.Println(string(jsonOutput))
}
if err != nil {
fmt.Println("Error!")
log.Fatal(err)
}
}