4
4
#include < thread>
5
5
#include < iostream>
6
6
#include < aws/core/Aws.h>
7
- #include < aws/core/utils/logging/LogLevel.h>
8
7
#include < aws/core/client/ClientConfiguration.h>
9
8
#include < aws/s3/S3Client.h>
10
9
#include < aws/s3/model/CreateBucketRequest.h>
42
41
*/
43
42
static const int MAX_TIMEOUT_RETRIES = 20 ;
44
43
45
- static Aws::String createOneBucket (const Aws::S3::S3Client &s3Client) {
44
+ static Aws::String createOneBucket (const Aws::String &bucketNamePrefix, const Aws:: S3::S3Client &s3Client) {
46
45
// Create an S3 bucket within the us-west-2 AWS Region.
47
46
Aws::String uuid = Aws::Utils::UUID::RandomUUID ();
48
- Aws::String bucketName = " amzn-s3-demo-bucket- " +
47
+ Aws::String bucketName = bucketNamePrefix +
49
48
Aws::Utils::StringUtils::ToLower (uuid.c_str ());
50
49
51
50
Aws::S3::Model::CreateBucketRequest createBucketRequest;
@@ -160,13 +159,14 @@ bool deleteABucket(const Aws::S3::S3Client &s3Client, const Aws::String &bucketN
160
159
*/
161
160
162
161
bool AwsDoc::S3::listObjectsWithAwsGlobalRegion (
162
+ const Aws::String &bucketNamePrefix,
163
163
const Aws::S3::S3ClientConfiguration &clientConfig) {
164
164
Aws::S3::S3ClientConfiguration config (clientConfig);
165
165
config.region = Aws::Region::AWS_GLOBAL;
166
166
167
167
Aws::S3::S3Client s3Client (config);
168
168
169
- Aws::String bucketName = createOneBucket (s3Client);
169
+ Aws::String bucketName = createOneBucket (bucketNamePrefix, s3Client);
170
170
if (bucketName.empty ()) {
171
171
return false ;
172
172
}
@@ -186,17 +186,31 @@ bool AwsDoc::S3::listObjectsWithAwsGlobalRegion(
186
186
*
187
187
* main function
188
188
*
189
+ * Usage: ' run_list_objects_with_aws_global_region_bucket <bucket_name_prefix>'
190
+ *
189
191
*/
190
192
191
193
#ifndef EXCLUDE_MAIN_FUNCTION
192
194
193
- int main () {
195
+ int main (int argc, char *argv[]) {
196
+ if (argc != 2 ) {
197
+ std::cout << R"(
198
+ Usage:
199
+ run_list_objects_with_aws_global_region_bucket <bucket_name_prefix>
200
+ Where:
201
+ bucket_name - A bucket name prefix which will be made unique by appending a UUID.
202
+ )" << std::endl;
203
+ return 1 ;
204
+ }
205
+
194
206
Aws::SDKOptions options;
195
207
196
208
InitAPI (options);
209
+
210
+ Aws::String bucketNamePrefix = argv[1 ];
197
211
{
198
212
Aws::S3::S3ClientConfiguration config;
199
- AwsDoc::S3::listObjectsWithAwsGlobalRegion (config);
213
+ AwsDoc::S3::listObjectsWithAwsGlobalRegion (bucketNamePrefix, config);
200
214
}
201
215
ShutdownAPI (options);
202
216
0 commit comments