-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move session creation out of SSMStore constructor for reuse
- Loading branch information
Daniel Fuentes
committed
Aug 2, 2018
1 parent
7c1c368
commit d1a43b5
Showing
2 changed files
with
41 additions
and
24 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package store | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/ec2metadata" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
) | ||
|
||
const ( | ||
RegionEnvVar = "CHAMBER_AWS_REGION" | ||
) | ||
|
||
func getSession(numRetries int) (*session.Session, *string) { | ||
var region *string | ||
|
||
if regionOverride, ok := os.LookupEnv(RegionEnvVar); ok { | ||
region = aws.String(regionOverride) | ||
} | ||
retSession := session.Must(session.NewSessionWithOptions( | ||
session.Options{ | ||
Config: aws.Config{ | ||
Region: region, | ||
}, | ||
SharedConfigState: session.SharedConfigEnable, | ||
}, | ||
)) | ||
|
||
// If region is still not set, attempt to determine it via ec2 metadata API | ||
if aws.StringValue(retSession.Config.Region) == "" { | ||
session := session.New() | ||
ec2metadataSvc := ec2metadata.New(session) | ||
if regionOverride, err := ec2metadataSvc.Region(); err == nil { | ||
region = aws.String(regionOverride) | ||
} | ||
} | ||
|
||
return retSession, region | ||
} |
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