AWS SDK for Go (PILOT)
API Reference

PREVIEW DOCUMENTATION - This is a preview of a new format for the AWS SDK for Go API Reference documentation. For the current AWS SDK for Go API Reference, see https://docs.aws.amazon.com/sdk-for-go/api/.

We welcome your feedback on this new version of the documentation. Send your comments to aws-sdkdocs-feedback@amazon.com.

Signer

import "github.com/aws/aws-sdk-go/aws/signer/v4"

type Signer struct { Credentials *credentials.Credentials Debug aws.LogLevelType Logger aws.Logger DisableHeaderHoisting bool DisableURIPathEscaping bool DisableRequestBodyOverwrite bool UnsignedPayload bool }

Signer applies AWS v4 signing to given request. Use this to sign requests that need to be signed with AWS V4 Signatures.

Credentials

Type: *credentials.Credentials

The authentication credentials the request will be signed against. This value must be set to sign requests.

Debug

Type: aws.LogLevelType

Sets the log level the signer should use when reporting information to the logger. If the logger is nil nothing will be logged. See aws.LogLevelType for more information on available logging levels

By default nothing will be logged.

Logger

Type: aws.Logger

The logger loging information will be written to. If there the logger is nil, nothing will be logged.

DisableHeaderHoisting

Type: bool

Disables the Signer's moving HTTP header key/value pairs from the HTTP request header to the request's query string. This is most commonly used with pre-signed requests preventing headers from being added to the request's query string.

DisableURIPathEscaping

Type: bool

Disables the automatic escaping of the URI path of the request for the siganture's canonical string's path. For services that do not need additional escaping then use this to disable the signer escaping the path.

S3 is an example of a service that does not need additional escaping.

https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html

DisableRequestBodyOverwrite

Type: bool

Disables the automatical setting of the HTTP request's Body field with the io.ReadSeeker passed in to the signer. This is useful if you're using a custom wrapper around the body for the io.ReadSeeker and want to preserve the Body value on the Request.Body.

This does run the risk of signing a request with a body that will not be sent in the request. Need to ensure that the underlying data of the Body values are the same.

UnsignedPayload

Type: bool

UnsignedPayload will prevent signing of the payload. This will only work for services that have support for this.

Method

Presign

func (v4 Signer) Presign(r *http.Request, body io.ReadSeeker, service, region string, exp time.Duration, signTime time.Time) (http.Header, error)

Presign signs AWS v4 requests with the provided body, service name, region the request is made to, and time the request is signed at. The signTime allows you to specify that a request is signed for the future, and cannot be used until then.

Returns a list of HTTP headers that were included in the signature or an error if signing the request failed. For presigned requests these headers and their values must be included on the HTTP request when it is made. This is helpful to know what header values need to be shared with the party the presigned request will be distributed to.

Presign differs from Sign in that it will sign the request using query string instead of header values. This allows you to share the Presigned Request's URL with third parties, or distribute it throughout your system with minimal dependencies.

Presign also takes an exp value which is the duration the signed request will be valid after the signing time. This is allows you to set when the request will expire.

The requests body is an io.ReadSeeker so the SHA256 of the body can be generated. To bypass the signer computing the hash you can set the "X-Amz-Content-Sha256" header with a precomputed value. The signer will only compute the hash if the request header value is empty.

Presigning a S3 request will not compute the body's SHA256 hash by default. This is done due to the general use case for S3 presigned URLs is to share PUT/GET capabilities. If you would like to include the body's SHA256 in the presigned request's signature you can set the "X-Amz-Content-Sha256" HTTP header and that will be included in the request's signature.

Sign

func (v4 Signer) Sign(r *http.Request, body io.ReadSeeker, service, region string, signTime time.Time) (http.Header, error)

Sign signs AWS v4 requests with the provided body, service name, region the request is made to, and time the request is signed at. The signTime allows you to specify that a request is signed for the future, and cannot be used until then.

Returns a list of HTTP headers that were included in the signature or an error if signing the request failed. Generally for signed requests this value is not needed as the full request context will be captured by the http.Request value. It is included for reference though.

Sign will set the request's Body to be the `body` parameter passed in. If the body is not already an io.ReadCloser, it will be wrapped within one. If a `nil` body parameter passed to Sign, the request's Body field will be also set to nil. Its important to note that this functionality will not change the request's ContentLength of the request.

Sign differs from Presign in that it will sign the request using HTTP header values. This type of signing is intended for http.Request values that will not be shared, or are shared in a way the header values on the request will not be lost.

The requests body is an io.ReadSeeker so the SHA256 of the body can be generated. To bypass the signer computing the hash you can set the "X-Amz-Content-Sha256" header with a precomputed value. The signer will only compute the hash if the request header value is empty.

On this page: