@@ -73,7 +73,7 @@ public static void main(String[] args) {
73
73
// Runs the scenario.
74
74
private static void s3ExpressScenario () {
75
75
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. " );
77
77
logger .info ("""
78
78
Let's get started! First, please note that S3 Express One Zone works best when working within the AWS infrastructure,
79
79
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
93
93
setupClientsAndBuckets (expressUserName , regularUserName );
94
94
95
95
// 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. " );
97
97
waitForInputToContinue (scanner );
98
98
String bucketObject = createSessionAddObjects ();
99
99
@@ -104,7 +104,7 @@ specifically when working in the same Availability Zone (AZ). To see the best re
104
104
// regular and express buckets.
105
105
showLexicographicalDifferences (bucketObject );
106
106
107
- logger .info ("" );
107
+ logger .info (DASHES );
108
108
logger .info ("That's it for our tour of the basic operations for S3 Express One Zone." );
109
109
logger .info ("Would you like to cleanUp the AWS resources? (y/n): " );
110
110
String response = scanner .next ().trim ().toLowerCase ();
@@ -141,20 +141,21 @@ private static void cleanUp() {
141
141
}
142
142
143
143
private static void showLexicographicalDifferences (String bucketObject ) {
144
+ logger .info (DASHES );
144
145
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
148
149
"Directory". Where regular buckets store their key/value pairs in a
149
150
flat manner, directory buckets use actual directories/folders.
150
151
This allows for more rapid indexing, traversing, and therefore
151
152
retrieval times!
152
153
153
154
The more segmented your bucket is, with lots of
154
155
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
158
159
ListObjects changes.
159
160
""" );
160
161
@@ -199,8 +200,8 @@ private static void showLexicographicalDifferences(String bucketObject) {
199
200
}
200
201
201
202
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
204
205
creates directories and uses the object "key" as a path to the object.
205
206
""" );
206
207
waitForInputToContinue (scanner );
@@ -223,6 +224,7 @@ private static void showLexicographicalDifferences(String bucketObject) {
223
224
* @param bucketObject the name of the object to download
224
225
*/
225
226
private static void demonstratePerformance (String bucketObject ) {
227
+ logger .info (DASHES );
226
228
logger .info ("6. Demonstrate the performance difference." );
227
229
logger .info ("""
228
230
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) {
233
235
""" );
234
236
waitForInputToContinue (scanner );
235
237
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 + "." );
238
240
239
241
// 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): " );
241
243
String response = scanner .next ().trim ().toLowerCase ();
242
244
if (response .equals ("y" )) {
243
245
int maxDownloads = 1_000_000 ;
@@ -266,7 +268,7 @@ private static void demonstratePerformance(String bucketObject) {
266
268
logger .info ("Downloading from the directory bucket." );
267
269
long directoryTimeStart = System .nanoTime ();
268
270
for (int index = 0 ; index < downloads ; index ++) {
269
- if (index % 10 == 0 ) {
271
+ if (index % 50 == 0 ) {
270
272
logger .info ("Download " + index + " of " + downloads );
271
273
}
272
274
@@ -281,11 +283,11 @@ private static void demonstratePerformance(String bucketObject) {
281
283
282
284
long directoryTimeDifference = System .nanoTime () - directoryTimeStart ;
283
285
284
- // Simulating the download process for the normal bucket.
286
+ // Download from the regular bucket.
285
287
logger .info ("Downloading from the regular bucket." );
286
288
long normalTimeStart = System .nanoTime ();
287
289
for (int index = 0 ; index < downloads ; index ++) {
288
- if (index % 10 == 0 ) {
290
+ if (index % 50 == 0 ) {
289
291
logger .info ("Download " + index + " of " + downloads );
290
292
}
291
293
@@ -302,7 +304,7 @@ private static void demonstratePerformance(String bucketObject) {
302
304
}
303
305
304
306
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." );
306
308
long difference = normalTimeDifference - directoryTimeDifference ;
307
309
logger .info ("That's a difference of " + difference + " nanoseconds, or" );
308
310
logger .info (difference / 1_000_000_000.0 + " seconds." );
@@ -314,10 +316,11 @@ private static void demonstratePerformance(String bucketObject) {
314
316
}
315
317
316
318
private static String createSessionAddObjects () {
319
+ logger .info (DASHES );
317
320
logger .info ("""
318
321
5. Create an object and copy it.
319
322
We'll create a basic object consisting of some text and upload it to the
320
- normal bucket.
323
+ regular bucket.
321
324
Next we'll copy the object into the directory bucket using the regular client.
322
325
This works fine because copy operations are not restricted for directory buckets.
323
326
""" );
@@ -341,7 +344,7 @@ private static String createSessionAddObjects() {
341
344
logger .info ("""
342
345
It worked! It's important to remember the user permissions when interacting with
343
346
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
345
348
token to validate. This allows for much faster connection speeds on every call.
346
349
For single calls, this is low, but for many concurrent calls
347
350
this adds up to a lot of time saved.
@@ -366,6 +369,7 @@ public static UserNames createVpcUsers() {
366
369
Optionally create a VPC.
367
370
Create two IAM users, one with S3 Express One Zone permissions and one without.
368
371
*/
372
+ logger .info (DASHES );
369
373
logger .info ("""
370
374
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
371
375
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() {
391
395
} else {
392
396
logger .info ("Skipping the VPC setup. Don't forget to use this in production!" );
393
397
}
398
+ logger .info (DASHES );
394
399
logger .info ("""
395
400
2. Create a RegularUser and ExpressUser by using the AWS CDK.
396
401
One IAM User, named RegularUser, will have permissions to work only
@@ -416,7 +421,7 @@ public static UserNames createVpcUsers() {
416
421
* @return a {@link Map} of String keys and String values representing the stack outputs,
417
422
* which may include user-related information such as user names and IDs.
418
423
*/
419
- public static Map <String , String > createUsersUsingCDK () {
424
+ public static Map <String , String > createUsersUsingCDK () {
420
425
logger .info ("We'll use an AWS CloudFormation template to create the IAM users and policies." );
421
426
CloudFormationHelper .deployCloudFormationStack (stackName );
422
427
return CloudFormationHelper .getStackOutputsAsync (stackName ).join ();
@@ -462,6 +467,7 @@ public static void setupClientsAndBuckets(String expressUserName, String regular
462
467
return ;
463
468
}
464
469
470
+ logger .info (DASHES );
465
471
logger .info ("""
466
472
3. Create 2 S3Clients; one uses the ExpressUser's credentials and one uses the RegularUser's credentials.
467
473
The 2 S3Clients will use different credentials.
@@ -484,16 +490,17 @@ public static void setupClientsAndBuckets(String expressUserName, String regular
484
490
We can now use the ExpressUser client to make calls to S3 Express operations.
485
491
""" );
486
492
waitForInputToContinue (locscanner );
493
+ logger .info (DASHES );
487
494
logger .info ("""
488
495
4. Create two buckets.
489
496
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.
492
499
""" );
493
500
494
501
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.
497
504
""" );
498
505
String zoneId ;
499
506
String regularBucketName ;
0 commit comments