Created
March 19, 2019 17:39
-
-
Save jhnlsn/4139400c7cfc62050c28fc0a74b2c986 to your computer and use it in GitHub Desktop.
Random region selection
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
package main | |
import ( | |
"fmt" | |
"github.com/aws/aws-sdk-go/aws/endpoints" | |
) | |
func main() { | |
for i := 0; i < 10; i++ { | |
region := getAnyRegionForAwsPartition("aws") | |
fmt.Println("Region Selection", region) | |
} | |
} | |
func getAnyRegionForAwsPartition(partitionId string) *endpoints.Region { | |
resolver := endpoints.DefaultResolver() | |
partitions := resolver.(endpoints.EnumPartitions).Partitions() | |
for _, p := range partitions { | |
if p.ID() == partitionId { | |
for _, id := range p.Regions() { | |
return &id | |
} | |
} | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment