I'm using the following code to create a presigned put url:
svc := s3.New(nil)
req, _ := svc.PutObjectRequest(&s3.PutObjectInput{
Bucket: aws.String("myBucket"),
Key: aws.String("myKey"),
})
str, err := req.Presign(15 * time.Minute)
log.Println("The URL is:", str, " err:", err)
But I would like to get the configuration from a environment variable:
CONFIGURATIONS={ "Bucket": "myBucket", "Key": "myKey" }
I have just two weeks of Golang, and I have mainly a background in Node.js, so, I'm sorry if this question is very basic.
To better illustrate, I'm trying to do this... but in Go:
const CONFIGURATIONS = JSON.parse(process.env.CONFIGURATIONS)
const S3 = new AWS.S3()
S3.generatePresignedUrl('putObject', CONFIGURATIONS, callback...)
Thank you very much!
If I understand your question correctly you need to retrieve the bucket and key name from env variables. This is pretty easy to do in go. The os
package has a GetEnv
function for that.
Assuming your env variables are called AWS_BUCKET
and AWS_KEY
this is the way to get the values:
bucketName := Getenv("AWS_BUCKET")
key := Getenv("AWS_KEY")
You can check the package docs here.