Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: migration guide for presigning #2432

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions content/en/docs/migrating/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,100 @@ 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think we actually have PresignClients for every service that supports it. this is because in the past weve gotten feature requests to add a PresignClient for a specific operation, which we then fulfilled (i think this is the first task that Sean gave me to do #1888).

if this is indeed the case, maybe we should add something about filing a feature request if they dont see a PresignClient for a service they know supports it?


**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.

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
Expand Down
Loading