-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathmain.go
78 lines (69 loc) · 2.48 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package main
import (
"context"
"flag"
"fmt"
"log"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/awsdocs/aws-doc-sdk-examples/gov2/demotools"
"github.com/awsdocs/aws-doc-sdk-examples/gov2/dynamodb/actions"
"github.com/awsdocs/aws-doc-sdk-examples/gov2/dynamodb/scenarios"
)
// main loads default AWS credentials and configuration from the ~/.aws folder and runs
// a scenario specified by the `-scenario` flag.
//
// `-scenario` can be one of the following:
//
// - `movieTable` - Runs the interactive movie table scenario that shows you how to use
// Amazon DynamoDB API commands to work with DynamoDB tables and items.
// - `partiQLSingle` - Runs a scenario that shows you how to use PartiQL statements
// to work with DynamoDB tables and items.
// - `partiQLBatch` - Runs a scenario that shows you how to use batches of PartiQL
// statements to work with DynamoDB tables and items.
func main() {
scenarioMap := map[string]func(ctx context.Context, sdkConfig aws.Config){
"movieTable": runMovieScenario,
"partiQLSingle": runPartiQLSingleScenario,
"partiQLBatch": runPartiQLBatchScenario,
}
choices := make([]string, len(scenarioMap))
choiceIndex := 0
for choice := range scenarioMap {
choices[choiceIndex] = choice
choiceIndex++
}
scenario := flag.String(
"scenario", "",
fmt.Sprintf("The scenario to run. Must be one of %v.", choices))
flag.Parse()
if runScenario, ok := scenarioMap[*scenario]; !ok {
fmt.Printf("'%v' is not a valid scenario.\n", *scenario)
flag.Usage()
} else {
ctx := context.Background()
sdkConfig, err := config.LoadDefaultConfig(ctx)
if err != nil {
log.Fatalf("unable to load SDK config, %v", err)
}
log.SetFlags(0)
runScenario(ctx, sdkConfig)
}
}
func runMovieScenario(ctx context.Context, sdkConfig aws.Config) {
scenarios.RunMovieScenario(
ctx,
sdkConfig,
demotools.NewQuestioner(),
"doc-example-movie-table",
actions.MovieSampler{URL: "https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/samples/moviedata.zip"},
)
}
func runPartiQLSingleScenario(ctx context.Context, sdkConfig aws.Config) {
scenarios.RunPartiQLSingleScenario(ctx, sdkConfig, "doc-example-partiql-single-table")
}
func runPartiQLBatchScenario(ctx context.Context, sdkConfig aws.Config) {
scenarios.RunPartiQLBatchScenario(ctx, sdkConfig, "doc-example-partiql-batch-table")
}