From 7c2d43542072c46884d0be2cae5629f151931e7c Mon Sep 17 00:00:00 2001 From: Daniel Fuentes Date: Thu, 15 Jun 2017 16:39:36 -0700 Subject: [PATCH 1/2] try to determine region automatically if not set: - Will attempt to use the ec2 metadata API to look up current region if AWS_REGION environment variable is not set --- store/ssmstore.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/store/ssmstore.go b/store/ssmstore.go index e453eca4..4f8b436f 100644 --- a/store/ssmstore.go +++ b/store/ssmstore.go @@ -2,10 +2,12 @@ package store import ( "fmt" + "os" "regexp" "strconv" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/ec2metadata" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ssm" "github.com/aws/aws-sdk-go/service/ssm/ssmiface" @@ -27,8 +29,18 @@ type SSMStore struct { // NewSSMStore creates a new SSMStore func NewSSMStore() *SSMStore { - session := session.New() - svc := ssm.New(session) + region, ok := os.LookupEnv("AWS_REGION") + if !ok { + // If region is not set, attempt to determine it via ec2 metadata API + session := session.New() + ec2metadataSvc := ec2metadata.New(session) + region, _ = ec2metadataSvc.Region() + } + + ssmSession := session.Must(session.NewSession(&aws.Config{ + Region: aws.String(region), + })) + svc := ssm.New(ssmSession) return &SSMStore{ svc: svc, } From 8ab8caf6a1229a6e673e18a75fc4d04f994b1486 Mon Sep 17 00:00:00 2001 From: Daniel Fuentes Date: Thu, 15 Jun 2017 16:52:07 -0700 Subject: [PATCH 2/2] remove unused flag: - This flag is leftover from the cobra cli code gen --- cmd/root.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index a6486520..56d64d47 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -41,7 +41,6 @@ func Execute() { } func init() { - RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } func validateService(service string) error {