即使存在也缺少密钥

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!

If you look at the type s3.PutObjectInput, the key field has a required:"true" tag.

The required tag is also used by the envconfig package to indicate that the environment variable is required.

You either need to supply the key from the environment, or not use the aws structs directly with the envconfig package.