Created
February 22, 2019 21:07
-
-
Save wolviecb/cd86bcf81ef45208117928c198453ae8 to your computer and use it in GitHub Desktop.
Get AWS SSM Parameter
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" | |
"log" | |
"os" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/ssm" | |
) | |
var region = os.Getenv("AWS_REGION") | |
var env = os.Getenv("ENV") | |
func ssmCheck() string { | |
sess, err := session.NewSessionWithOptions(session.Options{ | |
Config: aws.Config{Region: aws.String(region)}, | |
SharedConfigState: session.SharedConfigEnable, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
ssmsvc := ssm.New(sess, aws.NewConfig().WithRegion(region)) | |
keyname := "/some/path/" + env + "/version" | |
withDecryption := false | |
param, err := ssmsvc.GetParameter(&ssm.GetParameterInput{ | |
Name: &keyname, | |
WithDecryption: &withDecryption, | |
}) | |
return *param.Parameter.Value | |
} | |
func main() { | |
ssmVersion := ssmCheck() | |
fmt.Printf("Version: %s\n", ssmVersion) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment