GolangでPreSignedUrlを発行するコードを書いたので残しておきます。
package main
import (
"context"
"fmt"
"time"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
// S3の接続情報
accessKey := os.Getenv("AWS_ACCSESS_KEY")
secretKey := os.Getenv("AWS_SECRET_KEY")
region := aws.String(os.Getenv("CUEE_DB_REGION"))
creds := credentials.NewStaticCredentials(accsessKey, secretKey, "")
session := session.Must(session.NewSession(&aws.Config{
Credentials: creds,
Region: region,
}))
svc := s3.New(session)
c, _ := svc.PutObjectRequest(&s3.PutObjectInput{
Bucket: aws.String("バケット名"),
Key: aws.String("/diectory/filename"),
})
url, err := c.Presign(15 * time.Minute)
if err != nil {
fmt.Println("error presigning request", err)
return nil, err
}
fmt.Println(url)
}
ここで有効期限を設定できます
url, err := c.Presign(15 * time.Minute)
公式
https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/s3-example-presigned-urls.html
Bodyにファイルを含め、発行されたURLにアクセスすればアップロードできます