Skip to content
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

Cpp: multi-service, add pagination #6370

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions cpp/example_code/acm/list_certificates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,48 @@ bool AwsDoc::ACM::listCertificates(
Aws::ACM::ACMClient acmClient(clientConfiguration);

Aws::ACM::Model::ListCertificatesRequest request;
Aws::Vector<Aws::ACM::Model::CertificateSummary> allCertificates;
Aws::String nextToken;
do {
if (!nextToken.empty()) {
request.SetNextToken(nextToken);
}

Aws::ACM::Model::ListCertificatesOutcome outcome =
acmClient.ListCertificates(request);

if (!outcome.IsSuccess()) {
std::cerr << "Error: ListCertificates: " <<
outcome.GetError().GetMessage() << std::endl;
Aws::ACM::Model::ListCertificatesOutcome outcome =
acmClient.ListCertificates(request);

return false;
}
else {
std::cout << "Success: Information about certificates: "
<< std::endl << std::endl;
if (!outcome.IsSuccess()) {
std::cerr << "Error: ListCertificates: " <<
outcome.GetError().GetMessage() << std::endl;

const Aws::ACM::Model::ListCertificatesResult &result = outcome.GetResult();
return false;
}
else {
const Aws::ACM::Model::ListCertificatesResult &result = outcome.GetResult();

Aws::Vector<Aws::ACM::Model::CertificateSummary> certificates =
result.GetCertificateSummaryList();
const Aws::Vector<Aws::ACM::Model::CertificateSummary> &certificates =
result.GetCertificateSummaryList();
allCertificates.insert(allCertificates.end(), certificates.begin(),
certificates.end());

if (certificates.size() > 0) {
for (const Aws::ACM::Model::CertificateSummary &certificate: certificates) {
std::cout << "Certificate ARN: " <<
certificate.GetCertificateArn() << std::endl;
std::cout << "Domain name: " <<
certificate.GetDomainName() << std::endl << std::endl;
}
nextToken = result.GetNextToken();
}
else {
std::cout << "No available certificates found in account. '" << std::endl;
} while (!nextToken.empty());

if (!allCertificates.empty()) {
for (const Aws::ACM::Model::CertificateSummary &certificate: allCertificates) {
std::cout << "Certificate ARN: " <<
certificate.GetCertificateArn() << std::endl;
std::cout << "Domain name: " <<
certificate.GetDomainName() << std::endl << std::endl;
}

return true;
}
else {
std::cout << "No available certificates found in account."
<< std::endl;
}

return true;
}
// snippet-end:[cpp.example_code.acm.ListCertificates]

Expand Down
10 changes: 5 additions & 5 deletions cpp/example_code/aurora/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ Code excerpts that show you how to call individual service functions.
- [Create a DB cluster parameter group](getting_started_with_db_clusters.cpp#L333) (`CreateDBClusterParameterGroup`)
- [Create a DB cluster snapshot](getting_started_with_db_clusters.cpp#L661) (`CreateDBClusterSnapshot`)
- [Create a DB instance in a DB cluster](getting_started_with_db_clusters.cpp#L588) (`CreateDBInstance`)
- [Delete a DB cluster](getting_started_with_db_clusters.cpp#L1033) (`DeleteDBCluster`)
- [Delete a DB cluster parameter group](getting_started_with_db_clusters.cpp#L1103) (`DeleteDBClusterParameterGroup`)
- [Delete a DB instance](getting_started_with_db_clusters.cpp#L1003) (`DeleteDBInstance`)
- [Delete a DB cluster](getting_started_with_db_clusters.cpp#L1047) (`DeleteDBCluster`)
- [Delete a DB cluster parameter group](getting_started_with_db_clusters.cpp#L1117) (`DeleteDBClusterParameterGroup`)
- [Delete a DB instance](getting_started_with_db_clusters.cpp#L1017) (`DeleteDBInstance`)
- [Describe DB cluster parameter groups](getting_started_with_db_clusters.cpp#L295) (`DescribeDBClusterParameterGroups`)
- [Describe DB cluster snapshots](getting_started_with_db_clusters.cpp#L701) (`DescribeDBClusterSnapshots`)
- [Describe DB clusters](getting_started_with_db_clusters.cpp#L746) (`DescribeDBClusters`)
- [Describe DB instances](getting_started_with_db_clusters.cpp#L883) (`DescribeDBInstances`)
- [Describe DB instances](getting_started_with_db_clusters.cpp#L896) (`DescribeDBInstances`)
- [Describe database engine versions](getting_started_with_db_clusters.cpp#L845) (`DescribeDBEngineVersions`)
- [Describe options for DB instances](getting_started_with_db_clusters.cpp#L923) (`DescribeOrderableDBInstanceOptions`)
- [Describe options for DB instances](getting_started_with_db_clusters.cpp#L936) (`DescribeOrderableDBInstanceOptions`)
- [Describe parameters from a DB cluster parameter group](getting_started_with_db_clusters.cpp#L786) (`DescribeDBClusterParameters`)
- [Update parameters in a DB cluster parameter group](getting_started_with_db_clusters.cpp#L402) (`ModifyDBClusterParameterGroup`)

Expand Down
38 changes: 26 additions & 12 deletions cpp/example_code/aurora/getting_started_with_db_clusters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,19 +864,32 @@ bool AwsDoc::Aurora::getDBEngineVersions(const Aws::String &engineName,
request.SetDBParameterGroupFamily(parameterGroupFamily);
}

Aws::RDS::Model::DescribeDBEngineVersionsOutcome outcome =
client.DescribeDBEngineVersions(request);
engineVersionsResult.clear();
Aws::String marker; // The marker is used for pagination.
do {
if (!marker.empty()) {
request.SetMarker(marker);
}

if (outcome.IsSuccess()) {
engineVersionsResult = outcome.GetResult().GetDBEngineVersions();
}
else {
std::cerr << "Error with Aurora::DescribeDBEngineVersionsRequest. "
<< outcome.GetError().GetMessage()
<< std::endl;
}
Aws::RDS::Model::DescribeDBEngineVersionsOutcome outcome =
client.DescribeDBEngineVersions(request);

return outcome.IsSuccess();
if (outcome.IsSuccess()) {
const Aws::Vector<Aws::RDS::Model::DBEngineVersion> &engineVersions =
outcome.GetResult().GetDBEngineVersions();

engineVersionsResult.insert(engineVersionsResult.end(),
engineVersions.begin(), engineVersions.end());
marker = outcome.GetResult().GetMarker();
}
else {
std::cerr << "Error with Aurora::DescribeDBEngineVersionsRequest. "
<< outcome.GetError().GetMessage()
<< std::endl;
}
} while (!marker.empty());

return true;
}
// snippet-end:[cpp.example_code.aurora.DescribeDBEngineVersions]

Expand Down Expand Up @@ -954,7 +967,8 @@ bool AwsDoc::Aurora::chooseDBInstanceClass(const Aws::String &engine,
outcome.GetResult().GetOrderableDBInstanceOptions();
for (const Aws::RDS::Model::OrderableDBInstanceOption &option: options) {
const Aws::String &instanceClass = option.GetDBInstanceClass();
if (std::find(instanceClasses.begin(), instanceClasses.end(), instanceClass) == instanceClasses.end()) {
if (std::find(instanceClasses.begin(), instanceClasses.end(),
instanceClass) == instanceClasses.end()) {
instanceClasses.push_back(instanceClass);
}
}
Expand Down
51 changes: 31 additions & 20 deletions cpp/example_code/autoscaling/groups_and_instances_scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,28 +565,39 @@ bool AwsDoc::AutoScaling::groupsAndInstancesScenario(
Aws::AutoScaling::Model::DescribeScalingActivitiesRequest request;
request.SetAutoScalingGroupName(groupName);

Aws::AutoScaling::Model::DescribeScalingActivitiesOutcome outcome =
autoScalingClient.DescribeScalingActivities(request);
Aws::Vector<Aws::AutoScaling::Model::Activity> allActivities;
Aws::String nextToken; // Used for pagination;
do {
if (!nextToken.empty()) {
request.SetNextToken(nextToken);
}
Aws::AutoScaling::Model::DescribeScalingActivitiesOutcome outcome =
autoScalingClient.DescribeScalingActivities(request);

if (outcome.IsSuccess()) {
const Aws::Vector<Aws::AutoScaling::Model::Activity> &activities =
outcome.GetResult().GetActivities();
std::cout << "Found " << activities.size() << " activities." << std::endl;
std::cout << "Activities are ordered with the most recent first."
<< std::endl;
for (const Aws::AutoScaling::Model::Activity &activity: activities) {
std::cout << activity.GetDescription() << std::endl;
std::cout << activity.GetDetails() << std::endl;
if (outcome.IsSuccess()) {
const Aws::Vector<Aws::AutoScaling::Model::Activity> &activities =
outcome.GetResult().GetActivities();
allActivities.insert(allActivities.end(), activities.begin(), activities.end());
nextToken = outcome.GetResult().GetNextToken();
}
}
else {
std::cerr << "Error with AutoScaling::DescribeScalingActivities. "
<< outcome.GetError().GetMessage()
<< std::endl;
// snippet-end:[cpp.example_code.autoscaling.describe_scaling_activities1]
cleanupResources(groupName, templateName, autoScalingClient, ec2Client);
return false;
// snippet-start:[cpp.example_code.autoscaling.describe_scaling_activities2]
else {
std::cerr << "Error with AutoScaling::DescribeScalingActivities. "
<< outcome.GetError().GetMessage()
<< std::endl;
// snippet-end:[cpp.example_code.autoscaling.describe_scaling_activities1]
cleanupResources(groupName, templateName, autoScalingClient, ec2Client);
return false;
// snippet-start:[cpp.example_code.autoscaling.describe_scaling_activities2]
}
} while (!nextToken.empty());

std::cout << "Found " << allActivities.size() << " activities."
<< std::endl;
std::cout << "Activities are ordered with the most recent first."
<< std::endl;
for (const Aws::AutoScaling::Model::Activity &activity: allActivities) {
std::cout << activity.GetDescription() << std::endl;
std::cout << activity.GetDetails() << std::endl;
}
// snippet-end:[cpp.example_code.autoscaling.describe_scaling_activities2]
}
Expand Down
66 changes: 38 additions & 28 deletions cpp/example_code/cloudtrail/lookup_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,50 @@
* Look up Cloud Trail events based on command line input
*/

int main(int argc, char **argv)
{
if (argc != 1)
{
std::cout << "Usage: lookup_events";
return 1;
}
Aws::SDKOptions options;
Aws::InitAPI(options);
{
int main(int argc, char **argv) {
if (argc != 1) {
std::cout << "Usage: lookup_events";
return 1;
}
Aws::SDKOptions options;
Aws::InitAPI(options);
{
Aws::CloudTrail::CloudTrailClient ct;

Aws::CloudTrail::CloudTrailClient ct;
Aws::CloudTrail::Model::LookupEventsRequest le_req;

Aws::CloudTrail::Model::LookupEventsRequest le_req;
int event_count = 0;
Aws::String nextToken; // Used for pagination.
do {
if (!nextToken.empty()) {
le_req.SetNextToken(nextToken);
}

auto le_out = ct.LookupEvents(le_req);
auto le_out = ct.LookupEvents(le_req);

if (le_out.IsSuccess())
{
std::cout << "Successfully looking up cloudtrail events:";
if (le_out.IsSuccess()) {
std::cout << "Successfully looking up cloudtrail events:";
const auto &events = le_out.GetResult().GetEvents();

for (auto val: le_out.GetResult().GetEvents())
{
std::cout << " " << val.GetEventName() << std::endl;
}
}
for (auto val: events) {
std::cout << " " << val.GetEventName() << std::endl;
}

else
{
std::cout << "Error looking up cloudtrail events" << le_out.GetError().GetMessage()
<< std::endl;
event_count += events.size();

nextToken = le_out.GetResult().GetNextToken();
}

else {
std::cout << "Error looking up cloudtrail events"
<< le_out.GetError().GetMessage()
<< std::endl;
break;
}
} while (!nextToken.empty() &&
(event_count < 100)); // Only show first 100 events.
}
}

Aws::ShutdownAPI(options);
return 0;
Aws::ShutdownAPI(options);
return 0;
}
99 changes: 53 additions & 46 deletions cpp/example_code/codebuild/list_builds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,65 @@
* Gets the list of builds and information about each build based on command line input
*/

int main(int argc, char **argv)
{
if (argc != 2)
{
std::cout << "Usage: list_builds <sort_order_type>";
return 1;
}
Aws::SDKOptions options;
Aws::InitAPI(options);
{
Aws::CodeBuild::CodeBuildClient codebuild;

Aws::CodeBuild::Model::ListBuildsRequest lb_req;
Aws::CodeBuild::Model::BatchGetBuildsRequest bgb_req;

if (Aws::Utils::StringUtils::CaselessCompare(argv[1], "ASCENDING"))
{
lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::ASCENDING);
}
else if(Aws::Utils::StringUtils::CaselessCompare(argv[1], "DESCENDING"))
{
lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::DESCENDING);
int main(int argc, char **argv) {
if (argc != 2) {
std::cout << "Usage: list_builds <sort_order_type>";
return 1;
}
else
Aws::SDKOptions options;
Aws::InitAPI(options);
{
lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::NOT_SET);
}
Aws::CodeBuild::CodeBuildClient codebuild;

auto lb_out = codebuild.ListBuilds(lb_req);
Aws::CodeBuild::Model::ListBuildsRequest lb_req;
Aws::CodeBuild::Model::BatchGetBuildsRequest bgb_req;

if (lb_out.IsSuccess())
{
std::cout << "Information about each build:" << std::endl;
bgb_req.SetIds(lb_out.GetResult().GetIds());
auto bgb_out = codebuild.BatchGetBuilds(bgb_req);

if (bgb_out.IsSuccess())
{
for (auto val: bgb_out.GetResult().GetBuilds())
{
std::cout << val.GetId() << std::endl;
if (Aws::Utils::StringUtils::CaselessCompare(argv[1], "ASCENDING")) {
lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::ASCENDING);
}
else if (Aws::Utils::StringUtils::CaselessCompare(argv[1], "DESCENDING")) {
lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::DESCENDING);
}
else {
lb_req.SetSortOrder(Aws::CodeBuild::Model::SortOrderType::NOT_SET);
}
}
}

else
{
std::cout << "Error listing builds" << lb_out.GetError().GetMessage()
<< std::endl;
Aws::String next_token; // Used for pagination.

do {
if (!next_token.empty()) {
lb_req.SetNextToken(next_token);
}

auto lb_out = codebuild.ListBuilds(lb_req);

if (lb_out.IsSuccess()) {
std::cout << "Information about each build:" << std::endl;
bgb_req.SetIds(lb_out.GetResult().GetIds());
auto bgb_out = codebuild.BatchGetBuilds(bgb_req);

if (bgb_out.IsSuccess()) {
const auto &builds = bgb_out.GetResult().GetBuilds();
std::cout << builds.size() << " build(s) found." << std::endl;
for (auto val: builds) {
std::cout << val.GetId() << std::endl;
}
}

next_token = lb_out.GetResult().GetNextToken();
}

else {
std::cout << "Error listing builds" << lb_out.GetError().GetMessage()
<< std::endl;
break;
}

} while (!next_token.empty());

}
}

Aws::ShutdownAPI(options);
return 0;

Aws::ShutdownAPI(options);
return 0;
}
Loading
Loading