Skip to content

Commit

Permalink
Allow region to be read from environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
adityacs committed Sep 17, 2019
1 parent afb9996 commit ecd64a5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"net/http"
"net/url"
"os"
"strings"
"time"

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ecd64a5

Please sign in to comment.