Skip to content

feat: put object with instruction file configured #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

akareddy04
Copy link

@akareddy04 akareddy04 commented May 30, 2025

Issue #, if available: #355

Description of changes:
*Adds ability to add instruction file configuration for putObject

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Check any applicable:

  • Were any files moved? Moving files changes their URL, which breaks all hyperlinks to the files.

@akareddy04 akareddy04 requested a review from a team as a code owner May 30, 2025 18:47
Comment on lines 1 to 2
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to include these lines in every file, they should not be deleted here.

Comment on lines 127 to 129
"To work around this issue you can disable multi part upload," +
"use the Async client, or not set this value on PutObject." +
"You may be able to update this value after the PutObject request completes."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"To work around this issue you can disable multi part upload," +
"use the Async client, or not set this value on PutObject." +
"You may be able to update this value after the PutObject request completes."
"To work around this issue you can disable Instruction File on PutObject or disable " +
"multi part upload, or use the Async client, or not set this value on PutObject." +
"You may be able to update this value after the request completes."

The text should be slightly different as it only applies to cases where InstructionFile puts are enabled.

// Rather than silently dropping the value,
// we loudly signal that we don't know how to handle this field.
throw new IllegalArgumentException(
f.locationName() + " is an unknown field. " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f.locationName() + " is an unknown field. " +
f.memberName() + " is an unknown field. " +

Please fix this in the other convertRequest method, we missed that originally.

@@ -12,6 +12,131 @@

public class ConvertSDKRequests {

public static PutObjectRequest convertRequest(CreateMultipartUploadRequest request) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We should add some comments here, i.e. that this is used to set the optional fields for Instruction File puts when the request is a multipart upload, because the instruction file is Put with an ordinary PutObject request.

And likewise for the other convertRequest method which is used to set the optional fields on high-level Multipart PutObject requests.

@@ -255,6 +262,7 @@ public MultipartUploadObjectPipeline build() {
.secureRandom(_secureRandom)
.build();
}
_contentMetadataEncodingStrategy = new ContentMetadataEncodingStrategy(_instructionFileConfig);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a null check for instructionFileConfig, it should never be null but for robustness, we should check if null and create a default instruction file config.

final InputStream objectStreamForResult = new BoundedInputStream(fileSizeLimit);

S3Client wrappedClient = S3Client.create();
S3Client s3Client = S3EncryptionClient.builder()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to set .enableMultipartPutObject(true) to enable multipart put.

.bucket(BUCKET)
.key(object_key + ".instruction")
.build());
assertTrue(directInstGetResponse.response().metadata().containsKey("x-amz-crypto-instr-file"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also set StorageClass in the original put request and check for it here.



CreateMultipartUploadResponse initiateResult = v3Client.createMultipartUpload(builder ->
builder.bucket(BUCKET).key(object_key));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also set StorageClass here and check for it in the directInstGetResponse later on.

@@ -3,6 +3,7 @@
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.services.s3.model.*;

import java.awt.event.ComponentListener;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unused

}

@Test
public void testConversionAllFields() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Specify that this is for CreateMPUToPutObject

Copy link
Contributor

@kessplas kessplas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor things to fix

Comment on lines 16 to 18
/*Converts a CreateMultipartUploadRequest into a PutObjectRequest by setting optional fields needed for
putInstructionFile operation.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a Javadoc comment. Meaning, it comes before the method and it has this syntax (most importantly, the two *s in the first block):

/**
 * Comment here
 */
public whatever methodName() {

There are many examples throughout the codebase. Your IDE should also render them as green rather than grey.

In terms of content, it is not really accurate. We should specify that the conversion is used when Instruction File PutObject is enabled and the customer performs a multipart upload. putInstructionFile doesn't exist in v3.

@@ -138,7 +140,9 @@ public static PutObjectRequest convertRequest(CreateMultipartUploadRequest reque
}

public static CreateMultipartUploadRequest convertRequest(PutObjectRequest request) {

/*Converts a PutObjectRequest into a CreateMultipartUploadRequest by setting optional fields needed for high-level
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@@ -45,6 +45,7 @@
import software.amazon.awssdk.services.s3.model.PutObjectResponse;
import software.amazon.awssdk.services.s3.model.S3Exception;
import software.amazon.awssdk.services.s3.model.StorageClass;
import software.amazon.awssdk.services.s3.model.StorageClassAnalysisDataExport;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is used

Copy link
Contributor

@kessplas kessplas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, lets get another review for this though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants