Interface AwsV4aHttpSigner
- All Superinterfaces:
AwsV4FamilyHttpSigner<AwsCredentialsIdentity>
,HttpSigner<AwsCredentialsIdentity>
- All Known Implementing Classes:
DefaultAwsCrtV4aHttpSigner
An
HttpSigner
that will use the AWS V4a signing algorithm to sign a request using an
AwsCredentialsIdentity
).
AWS request signing is described here.
Using the AwsV4aHttpSigner
Sign an HTTP request and send it to a service.
AwsV4aHttpSigner signer = AwsV4aHttpSigner.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 AwsV4aHttpSigner 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(AwsV4aHttpSigner.SERVICE_SIGNING_NAME, S3Client.SERVICE_NAME)
.putProperty(AwsV4aHttpSigner.REGION_SET, RegionSet.create("us-west-2"))
.putProperty(AwsV4aHttpSigner.DOUBLE_URL_ENCODE, false) // Required for S3 only
.putProperty(AwsV4aHttpSigner.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
<RegionSet> The AWS region-set 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 AwsV4aHttpSigner
create()
Get a default implementation of aAwsV4aHttpSigner
-
Field Details
-
REGION_SET
The AWS region-set to be used for computing the signature. This property is required.
-
-
Method Details
-
create
Get a default implementation of aAwsV4aHttpSigner
-