Last active
May 23, 2018 13:52
-
-
Save ncdc/db4da12871aecb067b23de17e192260d to your computer and use it in GitHub Desktop.
Time how long it takes to determine an s3 bucket's region
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
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. | |
[[projects]] | |
name = "github.com/aws/aws-sdk-go" | |
packages = [ | |
"aws", | |
"aws/awserr", | |
"aws/awsutil", | |
"aws/client", | |
"aws/client/metadata", | |
"aws/corehandlers", | |
"aws/credentials", | |
"aws/credentials/ec2rolecreds", | |
"aws/credentials/endpointcreds", | |
"aws/credentials/stscreds", | |
"aws/defaults", | |
"aws/ec2metadata", | |
"aws/endpoints", | |
"aws/request", | |
"aws/session", | |
"aws/signer/v4", | |
"internal/sdkio", | |
"internal/sdkrand", | |
"internal/shareddefaults", | |
"private/protocol", | |
"private/protocol/query", | |
"private/protocol/query/queryutil", | |
"private/protocol/rest", | |
"private/protocol/restxml", | |
"private/protocol/xml/xmlutil", | |
"service/s3", | |
"service/s3/s3iface", | |
"service/s3/s3manager", | |
"service/sts" | |
] | |
revision = "fad131ddc707880428615dc8bc1587b55fb46d74" | |
version = "v1.13.54" | |
[[projects]] | |
name = "github.com/go-ini/ini" | |
packages = ["."] | |
revision = "6529cf7c58879c08d927016dde4477f18a0634cb" | |
version = "v1.36.0" | |
[[projects]] | |
name = "github.com/jmespath/go-jmespath" | |
packages = ["."] | |
revision = "0b12d6b5" | |
[solve-meta] | |
analyzer-name = "dep" | |
analyzer-version = 1 | |
inputs-digest = "2d724165f4ce7af0fcc09cae7b26a24ddfaa4a65066702b9e7b1b8930c9ab6fc" | |
solver-name = "gps-cdcl" | |
solver-version = 1 |
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
# Gopkg.toml example | |
# | |
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | |
# for detailed Gopkg.toml documentation. | |
# | |
# required = ["github.com/user/thing/cmd/thing"] | |
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | |
# | |
# [[constraint]] | |
# name = "github.com/user/project" | |
# version = "1.0.0" | |
# | |
# [[constraint]] | |
# name = "github.com/user/project2" | |
# branch = "dev" | |
# source = "github.com/myfork/project2" | |
# | |
# [[override]] | |
# name = "github.com/x/y" | |
# version = "2.4.0" | |
# | |
# [prune] | |
# non-go = false | |
# go-tests = true | |
# unused-packages = true | |
[[constraint]] | |
name = "github.com/aws/aws-sdk-go" | |
version = "1.13.54" | |
[prune] | |
go-tests = true | |
unused-packages = true |
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 ( | |
"context" | |
"log" | |
"os" | |
"time" | |
"github.com/aws/aws-sdk-go/aws/endpoints" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/s3/s3manager" | |
) | |
func main() { | |
if len(os.Args) != 2 { | |
log.Fatalf("usage: %s BUCKET\n", os.Args[0]) | |
} | |
s, err := session.NewSession() | |
if err != nil { | |
log.Fatalf("error creating aws session/cleint: %v\n", err) | |
} | |
for _, partition := range endpoints.DefaultPartitions() { | |
log.Println("Partition:", partition.ID()) | |
for regionHint := range partition.Regions() { | |
log.Println("RegionHint:", regionHint) | |
now := time.Now() | |
region, err := s3manager.GetBucketRegion(context.Background(), s, os.Args[1], regionHint) | |
end := time.Now() | |
if err != nil { | |
log.Fatalf("error getting bucket region: %v\n", err) | |
} | |
if region != "" { | |
d := end.Sub(now) | |
log.Printf("Region: %q, time: %v\n", region, d) | |
return | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment