Skip to content

Commit 1f8cc93

Browse files
committed
rolled in review comments
1 parent 195a864 commit 1f8cc93

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

javav2/example_code/s3/src/main/java/com/example/s3/express/S3DirectoriesActions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public CompletableFuture<List<String>> listObjectsAsync(S3AsyncClient s3Client,
191191
return s3Client.listObjectsV2(request)
192192
.thenApply(response -> response.contents().stream()
193193
.map(S3Object::key)
194-
.collect(Collectors.toList()))
194+
.toList())
195195
.whenComplete((result, exception) -> {
196196
if (exception != null) {
197197
throw new CompletionException("Couldn't list objects in bucket: " + bucketName, exception);

javav2/example_code/s3/src/main/java/com/example/s3/express/S3DirectoriesScenario.java

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void main(String[] args) {
7373
// Runs the scenario.
7474
private static void s3ExpressScenario() {
7575
logger.info(DASHES);
76-
logger.info("Welcome to the Amazon S3 Express Basics demo using AWS SDK for Java V2");
76+
logger.info("Welcome to the Amazon S3 Express Basics demo using AWS SDK for Java V2.");
7777
logger.info("""
7878
Let's get started! First, please note that S3 Express One Zone works best when working within the AWS infrastructure,
7979
specifically when working in the same Availability Zone (AZ). To see the best results in this example and when you implement
@@ -93,7 +93,7 @@ specifically when working in the same Availability Zone (AZ). To see the best re
9393
setupClientsAndBuckets(expressUserName, regularUserName);
9494

9595
// Create an S3 session for the express S3 client and add objects to the buckets.
96-
logger.info("Create an S3 session for the express S3 client and add objects to the buckets");
96+
logger.info("Now let's add some objects to our buckets and demonstrate how to work with S3 Sessions.");
9797
waitForInputToContinue(scanner);
9898
String bucketObject = createSessionAddObjects();
9999

@@ -104,7 +104,7 @@ specifically when working in the same Availability Zone (AZ). To see the best re
104104
// regular and express buckets.
105105
showLexicographicalDifferences(bucketObject);
106106

107-
logger.info("");
107+
logger.info(DASHES);
108108
logger.info("That's it for our tour of the basic operations for S3 Express One Zone.");
109109
logger.info("Would you like to cleanUp the AWS resources? (y/n): ");
110110
String response = scanner.next().trim().toLowerCase();
@@ -141,20 +141,21 @@ private static void cleanUp() {
141141
}
142142

143143
private static void showLexicographicalDifferences(String bucketObject) {
144+
logger.info(DASHES);
144145
logger.info("""
145-
7. Populate the buckets to show the lexicographical difference.
146-
Now let's explore how directory buckets store objects in a different
147-
manner to regular buckets. The key is in the name
146+
7. Populate the buckets to show the lexicographical (alphabetical) difference
147+
when object names are listed. Now let's explore how directory buckets store
148+
objects in a different manner to regular buckets. The key is in the name
148149
"Directory". Where regular buckets store their key/value pairs in a
149150
flat manner, directory buckets use actual directories/folders.
150151
This allows for more rapid indexing, traversing, and therefore
151152
retrieval times!
152153
153154
The more segmented your bucket is, with lots of
154155
directories, sub-directories, and objects, the more efficient it becomes.
155-
This structural difference also causes ListObjects to behave differently,
156-
which can cause unexpected results. Let's add a few more
157-
objects with layered directories to see how the output of
156+
This structural difference also causes `ListObject` operations to behave
157+
differently, which can cause unexpected results. Let's add a few more
158+
objects in subdirectories directories to see how the output of
158159
ListObjects changes.
159160
""");
160161

@@ -199,8 +200,8 @@ private static void showLexicographicalDifferences(String bucketObject) {
199200
}
200201

201202
logger.info("""
202-
Notice how the normal bucket lists objects in lexicographical order, while the directory bucket does not. This is
203-
because the normal bucket considers the whole "key" to be the object identifier, while the directory bucket actually
203+
Notice how the regular bucket lists objects in lexicographical order, while the directory bucket does not. This is
204+
because the regular bucket considers the whole "key" to be the object identifier, while the directory bucket actually
204205
creates directories and uses the object "key" as a path to the object.
205206
""");
206207
waitForInputToContinue(scanner);
@@ -223,6 +224,7 @@ private static void showLexicographicalDifferences(String bucketObject) {
223224
* @param bucketObject the name of the object to download
224225
*/
225226
private static void demonstratePerformance(String bucketObject) {
227+
logger.info(DASHES);
226228
logger.info("6. Demonstrate the performance difference.");
227229
logger.info("""
228230
Now, let's do a performance test. We'll download the same object from each
@@ -233,11 +235,11 @@ private static void demonstratePerformance(String bucketObject) {
233235
""");
234236
waitForInputToContinue(scanner);
235237

236-
int downloads = 1000; // Default value
237-
logger.info("The number of downloads of the same object for this example is set at " + downloads + ".");
238+
int downloads = 1000; // Default value.
239+
logger.info("The default number of downloads of the same object for this example is set at " + downloads + ".");
238240

239241
// Ask if the user wants to download a different number.
240-
logger.info("Would you like to download a different number? (y/n): ");
242+
logger.info("Would you like to download the file a different number of times? (y/n): ");
241243
String response = scanner.next().trim().toLowerCase();
242244
if (response.equals("y")) {
243245
int maxDownloads = 1_000_000;
@@ -266,7 +268,7 @@ private static void demonstratePerformance(String bucketObject) {
266268
logger.info("Downloading from the directory bucket.");
267269
long directoryTimeStart = System.nanoTime();
268270
for (int index = 0; index < downloads; index++) {
269-
if (index % 10 == 0) {
271+
if (index % 50 == 0) {
270272
logger.info("Download " + index + " of " + downloads);
271273
}
272274

@@ -281,11 +283,11 @@ private static void demonstratePerformance(String bucketObject) {
281283

282284
long directoryTimeDifference = System.nanoTime() - directoryTimeStart;
283285

284-
// Simulating the download process for the normal bucket.
286+
// Download from the regular bucket.
285287
logger.info("Downloading from the regular bucket.");
286288
long normalTimeStart = System.nanoTime();
287289
for (int index = 0; index < downloads; index++) {
288-
if (index % 10 == 0) {
290+
if (index % 50 == 0) {
289291
logger.info("Download " + index + " of " + downloads);
290292
}
291293

@@ -302,7 +304,7 @@ private static void demonstratePerformance(String bucketObject) {
302304
}
303305

304306
long normalTimeDifference = System.nanoTime() - normalTimeStart;
305-
logger.info("The directory bucket took " + directoryTimeDifference + " nanoseconds, while the normal bucket took " + normalTimeDifference + " nanoseconds.");
307+
logger.info("The directory bucket took " + directoryTimeDifference + " nanoseconds, while the regular bucket took " + normalTimeDifference + " nanoseconds.");
306308
long difference = normalTimeDifference - directoryTimeDifference;
307309
logger.info("That's a difference of " + difference + " nanoseconds, or");
308310
logger.info(difference / 1_000_000_000.0 + " seconds.");
@@ -314,10 +316,11 @@ private static void demonstratePerformance(String bucketObject) {
314316
}
315317

316318
private static String createSessionAddObjects() {
319+
logger.info(DASHES);
317320
logger.info("""
318321
5. Create an object and copy it.
319322
We'll create a basic object consisting of some text and upload it to the
320-
normal bucket.
323+
regular bucket.
321324
Next we'll copy the object into the directory bucket using the regular client.
322325
This works fine because copy operations are not restricted for directory buckets.
323326
""");
@@ -341,7 +344,7 @@ private static String createSessionAddObjects() {
341344
logger.info("""
342345
It worked! It's important to remember the user permissions when interacting with
343346
directory buckets. Instead of validating permissions on every call as
344-
normal buckets do, directory buckets utilize the user credentials and session
347+
regular buckets do, directory buckets utilize the user credentials and session
345348
token to validate. This allows for much faster connection speeds on every call.
346349
For single calls, this is low, but for many concurrent calls
347350
this adds up to a lot of time saved.
@@ -366,6 +369,7 @@ public static UserNames createVpcUsers() {
366369
Optionally create a VPC.
367370
Create two IAM users, one with S3 Express One Zone permissions and one without.
368371
*/
372+
logger.info(DASHES);
369373
logger.info("""
370374
1. First, we'll set up a new VPC and VPC Endpoint if this program is running in an EC2 instance in the same AZ as your\s
371375
directory buckets will be. Are you running this in an EC2 instance located in the same AZ as your intended directory buckets?
@@ -391,6 +395,7 @@ public static UserNames createVpcUsers() {
391395
} else {
392396
logger.info("Skipping the VPC setup. Don't forget to use this in production!");
393397
}
398+
logger.info(DASHES);
394399
logger.info("""
395400
2. Create a RegularUser and ExpressUser by using the AWS CDK.
396401
One IAM User, named RegularUser, will have permissions to work only
@@ -416,7 +421,7 @@ public static UserNames createVpcUsers() {
416421
* @return a {@link Map} of String keys and String values representing the stack outputs,
417422
* which may include user-related information such as user names and IDs.
418423
*/
419-
public static Map<String, String> createUsersUsingCDK() {
424+
public static Map<String, String> createUsersUsingCDK() {
420425
logger.info("We'll use an AWS CloudFormation template to create the IAM users and policies.");
421426
CloudFormationHelper.deployCloudFormationStack(stackName);
422427
return CloudFormationHelper.getStackOutputsAsync(stackName).join();
@@ -462,6 +467,7 @@ public static void setupClientsAndBuckets(String expressUserName, String regular
462467
return;
463468
}
464469

470+
logger.info(DASHES);
465471
logger.info("""
466472
3. Create 2 S3Clients; one uses the ExpressUser's credentials and one uses the RegularUser's credentials.
467473
The 2 S3Clients will use different credentials.
@@ -484,16 +490,17 @@ public static void setupClientsAndBuckets(String expressUserName, String regular
484490
We can now use the ExpressUser client to make calls to S3 Express operations.
485491
""");
486492
waitForInputToContinue(locscanner);
493+
logger.info(DASHES);
487494
logger.info("""
488495
4. Create two buckets.
489496
Now we will create a directory bucket which is the linchpin of the S3 Express One Zone service. Directory buckets
490-
behave in different ways from regular S3 buckets which we will explore here. We'll also create a normal bucket, put
491-
an object into the normal bucket, and copy it over to the directory bucket.
497+
behave differently from regular S3 buckets which we will explore here. We'll also create a regular bucket, put
498+
an object into the regular bucket, and copy it to the directory bucket.
492499
""");
493500

494501
logger.info("""
495-
Now, let's choose an availability zone for the directory bucket. We'll choose one
496-
that is supported.
502+
Now, let's choose an availability zone (AZ) for the directory bucket.
503+
We'll choose one that is supported.
497504
""");
498505
String zoneId;
499506
String regularBucketName;

0 commit comments

Comments
 (0)