Last active
January 7, 2019 21:13
-
-
Save dmolesUC/1f50935d4e55b465de5c6f753ea2f505 to your computer and use it in GitHub Desktop.
Demonstration of AWS credentials timeout issue (https://github.com/aws/aws-sdk-go/issues/2392)
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" | |
"io/ioutil" | |
"log" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/s3" | |
"github.com/aws/aws-sdk-go/service/s3/s3manager" | |
) | |
func main() { | |
s3Config := aws.Config{ | |
Endpoint: aws.String("http://127.0.0.1:9000/"), | |
Region: aws.String("us-west-2"), | |
S3ForcePathStyle: aws.Bool(true), | |
CredentialsChainVerboseErrors: aws.Bool(true), | |
} | |
s3Opts := session.Options{ | |
Config: s3Config, | |
SharedConfigState: session.SharedConfigEnable, | |
} | |
sess, err := session.NewSessionWithOptions(s3Opts) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
outfile, err := ioutil.TempFile("", "myfile") | |
if err != nil { | |
log.Fatalln(err) | |
} | |
downloader := s3manager.NewDownloader(sess) | |
bytesDownloaded, err := downloader.Download(outfile, &s3.GetObjectInput{ | |
Bucket: aws.String("mybucket"), | |
Key: aws.String("mykey"), | |
}) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
fmt.Printf("Downloaded %d bytes to tempfile: %v\n", bytesDownloaded, outfile.Name()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment