I need to get public permanent (not signed) URL of a resource using golang and official aws go sdk. In Java AWS S3 SDK there's a method called getResourceUrl() what's the equivalent in go?
This is how you get presigned URLs using the go sdk:
func GetFileLink(key string) (string, error) {
    svc := s3.New(some params)
    params := &s3.GetObjectInput{
        Bucket: aws.String(a bucket name),
        Key:    aws.String(key),
    }
    req, _ := svc.GetObjectRequest(params)
    url, err := req.Presign(15 * time.Minute) // Set link expiration time
    if err != nil {
        global.Log("[AWS GET LINK]:", params, err)
    }
    return url, err
}
If what you want is just the URL of a public access object you can build the URL yourself:
https://<region>.amazonaws.com/<bucket-name>/<key>
Where <region> is something like us-east-2. So using go it will be something like:
url := "https://%s.amazonaws.com/%s/%s"
url = fmt.Sprintf(url, "us-east-2", "my-bucket-name", "some-file.txt")
Here is a list of all the available regions for S3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With