Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bug: awslocal get-object-attributes does not return the checksums of the single parts #12757

Open
@mirkoscotti

Description

@mirkoscotti

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I uploaded a file to an S3 bucket in my Localstack server using multipart features with checksum enabled. The upload generated three parts. After the end of the process, the command
awslocal s3api get-object-attributes --bucket test-bucket --key file.txt --object-attributes Checksum ObjectParts
returns:

{
    "LastModified": "Sun, 15 Jun 2025 04:33:36 GMT",
    "Checksum": {
        "ChecksumSHA256": "R6zkFE4j0YnCkZJk/cJ+dI+Z/BcS9Ug1g+p3VNqF5Ik=",
        "ChecksumType": "COMPOSITE"
    },
    "ObjectParts": {
        "TotalPartsCount": 3
    }
}

Expected Behavior

The expected return is something like this:

{
    "LastModified": "Sun, 15 Jun 2025 04:33:36 GMT",
    "Checksum": {
        "ChecksumSHA256": "R6zkFE4j0YnCkZJk/cJ+dI+Z/BcS9Ug1g+p3VNqF5Ik=",
        "ChecksumType": "COMPOSITE"
    },
    "ObjectParts": {
        "TotalPartsCount": 3,
        "Parts": [
            {
                "PartNumber": 1,
                "Size": 5242880,
                "ChecksumSHA256": "abc123..."
            },
            {
                "PartNumber": 2,
                "Size": 5242880,
                "ChecksumSHA256": "def456..."
            },
            {
                "PartNumber": 3,
                "Size": 1048576,
                "ChecksumSHA256": "ghi789..."
            }
        ]
    }
}

How are you starting LocalStack?

I have executed a JUnit test with Testcontainers, implementing my custom container for S3

Steps To Reproduce

this is a fragment of the testcontainer implementation:

public class S3Container
	extends LocalStackContainer
{

	private static final String LOCALSTACK = "localstack";

	private static final String IMAGE_NAME = "%1$s/%1$s:4.5.0".formatted(LOCALSTACK);

	...

	private static final String GET_OBJECT_ATTRIBUTES_COMMAND = "awslocal s3api get-object-attributes --bucket %s --key %s --object-attributes %s %s";

	...

	public String checksum(String bucketName, String key)
	{
		String result;
		Object[] array = {bucketName, key, "Checksum", "ObjectParts"};
		var command = GET_OBJECT_ATTRIBUTES_COMMAND.formatted(array);
		try (var jsonb = JsonbBuilder.create())
		{
			var output = execInContainer("sh", "-c", command);
			var message = "Failed to retrieve the checksum of object %s in bucket %s";
			Assertions.assertEquals(0, output.getExitCode(), message.formatted(key, bucketName));
			var attributes = jsonb.fromJson(output.getStdout(), ObjectAttributes.class);
			result = attributes.checksum().checksumSha256();
		}
		catch (InterruptedException x)
		{
			Thread.currentThread().interrupt();
			result = Assertions.fail(x);
		}
		catch (Exception x)
		{
			result = Assertions.fail(x);
		}
		return result;
	}

	...

}

Invoke this method after having created a bucket and uploaded a file with multipart and checksum enabled using your preferred API.

Attached you can find the usage of all the phases of the multipart upload through the Java AWS SDK and the status of the debugger when the upload is going to complete. Checksums of every parts have been calculated as expected.

Image

Environment

- OS:
- LocalStack: Community 
  LocalStack version: 4.5.0
  LocalStack Docker image sha: localstack/localstack:4.5.0
  LocalStack build date: 2025, 5th of June

Anything else?

In order to check that my Java multipart upload has been successfully completed, I want to calculate the checksum of my local file applying the same algorithm explained here. Expand the "Using the AWS SDKs" section and see the method validateExistingFileAgainstS3Checksum for further details.

Metadata

Metadata

Assignees

Labels

aws:s3Amazon Simple Storage Servicetype: bugBug report

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions