forked from ktruckenmiller/go-aws-get-parameter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssm_get_parameter.go
More file actions
executable file
·59 lines (51 loc) · 1.45 KB
/
ssm_get_parameter.go
File metadata and controls
executable file
·59 lines (51 loc) · 1.45 KB
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
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ssm"
)
func main() {
var region = flag.String("region", "us-west-2", "AWS Region")
var path = flag.String("path", "", "parameter path")
var param_name = flag.String("name", "", "single parameter value")
flag.Parse()
// Make sure users set values
if *path == "" && *param_name == "" {
exitErrorf("Make sure you set --path or --name as arguments")
}
// Create SSM service client
svc := ssm.New(session.New(&aws.Config{Region: aws.String(*region)}))
if *path == "" {
params := &ssm.GetParameterInput{
Name: aws.String(*param_name),
WithDecryption: aws.Bool(true),
}
resp, err := svc.GetParameter(params)
if err != nil {
exitErrorf("Unable to get key %q, %v", *param_name, err)
}
fmt.Println(*resp.Parameter.Value)
} else {
params := &ssm.GetParametersByPathInput{
Path: aws.String(*path),
Recursive: aws.Bool(true),
WithDecryption: aws.Bool(true),
}
resp, err := svc.GetParametersByPath(params)
if err != nil {
exitErrorf("Unable to get key %q, %v", *path, err)
}
for _, v := range resp.Parameters {
the_key := strings.Split(*v.Name, "/")
fmt.Printf("export %s=\"%s\"\n", the_key[len(the_key)-1], *v.Value)
}
}
}
func exitErrorf(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg+"\n", args...)
os.Exit(1)
}