Repository navigation
Expand file tree
/
Copy pathlist_buckets.cpp
More file actions
80 lines (65 loc) · 2.23 KB
/
Copy pathlist_buckets.cpp
File metadata and controls
80 lines (65 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#include <iostream>
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/Bucket.h>
#include "s3_examples.h"
/**
* Before running this C++ code example, set up your development environment, including your credentials.
*
* For more information, see the following documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started.html
*
* Purpose
*
* Demonstrates using the AWS SDK for C++ to list the buckets in the current account.
*
*/
//! Routine which demonstrates listing the buckets in the current account.
/*!
\param clientConfig: Aws client configuration.
\return bool: Function succeeded.
*/
// snippet-start:[s3.cpp.list_buckets.code]
bool AwsDoc::S3::listBuckets(const Aws::S3::S3ClientConfiguration &clientConfig) {
Aws::S3::S3Client client(clientConfig);
auto outcome = client.ListBuckets();
bool result = true;
if (!outcome.IsSuccess()) {
std::cerr << "Failed with error: " << outcome.GetError() << std::endl;
result = false;
} else {
std::cout << "Found " << outcome.GetResult().GetBuckets().size() << " buckets\n";
for (auto &&b: outcome.GetResult().GetBuckets()) {
std::cout << b.GetName() << std::endl;
}
}
return result;
}
// snippet-end:[s3.cpp.list_buckets.code]
/*
*
* main function
*
*/
#ifndef EXCLUDE_MAIN_FUNCTION
int main() {
//The Aws::SDKOptions struct contains SDK configuration options.
//An instance of Aws::SDKOptions is passed to the Aws::InitAPI and
//Aws::ShutdownAPI methods. The same instance should be sent to both methods.
Aws::SDKOptions options;
//The AWS SDK for C++ must be initialized by calling Aws::InitAPI.
InitAPI(options);
{
Aws::S3::S3ClientConfiguration clientConfig;
// Optional: Set to the AWS Region in which the bucket was created (overrides config file).
// clientConfig.region = "us-east-1";
AwsDoc::S3::listBuckets(clientConfig);
}
//Before the application terminates, the SDK must be shut down.
ShutdownAPI(options);
return 0;
}
#endif // EXCLUDE_MAIN_FUNCTION