-
I'm working on an application where we currently add a custom header to an You can do this fairly easily in the v1 sdk with the following snippet: stsService := sts.New(sess)
req, _ := stsService.GetCallerIdentityRequest(&sts.GetCallerIdentityInput{})
// set challenge header
req.HTTPRequest.Header.Set(challengeHeaderKey, challenge)
// request json for simpler parsing
req.HTTPRequest.Header.Set("Accept", "application/json")
// sign the request, including headers
if err := req.Sign(); err != nil {
return nil, err
}
// write the signed HTTP request to a buffer
var signedRequest bytes.Buffer
if err := req.HTTPRequest.Write(&signedRequest); err != nil {
return nil, err
} Is there any nice way to do this with the v2 sdk? I'm currently looking at mucking about with the smithy middleware. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You should be able to do this by overriding the
|
Beta Was this translation helpful? Give feedback.
-
Oh it turns out you can use a custom EndpointResolverV2, or add a Serializer to the middleware stack. I need a custom endpoint resolver anyway, so doing it like this. type customResolver struct {
defaultResolver sts.EndpointResolverV2
challenge string
}
func newCustomResolver(challenge string) *customResolver {
return &customResolver{
defaultResolver: sts.NewDefaultEndpointResolverV2(),
challenge: challenge,
}
}
func (r customResolver) ResolveEndpoint(ctx context.Context, params sts.EndpointParameters) (smithyendpoints.Endpoint, error) {
endpoint, err := r.defaultResolver.ResolveEndpoint(ctx, params)
if err != nil {
return endpoint, err
}
endpoint.Headers.Add(challengeHeaderKey, r.challenge)
return endpoint, nil
} |
Beta Was this translation helpful? Give feedback.
Oh it turns out you can use a custom EndpointResolverV2, or add a Serializer to the middleware stack. I need a custom endpoint resolver anyway, so doing it like this.