Created
May 20, 2020 16:20
-
-
Save galamdring/73a5d12cc6dc630289e3acef8938dffc to your computer and use it in GitHub Desktop.
Retrieve SSM Parameter Store values in Golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/ssm" | |
"strings" | |
) | |
// GetSecrets returns the secrets stored in SSM | |
func GetSecrets(region string, stage string, keynames []*string) (*map[string]interface{}, error) { | |
sess, err := session.NewSessionWithOptions(session.Options{ | |
Config: aws.Config{Region: aws.String(region)}, | |
SharedConfigState: session.SharedConfigEnable, | |
}) | |
if err != nil { | |
return nil, err | |
} | |
ssmsvc := ssm.New(sess, aws.NewConfig().WithRegion("us-east-1")) | |
withDecryption := true | |
param, err := ssmsvc.GetParameters(&ssm.GetParametersInput{ | |
Names: keynames, | |
WithDecryption: &withDecryption, | |
}) | |
if err != nil { | |
return nil, err | |
} | |
var secretsInfo map[string]interface{} | |
for _, item := range param.Parameters { | |
secretsInfo[*item.Name] = *item.Value | |
} | |
return &secretsInfo, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment