Skip to content

Instantly share code, notes, and snippets.

@jeffotoni
Created June 14, 2021 14:58
Show Gist options
  • Save jeffotoni/b7d1181f2bb792c5083f7401935b2bab to your computer and use it in GitHub Desktop.
Save jeffotoni/b7d1181f2bb792c5083f7401935b2bab 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-east-1")},
)
// Create S3 service client
svc := s3.New(sess)
req, _ := svc.GetObjectRequest(&s3.GetObjectInput{
Bucket: aws.String("<bucket-here>"),
Key: aws.String("diretorio1/namefile-uuid"),
})
urlStr, err := req.Presign(30 * 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