Created
September 27, 2018 19:45
-
-
Save ervitis/d9f671c7ba37a4d5fb27d62b4d2d458c to your computer and use it in GitHub Desktop.
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 ( | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/s3" | |
"log" | |
"time" | |
) | |
// Downloads an item from an S3 Bucket | |
// | |
// Usage: | |
// go run s3_download.go | |
func main() { | |
// Initialize a session in us-west-2 that the SDK will use to load | |
// credentials from the shared credentials file ~/.aws/credentials. | |
sess, err := session.NewSession(&aws.Config{ | |
Region: aws.String("us-west-2")}, | |
) | |
// Create S3 service client | |
svc := s3.New(sess) | |
req, _ := svc.GetObjectRequest(&s3.GetObjectInput{ | |
Bucket: aws.String("myBucket"), | |
Key: aws.String("myKey"), | |
}) | |
urlStr, err := req.Presign(15 * time.Minute) | |
if err != nil { | |
log.Println("Failed to sign request", err) | |
} | |
log.Println("The URL is", urlStr) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment