Skip to content

Commit

Permalink
Merge pull request #166 from adityacs/master
Browse files Browse the repository at this point in the history
Allow region to be read from environment variable
  • Loading branch information
bboreham authored Sep 17, 2019
2 parents afb9996 + ecd64a5 commit a2b2a63
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 a2b2a63

Please sign in to comment.