Skip to content

Instantly share code, notes, and snippets.

@alexrios
Created November 27, 2020 18:17
Show Gist options
  • Save alexrios/a8df3ade1f2e295e0ffcb088bd198717 to your computer and use it in GitHub Desktop.
Save alexrios/a8df3ade1f2e295e0ffcb088bd198717 to your computer and use it in GitHub Desktop.
Creating pre sign URL AWS S3
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