From a6650c01019455624fb6b0e7600a0cf78fbc6312 Mon Sep 17 00:00:00 2001 From: Luc Talatinian Date: Tue, 19 Dec 2023 16:35:17 -0500 Subject: [PATCH 1/2] docs: migration guide for presigning --- content/en/docs/migrating/_index.md | 90 +++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/content/en/docs/migrating/_index.md b/content/en/docs/migrating/_index.md index 50d4fafe798..59a8c603032 100644 --- a/content/en/docs/migrating/_index.md +++ b/content/en/docs/migrating/_index.md @@ -899,6 +899,96 @@ to wait for a {{% alias service=S3 %}} Bucket to exist, you must construct a `Bu [s3.BucketExistsWaiter]({{< apiref "service/s3#BucketExistsWaiter" >}}). The `s3.BucketExistsWaiter` provides a `Wait` method which can be used to wait for a bucket to become available. +### Presigned Requests + +The V1 SDK technically supported presigning _any_ AWS SDK operation, however, +this does not accurately represent what is actually supported at the service +level (and in reality most AWS service operations do not support presigning). + +{{% alias sdk-go %}} resolves this by exposing specific `PresignClient` +implementations in service packages with specific APIs for supported +presignable operations. + +Uses of [Presign]({{< apiref v1="aws/request#Request.Presign" >}}) and +[PresignRequest]({{< apiref v1="aws/request#Request.PresignRequest" >}}) must +be converted to use service-specific presigning clients. + +The following example shows how to migrate presigning of an S3 GetObject +request: + +```go +// V1 + +import ( + "fmt" + "time" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/s3" +) + +func main() { + sess := session.Must(session.NewSessionWithOptions(session.Options{ + SharedConfigState: session.SharedConfigEnable, + })) + + svc := s3.New(sess) + req, _ := svc.GetObjectRequest(&s3.GetObjectInput{ + Bucket: aws.String("bucket"), + Key: aws.String("key"), + }) + + // pattern 1 + url1, err := req.Presign(20 * time.Minute) + if err != nil { + panic(err) + } + fmt.Println(url1) + + // pattern 2 + url2, header, err := req.PresignRequest(20 * time.Minute) + if err != nil { + panic(err) + } + fmt.Println(url2, header) +} +``` + +```go +// V2 + +import ( + "context" + "fmt" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/service/s3" +) + +func main() { + cfg, err := config.LoadDefaultConfig(context.Background()) + if err != nil { + panic(err) + } + + svc := s3.NewPresignClient(s3.NewFromConfig(cfg)) + req, err := svc.PresignGetObject(context.Background(), &s3.GetObjectInput{ + Bucket: aws.String("bucket"), + Key: aws.String("key"), + }, func(o *s3.PresignOptions) { + o.Expires = 20 * time.Minute + }) + if err != nil { + panic(err) + } + + fmt.Println(req.Method, req.URL, req.SignedHeader) +} +``` + ## Request customization The monolithic [request.Request]({{< apiref v1="aws/request#Request" >}}) API From c3a861a256036c806d43cc777470abbe2df08b9b Mon Sep 17 00:00:00 2001 From: Luc Talatinian Date: Tue, 19 Dec 2023 17:07:55 -0500 Subject: [PATCH 2/2] add gh call to action for missing presign --- content/en/docs/migrating/_index.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/content/en/docs/migrating/_index.md b/content/en/docs/migrating/_index.md index 59a8c603032..e74022fee81 100644 --- a/content/en/docs/migrating/_index.md +++ b/content/en/docs/migrating/_index.md @@ -909,6 +909,10 @@ level (and in reality most AWS service operations do not support presigning). implementations in service packages with specific APIs for supported presignable operations. +**Note: If a service is missing presigning support for an operation that you +were successfully using in SDK v1, please let us know by +[filing an issue on GitHub](https://github.com/aws/aws-sdk-go-v2/issues).** + Uses of [Presign]({{< apiref v1="aws/request#Request.Presign" >}}) and [PresignRequest]({{< apiref v1="aws/request#Request.PresignRequest" >}}) must be converted to use service-specific presigning clients.