Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm attempting to narrow down the following 400 Bad Request error:

com.amazonaws.services.s3.model.AmazonS3Exception: Bad Request (Service: Amazon S3; Status Code: 400; Error Code: 400 Bad Request; Request ID: 7FBD3901B77A07C0), S3 Extended Request ID: +PrYXDrq9qJwhwHh+DmPusGekwWf+jmU2jepUkQX3zGa7uTT3GA1GlmHLkJjjjO67UQTndQA9PE=
    at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1343)
    at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:961)
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:738)
    at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:489)
    at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:448)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:397)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:378)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4039)
    at com.amazonaws.services.s3.AmazonS3Client.getObjectMetadata(AmazonS3Client.java:1177)
    at com.amazonaws.services.s3.AmazonS3Client.getObjectMetadata(AmazonS3Client.java:1152)
    at com.amazonaws.services.s3.AmazonS3Client.doesObjectExist(AmazonS3Client.java:1212)
    at com.abcnews.apwebfeed.articleresolver.APWebFeedArticleResolverImpl.makeS3Crops(APWebFeedArticleResolverImpl.java:904)
    at com.abcnews.apwebfeed.articleresolver.APWebFeedArticleResolverImpl.resolve(APWebFeedArticleResolverImpl.java:542)
    at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.xfire.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:54)
    at org.codehaus.xfire.service.binding.ServiceInvocationHandler.sendMessage(ServiceInvocationHandler.java:322)
    at org.codehaus.xfire.service.binding.ServiceInvocationHandler$1.run(ServiceInvocationHandler.java:86)
    at java.lang.Thread.run(Thread.java:662)

I'm testing something as imple as this:

boolean exists = s3client.doesObjectExist("aws-wire-qa", "wfiles/in/wire.json");

I manually added the wfiles/in/wire.json file. I get back true when I run this line inside a local app. But inside a separate remote service it throws the error above. I use the same credentials inside the service as I use in my local app. I also set bucket as "Enable website hosting", but no difference. My permissions are set as:

Grantee: Any Authenticated AWS User
y List 
y Upload/DeleteView 
y PermissionsEdit Permissions    

So I thought the error could be related to not having a policy on the bucket and created a policy file on the bucket for GET/PUT/DELETE objects, but I'm still getting the same error. My policy look like this:

"Version": "2012-10-17", "Id": "Policy1481303257155", "Statement": [ "Sid": "Stmt1481303250933", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::755710071517:user/law" "Action": [ "s3:DeleteObject", "s3:GetObject", "s3:PutObject" "Resource": "arn:aws:s3:::aws-wire-qa/*"

I was told it can't be a firewall or a proxy issue. What else I could try? The error is very non-specific. And so far I did only local development, so I have no idea what else can be not set up here. Would much appreciate some help here.

This isn't related to permissions. It's possible that you could be sending the request to the wrong S3 region. – Michael - sqlbot Dec 14, 2016 at 3:49 @Michael-sqlbot: you are absolutely right, I was testing earlier with another bucket and managed not to change the region. Thanks a lot! Right on target! – user2917629 Dec 14, 2016 at 16:54 Permissions issues were easily ruled out because that should be 403 Forbidden... I'm glad that fixed it but, to be honest, that was just an intuitive guess -- one possibility among several that could cause a 400 Bad Request response. I would like to think that the Java SDK provides a mechanism to access the response headers and body, because the information should be there, and that would make for a more legitimate and useful answer. – Michael - sqlbot Dec 14, 2016 at 18:18 I am not a Java developer, so I may have no idea what I'm asking, but I found this, so I wonder... using that, is it possible for you to use getErrorResponseXml() to extract the error XML from the exception? – Michael - sqlbot Dec 14, 2016 at 18:21 Locally installed the angular application which was running in another machine and tried executing doesObjectExist. It throws the same error mentioned in the question. I am using app-dev.yml properties file to fetch region and bucket name. A Configuration File creates a Bean using which I check for doesObjectExist. It works without an error using PostMan Tool, it throws error when I hit the same service using angular application. Is there something angular application should have? When I debug the java code in STS the region is same for both requests (via angular and Posstman). – Mohammed Idris Oct 4, 2019 at 12:42

In my case that was a region issue!
I had to remove the region from the elasticsearch.yml and set in the command. If I don't remove the region from the yml file, elastic won't start (with the latest s3-repository plugin)

Name: repository-s3
Description: The S3 repository plugin adds S3 repositories
Version: 5.2.2
 * Classname: org.elasticsearch.plugin.repository.s3.S3RepositoryPlugin
                mine too was a region error, use fiddler to view their response as the .net exception is not clear.
– Ronen Festinger
                Oct 9, 2017 at 14:40
                Also region error for me, but interestingly enough the file still showed up fine in S3. Go figure.
– d512
                Nov 16, 2017 at 22:25

Using Fiddler I've seen that my url was wrong.

I didn't need to use ServiceURL property and config class, instead, I used this constructor for the client, use your region as the third parameter.

        AmazonS3Client s3Client = new AmazonS3Client(
                ACCESSKEY,
                SECRETKEY,
                Amazon.RegionEndpoint.USEast1

I too had the same error and later found that this was due to an issue withe proxy setting. After disabling the proxy was able to upload to S3 fine.

-Dhttp.nonProxyHosts=s3***.com

It is just to register my particular case... I am configuring dspace to use S3. It is very clearly explained, but with region "eu-north-1" does not work. Error 400 is returned by Amazonaws.

Create a bucket test with us-west-1 (by default) , and try.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.