skip to Main Content

I’m encountering an issue with the AWS SDK for Java v2 specifically for S3, but only on one particular Mac computer. The same code works fine on other machines (both Mac and Ubuntu). Interestingly, the AWS SDK v1 works perfectly on this problematic Mac, as does the AWS CLI.
Here’s a snippet of the Java code I’m using:

String accessKeyId = “<my-access-key>;
String secretAccessKey = "<my-secret-access-key>”;

String bucketName = "activate-datafeed";
String prefix = "work_area/";

// Create AWS credentials
AwsBasicCredentials awsCredentials = AwsBasicCredentials.create(accessKeyId, secretAccessKey);

// Create the S3 client
S3Client s3 = S3Client.builder()
    .region(Region.US_EAST_1) // Replace with your bucket's region
    .credentialsProvider(StaticCredentialsProvider.create(awsCredentials))
    .build();

try {
    // List objects in the specified bucket and prefix
    ListObjectsV2Request listObjectsReqManual = ListObjectsV2Request.builder()
        .bucket(bucketName)
        .prefix(prefix)
        .build();

    ListObjectsV2Response listObjResponse = s3.listObjectsV2(listObjectsReqManual);
    // Process response...
} catch (S3Exception e) {
    e.printStackTrace();
}

Here’s my Maven dependency:

<dependency>
    <groupId>software.amazon.awssdk</groupId>
    <artifactId>s3</artifactId>
    <version>2.20.0</version> 
</dependency>

The Issue:

On the problematic Mac, I receive the following stack trace:

software.amazon.awssdk.services.s3.model.S3Exception: null (Service: S3, Status Code: 400, Request ID: null) 
at software.amazon.awssdk.protocols.xml.internal.unmarshall.AwsXmlPredicatedResponseHandler.handleErrorResponse(...) 
... 
at    software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient$RequestExecutionBuilderImpl.execute(...) 
at software.amazon.awssdk.core.internal.handler.BaseSyncClientHandler.invoke(...) 
at software.amazon.awssdk.services.s3.DefaultS3Client.listObjectsV2(DefaultS3Client.java:6430) 
at com.example.s3.S3ListObjects.main(S3ListObjects.java:39)

What I’ve Tried:

•   The connection works on other machines, so it's likely specific to this particular Mac.
•   AWS SDK v1 works fine on this Mac, as does the AWS CLI.
•   I've confirmed that the region, bucket name, and credentials are correct.

What Could Be the Issue?
I’m wondering if there’s something specific to the environment on this Mac that’s causing the problem with AWS SDK v2. Could it be related to the Java installation, network configuration, or something else?
Any insights or troubleshooting tips would be greatly appreciated!

2

Answers


  1. Check your POM. If you have this:

      <dependency>
           <groupId>software.amazon.awssdk</groupId>
           <artifactId>bom</artifactId>
           <version>2.26.14</version>
           <type>pom</type>
           <scope>import</scope>
       </dependency>
    

    You do not need to specify a version here:

    <dependency>
        <groupId>software.amazon.awssdk</groupId>
        <artifactId>s3</artifactId>
        <version>2.20.0</version> 
    </dependency>
    

    Having a mismatch between the versions of the AWS SDK BOM (Bill of Materials) and the individual service dependencies can lead to runtime errors. A version mismatch can indeed cause issues, such as the S3Exception you’re encountering

    Login or Signup to reply.
  2. Make sure the pom looks like

     <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>software.amazon.awssdk</groupId>
                <artifactId>bom</artifactId>
                <version>2.26.14</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    <dependencies>
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>s3</artifactId>
        </dependency>
    </dependencies>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search