-
Notifications
You must be signed in to change notification settings - Fork 178
/
query-with-cancel.go
74 lines (59 loc) · 1.7 KB
/
query-with-cancel.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
package main
import (
"go_sample/utils"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/timestreamquery"
"context"
"flag"
"fmt"
"os"
)
func main() {
// process command line arguments
region := flag.String("region", utils.REGION, "region")
queryPtr := flag.String("query", "", "query string")
filePtr := flag.String("outputfile", "", "output results file in the current folder")
flag.Parse()
// setup the query client
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(*region))
querySvc := timestreamquery.NewFromConfig(cfg, func(o *timestreamquery.Options) {
o.Region = *region
})
if *queryPtr == "" {
fmt.Println("Invalid Input: --query must be specified to non empty")
os.Exit(-1)
}
var f *os.File
if *filePtr != "" {
var ferr error
f, ferr = os.Create(*filePtr)
utils.Check(ferr)
defer f.Close()
}
queryInput := ×treamquery.QueryInput{
QueryString: aws.String(*queryPtr),
}
fmt.Println("Submitting a query:")
fmt.Println(*queryPtr)
// submit the query
queryOutput, err := querySvc.Query(context.TODO(), queryInput)
if err != nil {
fmt.Println("Error:")
fmt.Println(err)
}
cancelQueryInput := ×treamquery.CancelQueryInput{
QueryId: aws.String(*queryOutput.QueryId),
}
fmt.Println("Submitting cancellation for the query")
fmt.Println(utils.JsonMarshalIgnoreError(cancelQueryInput))
// submit the query
cancelQueryOutput, err := querySvc.CancelQuery(context.TODO(), cancelQueryInput)
if err != nil {
fmt.Println("Error:")
fmt.Println(err)
} else {
fmt.Println("Query has been cancelled successfully")
fmt.Println(utils.JsonMarshalIgnoreError(cancelQueryOutput))
}
}