Skip to content

Instantly share code, notes, and snippets.

@galamdring
Created May 20, 2020 16:20
Show Gist options
  • Save galamdring/73a5d12cc6dc630289e3acef8938dffc to your computer and use it in GitHub Desktop.
Save galamdring/73a5d12cc6dc630289e3acef8938dffc to your computer and use it in GitHub Desktop.
Retrieve SSM Parameter Store values in Golang
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