Closed
Description
Waiters let you pass per-request APIOptions
but there's no way to do the same for other client configs (e.g. region, credentials, etc.).
Extend waiter-specific options to accept general client options that inform the underlying service call (paginators already allow this since the NextPage
API accepts client options to be forwarded directly).
Using TableExistsWaiter
as an example:
type TableExistsWaiterOptions struct {
// technically redundant now - we could mark deprecated, at the very least we should
// suggest people use the generic field instead
APIOptions[]func(*middleware.Stack) error)
// Functional per-request options to be forwarded to the service operation used by this waiter.
+ ClientOptions []func(*Options)
}
workaround
You can technically wrap the *APIClient
input to accomplish this. Shown below is an example for TableExistsWaiter
.
I don't think it makes the FR any less valid though - we should make simple things easy and we already have a pattern of forwarding functional options in our own HLLs (e.g. s3 manager, the APIs there let you pass s3 client options to be forwarded).
package main
import (
"context"
"log"
"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/dynamodb"
)
// withOptions wraps a Client to embed functional options on DescribeTable invocations
type withOptions struct {
client *dynamodb.Client
options []func(*dynamodb.Options)
}
func (c *withOptions) DescribeTable(
ctx context.Context, in *dynamodb.DescribeTableInput, opts ...func(*dynamodb.Options),
) (
*dynamodb.DescribeTableOutput, error,
) {
return c.client.DescribeTable(ctx, in, append(c.options, opts...)...)
}
// convenience for variadic, could do it inline
func clientWithOptions(client *dynamodb.Client, opts ...func(*dynamodb.Options)) *withOptions {
return &withOptions{client, opts}
}
func main() {
cfg, err := config.LoadDefaultConfig(context.Background())
if err != nil {
log.Fatal(err)
}
svc := dynamodb.NewFromConfig(cfg)
w := dynamodb.NewTableExistsWaiter(clientWithOptions(svc, func(o *dynamodb.Options) {
o.Region = "us-east-99"
o.ClientLogMode = aws.LogRequest
}))
w.Wait(context.Background(), &dynamodb.DescribeTableInput{
TableName: aws.String("table"),
}, 5*time.Second)
}
Activity