Skip to content

Instantly share code, notes, and snippets.

@jhnlsn
Created March 19, 2019 17:39
Show Gist options
  • Save jhnlsn/4139400c7cfc62050c28fc0a74b2c986 to your computer and use it in GitHub Desktop.
Save jhnlsn/4139400c7cfc62050c28fc0a74b2c986 to your computer and use it in GitHub Desktop.
Random region selection
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