s3.getObject(bucket,key) fails with 400

dreamobjects

#1

Guys getting the following exceptions while trying to use getObject() of aws-java-sdk.
Is it a compatibility issue?

the call is simple.
AmazonS3Client dreamObjectsS3 = new AmazonS3Client(new BasicAWSCredentials(“key”, “secret”));
dreamObjectsS3.setEndpoint(“objects.dreamhost.com”);
dreamObjectsS3.getObject(
bucket, key //my bucket and filekey
);

Exception in thread “main” com.amazonaws.services.s3.model.AmazonS3Exception: null (Service: Amazon S3; Status Code: 400; Error Code: InvalidArgument; Request ID: null), S3 Extended Request ID: null
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1077)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:725)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:460)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:295)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3736)
at com.amazonaws.services.s3.AmazonS3Client.getObject(AmazonS3Client.java:1163)
at com.amazonaws.services.s3.AmazonS3Client$3.getS3ObjectStream(AmazonS3Client.java:1252)
at com.amazonaws.services.s3.internal.ServiceUtils.retryableDownloadS3ObjectToFile(ServiceUtils.java:346)
at com.amazonaws.services.s3.AmazonS3Client.getObject(AmazonS3Client.java:1248)

thank you!!!


#2

I just ran into this problem and hadn’t gotten a chance to update the documentation yet. It looks like the 1.9 version of the java sdk is checking the endpoint name to determine the region and whether or not to use the newer v4 signing method. The easiest workaround I found was to use an sdk below version 1.9 since DreamObjects only supports v2 signing with its S3 compatible api today.


#3

Thank you, I used the following libs from maven now it’s working perfectly.

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-core</artifactId>
        <version>1.9.21</version>
    </dependency>
    <dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk</artifactId>
    <version>1.8.9.1</version>
</dependency>