I'm using the following code to create a presigned url:
package main
import (
"fmt"
"log"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/kelseyhightower/envconfig"
)
func main() {
configuration := s3.PutObjectInput{ Key: aws.String("default_key") }
// Add Bucket to configuration from environment variable
// e.g:
// CONFIGURATION_BUCKET -> configuration.Bucket
err := envconfig.Process("configuration", &configuration)
if err != nil {
log.Fatal(err.Error())
}
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
svc := s3.New(sess)
req, _ := svc.PutObjectRequest(&configuration)
url, err := req.Presign(15 * time.Minute)
if err != nil {
log.Fatal(err.Error())
}
fmt.Println("Url is", url)
}
The key is always the same, but the bucket can change depending on the environment that I'm.
When I print with fmt.Println
the Bucket and Key exists:
fmt.Println(configuration.Bucket, configuration.Key) // returns address
But the following error happens: required key CONFIGURATION_KEY missing value
Thank you!