From ecd64a57df80817ab201b56e5ba4c8a1b2f01512 Mon Sep 17 00:00:00 2001 From: Aditya C S Date: Mon, 16 Sep 2019 16:42:06 +0530 Subject: [PATCH] Allow region to be read from environment variable --- aws/config.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/aws/config.go b/aws/config.go index 9747fca2..8937e749 100644 --- a/aws/config.go +++ b/aws/config.go @@ -5,6 +5,7 @@ import ( "net" "net/http" "net/url" + "os" "strings" "time" @@ -45,10 +46,14 @@ func ConfigFromURL(awsURL *url.URL) (*aws.Config, error) { } if strings.Contains(awsURL.Host, ".") { + region := os.Getenv("AWS_REGION") + if region == "" { + region = "dummy" + } if awsURL.Scheme == "https" { - return config.WithEndpoint(fmt.Sprintf("https://%s", awsURL.Host)).WithRegion("dummy"), nil + return config.WithEndpoint(fmt.Sprintf("https://%s", awsURL.Host)).WithRegion(region), nil } - return config.WithEndpoint(fmt.Sprintf("http://%s", awsURL.Host)).WithRegion("dummy"), nil + return config.WithEndpoint(fmt.Sprintf("http://%s", awsURL.Host)).WithRegion(region), nil } // Let AWS generate default endpoint based on region passed as a host in URL.