aws-sdk-java-v2 icon indicating copy to clipboard operation
aws-sdk-java-v2 copied to clipboard

GZIP Request and Response Configuration

Open sedovalx opened this issue 7 years ago • 7 comments

Here is how I create a client:

AthenaClient
    .builder()
    .region(Region.of(environment.aws.region))
    .credentialsProvider(DefaultCredentialsProvider.create())
    .overrideConfiguration {
        it.apiCallTimeout(Duration.ofMillis(environment.athena.executionTimeout.toLong()))
//                    it.gzipEnabled(true)
//                    it.totalExecutionTimeout(Duration.ofMillis(environment.athena.executionTimeout.toLong()))
    }
    .build()

Previously I could use the gzipEnabled property to enable gzip encoding, it is absent now. Can you give me an example of setting it up?

sedovalx avatar Nov 21 '18 21:11 sedovalx

Right now, GZIP usage is determined automatically based on the service and HTTP implementation itself. There's no flag to force it on. Is this causing you latency issues?

millems avatar Nov 21 '18 21:11 millems

I'm doing queries to Athena and its responses might be relatively big json entities. So yes, it may cause problems but I haven't done any measurements yet. Just migrating from 2.0.0-preview-9 and have noticed that response data from Athena came without compressing. The same for DynamoDb.

sedovalx avatar Nov 21 '18 22:11 sedovalx

Migrating this to a feature request to add the option of enabling HTTP-level compressing. This would be on the HTTP client implementation itself.

millems avatar Nov 21 '18 22:11 millems

You MAY be able to workaround this by adding a custom header Accept-Encoding: gzip.

Something like this

GetQueryResults.builder()
   .overrideConfiguration(o -> o.putHeader("Accept-Encoding", "gzip"))
   .build()

shorea avatar Nov 23 '18 20:11 shorea

software.amazon.awssdk.core.exception.Crc32MismatchException. Please help to fix

nidhinr007 avatar Jan 24 '23 09:01 nidhinr007

You MAY be able to workaround this by adding a custom header Accept-Encoding: gzip.

Something like this

GetQueryResults.builder()
   .overrideConfiguration(o -> o.putHeader("Accept-Encoding", "gzip"))
   .build()

This doesn't really work, adds the header but the request is no compressed at all.

cristianocca avatar May 24 '23 20:05 cristianocca

Hi,

@millems Based on PR https://github.com/aws/aws-sdk-java-v2/pull/4371, it appears that compression configuration was introduced to the SDK in 2023. Using this configuration, I was able to successfully compress the payload for a PUT request on DynamoDbClient:

     // Enable GZIP compression for requests above 1024 bytes
     CompressionConfiguration compressionConfig = CompressionConfiguration.builder()
            .requestCompressionEnabled(true)
            .minimumCompressionThresholdInBytes(1024)
            .build();

    RequestCompression requestCompressionTrait = RequestCompression.builder()
            .encodings("gzip")
            .isStreaming(false)
            .build();

    // Apply compression to the client
    ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder()
            .compressionConfiguration(compressionConfig)
            .putExecutionAttribute(SdkInternalExecutionAttribute.REQUEST_COMPRESSION,
                    requestCompressionTrait)
            .build();
    
    DynamoDbClient dynamoDbClient = DynamoDbClient.builder()
            .credentialsProvider(credentialsProvider())
            .region(Region.of(environment.aws.region))
            .overrideConfiguration(overrideConfig)
            .build();

    PutItemResponse response = dynamoDbClient.putItem(putItemRequest);

Did I understand correctly that this PR resolves the linked GitHub issue?

roamariei avatar Mar 21 '25 09:03 roamariei