Interface AwsV4HttpSigner
- All Superinterfaces:
AwsV4FamilyHttpSigner<AwsCredentialsIdentity>
,HttpSigner<AwsCredentialsIdentity>
- All Known Implementing Classes:
DefaultAwsV4HttpSigner
An
HttpSigner
that will use the AWS V4 signing algorithm to sign a request using an
AwsCredentialsIdentity
).
The steps performed by this signer are documented here.
Using the AwsV4HttpSigner
Sign an HTTP request and send it to a service.
AwsV4HttpSigner signer = AwsV4HttpSigner.create();
// Specify AWS credentials. Credential providers that are used by the SDK by default are
// available in the module "auth" (e.g. DefaultCredentialsProvider).
AwsCredentialsIdentity credentials =
AwsSessionCredentialsIdentity.create("skid", "akid", "stok");
// Create the HTTP request to be signed
SdkHttpRequest httpRequest =
SdkHttpRequest.builder()
.uri("https://s3.us-west-2.amazonaws.com/bucket/object")
.method(SdkHttpMethod.PUT)
.putHeader("Content-Type", "text/plain")
.build();
// Create the request payload to be signed
ContentStreamProvider requestPayload =
ContentStreamProvider.fromUtf8String("Hello, World!");
// Sign the request. Some services require custom signing configuration properties (e.g. S3).
// See AwsV4HttpSigner and AwsV4FamilyHttpSigner for the available signing options.
// Note: The S3Client class below requires a dependency on the 's3' module. Alternatively, the
// signing name can be hard-coded because it is guaranteed to not change.
SignedRequest signedRequest =
signer.sign(r -> r.identity(credentials)
.request(httpRequest)
.payload(requestPayload)
.putProperty(AwsV4HttpSigner.SERVICE_SIGNING_NAME, S3Client.SERVICE_NAME)
.putProperty(AwsV4HttpSigner.REGION_NAME, "us-west-2")
.putProperty(AwsV4HttpSigner.DOUBLE_URL_ENCODE, false) // Required for S3 only
.putProperty(AwsV4HttpSigner.NORMALIZE_PATH, false)); // Required for S3 only
// Create and HTTP client and send the request. ApacheHttpClient requires the 'apache-client' module.
try (SdkHttpClient httpClient = ApacheHttpClient.create()) {
HttpExecuteRequest httpExecuteRequest =
HttpExecuteRequest.builder()
.request(signedRequest.request())
.contentStreamProvider(signedRequest.payload().orElse(null))
.build();
HttpExecuteResponse httpResponse =
httpClient.prepareRequest(httpExecuteRequest).call();
System.out.println("HTTP Status Code: " + httpResponse.httpResponse().statusCode());
} catch (IOException e) {
System.err.println("HTTP Request Failed.");
e.printStackTrace();
}
-
Nested Class Summary
Nested classes/interfaces inherited from interface software.amazon.awssdk.http.auth.aws.signer.AwsV4FamilyHttpSigner
AwsV4FamilyHttpSigner.AuthLocation
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SignerProperty
<String> The AWS region name to be used for computing the signature.Fields inherited from interface software.amazon.awssdk.http.auth.aws.signer.AwsV4FamilyHttpSigner
AUTH_LOCATION, CHECKSUM_ALGORITHM, CHUNK_ENCODING_ENABLED, DOUBLE_URL_ENCODE, EXPIRATION_DURATION, NORMALIZE_PATH, PAYLOAD_SIGNING_ENABLED, SERVICE_SIGNING_NAME
Fields inherited from interface software.amazon.awssdk.http.auth.spi.signer.HttpSigner
SIGNING_CLOCK
-
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic AwsV4HttpSigner
create()
Get a default implementation of aAwsV4HttpSigner
-
Field Details
-
REGION_NAME
The AWS region name to be used for computing the signature. This property is required.
-
-
Method Details
-
create
Get a default implementation of aAwsV4HttpSigner
-