Sample code for adding custom header to CreateBucket request.
AWS-SDK's CreateBucket does not let you add custom headers so you have to create your own http request.
import (
"fmt"
"log"
"net/http"
"time"
"github.com/aws/aws-sdk-go/aws/credentials"
v4 "github.com/aws/aws-sdk-go/aws/signer/v4"
)
func createBucket() {
endpoint := "https://xxx.xxx.xxx/"
region := "region-1"
bucketName := "bucket-name"
// Specify accesskey secretkey or read from env with NewEnvCredentials()
cred := credentials.NewEnvCredentials()
// cred := credentials.NewStaticCredentialsFromCreds(credentials.Value{
// AccessKeyID: akey,
// SecretAccessKey: skey,
// })
signer := v4.NewSigner(cred)
httpClient := &http.Client{}
// Create a PUT request
req, err := http.NewRequest(http.MethodPut, endpoint+bucketName, nil)
if err != nil {
fmt.Print(err)
}
// Now add whatever header you want
req.Header.Add("Content-Type", "application/json")
req.Header.Add("HEADER-TO-BE-ADDED", "HEADER-TO-BE-ADDED")
// Sign it
signer.Sign(req, nil, "s3", region, time.Now())
// Send the request
res, err := httpClient.Do(req)
log.Println(res.Status)
}```