Skip to content

S3 putObject via RequestBody.fromContentProvider yields an object with 0 bytes #5824

@tarehart

Description

@tarehart

Describe the bug

S3 putObject via RequestBody.fromContentProvider yields an object with 0 bytes. The operation completes as though it were successful, which increases the harm of this bug since there's potential for undetected data loss.

I believe this is related to #5801. The problem goes away when I set the environment variable AWS_REQUEST_CHECKSUM_CALCULATION=WHEN_REQUIRED.

This started with 2.30.0.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

S3 putObject via RequestBody.fromContentProvider uploads all content from the input stream, yielding an object with non-zero size in the S3 bucket.

Current Behavior

The object in S3 has zero bytes, despite the operation reporting success.

Reproduction Steps

package repro;

import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.HeadObjectRequest;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;

import java.io.IOException;
import java.net.URL;


public class UploadRepro {

    public static void main(String[] args) throws IOException {
        final var bucket = "XXXXXXXXXXXXXX";
        final var key = "XXXXXXXX";
        
        final var url = new URL(
            "https://raw.githubusercontent.com/aws/aws-sdk-java-v2/ad35231f768e1bb68e6f77cb29f69d1a7278931e/.changes/next-release/feature-AmazonS3-c101d4d.json"
        );

        var s3Client = S3Client.builder()
                .credentialsProvider(ProfileCredentialsProvider.builder().profileName("Dev-Admin").build())
                .region(Region.US_EAST_1)
                .build();

        try (var stream = url.openStream()) {
            s3Client.putObject(
                PutObjectRequest.builder().bucket(bucket).key(key).build(),
                RequestBody.fromContentProvider(() -> stream, "application/json")
            );
        }

        var length = s3Client.headObject(
            HeadObjectRequest.builder().bucket(bucket).key(key).build()
        ).contentLength();

        System.out.println(length); // prints 0
    }
}

Possible Solution

No response

Additional Information/Context

No response

AWS Java SDK version used

2.30.1

JDK version used

openjdk version "17.0.13"

Operating System and version

MacOS 15.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.p1This is a high priority issuepotential-regressionMarking this issue as a potential regression to be checked by team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions