I want to troubleshoot the errors that I experience when I use the AWS SDK for Java to access my Amazon Simple Storage Service (Amazon S3) resources.
Short description
With the AWS SDK for Java with Amazon S3, you can receive client-side exceptions when the SDK can’t send the request or parse the response. You can also receive service-side exceptions when Amazon S3 returns an error response. Identify the exception type in the stack trace, and then complete the resolution steps for that exception type.
Resolution
AmazonServiceException, AwsServiceException, or AmazonS3Exception
If you receive an AmazonServiceException, AwsServiceException, or AmazonS3Exception error, then an issue occurred after you successfully sent the request to the AWS service. To resolve the issue, check the HTTP status code in the stack trace response. The following examples are status code errors that you might encounter. For a full list of HTTP status codes, see List of error codes.
HTTP 400
The HTTP 400 error occurs because of incorrect request syntax. Before you send your request to Amazon S3, temporarily log or print your request to check your request syntax.
HTTP 403
You receive an HTTP 403 "Access denied" error when you don't have permission to perform actions. Check your AWS Identity and Access Management (IAM) permissions, service control policies (SCPs), S3 bucket policy, and object ownership to make sure that you have sufficient permissions. Also, make sure that your credentials didn't expire.
For GetObject requests, the "Access denied" error can occur when the caller doesn’t have s3:ListBucket permission and the object doesn’t exist.
For more information, see Troubleshoot access denied (403 Forbidden) errors in Amazon S3.
HTTP 404
Make sure that the S3 object exists in the bucket.
HTTP 409
You receive an HTTP 409 error when the request conflicts with the current state of the resource. For example, you can receive HTTP 409 if you try to create a bucket name that already exists. You can also receive this error if you try to delete a bucket that isn’t empty, or if concurrent requests conflict. Check the error code in the response, such as BucketAlreadyExists or BucketNotEmpty, and then retry the operation after you correct the conflict.
UnknownHostException
If you receive an UnknownHostException error, then confirm that DNS resolution works for the Amazon S3 endpoint hostname. Check DNS resolution from the same environment where your application runs. If your application runs in a VPC, then confirm that VPC DNS settings are turned on. Also confirm that the application can reach the configured DNS resolver. If your environment uses custom DNS servers or an HTTP proxy, then apply the DNS and proxy configuration consistently for the Java process.
Related information
Exception handling
Handling errors in the AWS SDK for Java 2.x
Configure retry behavior in the AWS SDK for Java 2.x
GetObject