javadockeramazon-s3localstackaws-s3-client

Error reading file from S3: null (Service: S3, Status Code: 502) with GetObjectRequest


I am trying to read file from localstack s3 and getting below error

"message":"Error reading file from S3: null (Service: S3, Status Code: 502, Request ID: null)","exception":"","level_value":40000

Even i tried with single class locally it's working fine

enter code here  public static void main(String[] args) {
AwsBasicCredentials credentials = AwsBasicCredentials.create("test", "test");
StaticCredentialsProvider staticCredentialsProvider =
    StaticCredentialsProvider.create(credentials);

S3Client s3Client =
    S3Client.builder()
        .region(Region.of("us-east-1"))
        .endpointOverride(URI.create("http://localhost:4566"))
        .credentialsProvider(staticCredentialsProvider)
        .forcePathStyle(true)
        .build();
GetObjectRequest getObjectRequest =
    GetObjectRequest.builder().bucket("test").key("file.txt").build();
ResponseBytes<GetObjectResponse> response = s3Client.getObjectAsBytes(getObjectRequest);
System.out.println(response);

}

Can anyone help here why am i getting 502 in docker.

I tried with local java file it seems to be working. Getting 502 with docker


Solution

  • Issue was related to s3 url defined in properties file older aws.endpoint-s3=${AWS_ENDPOINT_S3:http://localhost:4566}

    new change cloud.aws.s3.endpoint=${AWS_ENDPOINT_S3:http://localhost:4566}

    key name should be defined like this only