-
Notifications
You must be signed in to change notification settings - Fork 84
/
athena.go
executable file
·93 lines (79 loc) · 2.96 KB
/
athena.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package reset
import (
"log"
"github.com/aws/aws-sdk-go/service/athena"
"github.com/aws/aws-sdk-go/service/athena/athenaiface"
)
// AthenaService interface
type AthenaService interface {
ListWorkGroups(input *athena.ListWorkGroupsInput) (*athena.ListWorkGroupsOutput, error)
ListNamedQueries(input *athena.ListNamedQueriesInput) (*athena.ListNamedQueriesOutput, error)
DeleteNamedQuery(input *athena.DeleteNamedQueryInput) (*athena.DeleteNamedQueryOutput, error)
DeleteWorkGroup(input *athena.DeleteWorkGroupInput) (*athena.DeleteWorkGroupOutput, error)
}
// AthenaReset defines a concrete implementation of the above Service interface
type AthenaReset struct {
Client athenaiface.AthenaAPI
}
// ListWorkGroups implemenation
func (athenaReset AthenaReset) ListWorkGroups(input *athena.ListWorkGroupsInput) (*athena.ListWorkGroupsOutput, error) {
return athenaReset.Client.ListWorkGroups(input)
}
// ListNamedQueries implemenation
func (athenaReset AthenaReset) ListNamedQueries(input *athena.ListNamedQueriesInput) (*athena.ListNamedQueriesOutput, error) {
return athenaReset.Client.ListNamedQueries(input)
}
// DeleteWorkGroup implemenation
func (athenaReset AthenaReset) DeleteWorkGroup(input *athena.DeleteWorkGroupInput) (*athena.DeleteWorkGroupOutput, error) {
return athenaReset.Client.DeleteWorkGroup(input)
}
// DeleteNamedQuery implemenation
func (athenaReset AthenaReset) DeleteNamedQuery(input *athena.DeleteNamedQueryInput) (*athena.DeleteNamedQueryOutput, error) {
return athenaReset.Client.DeleteNamedQuery(input)
}
// DeleteAthenaResources deletes all aethna resources in the current aws session
func DeleteAthenaResources(athenaSvc AthenaService) error {
var maxResult int64 = 50
// Delete all workgroups
listWorkGroupsInput := &athena.ListWorkGroupsInput{
MaxResults: &maxResult,
}
listWorkGroupsOutput, err := athenaSvc.ListWorkGroups(listWorkGroupsInput)
if err != nil {
return err
}
for _, workGroup := range listWorkGroupsOutput.WorkGroups {
isDelete := true
log.Printf("Starting Athena workgroup list %v", workGroup)
if *workGroup.Name == "primary" {
continue
}
deleteWorkGroupInput := &athena.DeleteWorkGroupInput{
RecursiveDeleteOption: &isDelete,
WorkGroup: workGroup.Name,
}
log.Printf("Starting Athena workgroup delete %v", workGroup)
_, err := athenaSvc.DeleteWorkGroup(deleteWorkGroupInput)
if err != nil {
log.Printf("Athena workgroup delete error: %v", err)
return err
}
}
// Delete all namedqueries
listNamedQueriesInput := &athena.ListNamedQueriesInput{}
listNamedQueriesOutput, err := athenaSvc.ListNamedQueries(listNamedQueriesInput)
if err != nil {
return err
}
for _, namedQuery := range listNamedQueriesOutput.NamedQueryIds {
log.Printf("Starting Athena namedquery delete %v", *namedQuery)
deleteNamedQueryInput := &athena.DeleteNamedQueryInput{
NamedQueryId: namedQuery,
}
_, err := athenaSvc.DeleteNamedQuery(deleteNamedQueryInput)
if err != nil {
return err
}
}
return nil
}