Skip to content

Instantly share code, notes, and snippets.

@ervitis
Created September 27, 2018 19:45
Show Gist options
  • Save ervitis/d9f671c7ba37a4d5fb27d62b4d2d458c to your computer and use it in GitHub Desktop.
Save ervitis/d9f671c7ba37a4d5fb27d62b4d2d458c to your computer and use it in GitHub Desktop.
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