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
|
package main
import (
"context"
"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/ssm"
"github.com/aws/aws-sdk-go-v2/service/ssm/types"
"github.com/knadh/koanf/providers/parameterstore/v2"
"github.com/knadh/koanf/v2"
)
var k = koanf.New(".")
func main() {
// The configuration values are read from the environment variables.
c, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
log.Fatal(err)
}
client := ssm.NewFromConfig(c)
for k, v := range map[string]string{
"parent1": "alice",
"parent2.child1": "bob",
"parent2.child2.grandchild1": "carol",
} {
if _, err := client.PutParameter(context.TODO(), &ssm.PutParameterInput{
Name: aws.String(k),
Value: aws.String(v),
Type: types.ParameterTypeSecureString,
Overwrite: aws.Bool(true),
}); err != nil {
log.Fatal(err)
}
}
// Get a parameter.
if err := k.Load(parameterstore.ProviderWithClient(parameterstore.Config[ssm.GetParameterInput]{
Delim: ".",
Input: ssm.GetParameterInput{Name: aws.String("parent1"), WithDecryption: aws.Bool(true)},
}, client), nil); err != nil {
log.Fatalf("error loading config: %v", err)
}
fmt.Println(k.Sprint())
// Get parameters.
if err := k.Load(parameterstore.ProviderWithClient(parameterstore.Config[ssm.GetParametersInput]{
Delim: ".",
Input: ssm.GetParametersInput{Names: []string{"parent1", "parent2.child1"}, WithDecryption: aws.Bool(true)},
}, client), nil); err != nil {
log.Fatalf("error loading config: %v", err)
}
fmt.Println(k.Sprint())
// Get parameters by path.
if err := k.Load(parameterstore.ProviderWithClient(parameterstore.Config[ssm.GetParametersByPathInput]{
Delim: ".",
Input: ssm.GetParametersByPathInput{Path: aws.String("/"), WithDecryption: aws.Bool(true)},
}, client), nil); err != nil {
log.Fatalf("error loading config: %v", err)
}
fmt.Println(k.Sprint())
}
|