diff --git a/cpp/example_code/acm/list_certificates.cpp b/cpp/example_code/acm/list_certificates.cpp index 7025a0a739d..71eefe3c8cf 100644 --- a/cpp/example_code/acm/list_certificates.cpp +++ b/cpp/example_code/acm/list_certificates.cpp @@ -28,39 +28,48 @@ bool AwsDoc::ACM::listCertificates( Aws::ACM::ACMClient acmClient(clientConfiguration); Aws::ACM::Model::ListCertificatesRequest request; + Aws::Vector 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 certificates = - result.GetCertificateSummaryList(); + const Aws::Vector &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] diff --git a/cpp/example_code/aurora/README.md b/cpp/example_code/aurora/README.md index a63d6b76fce..9824ddb1e09 100644 --- a/cpp/example_code/aurora/README.md +++ b/cpp/example_code/aurora/README.md @@ -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`) diff --git a/cpp/example_code/aurora/getting_started_with_db_clusters.cpp b/cpp/example_code/aurora/getting_started_with_db_clusters.cpp index 6fa26d4a652..ddf70ed6846 100644 --- a/cpp/example_code/aurora/getting_started_with_db_clusters.cpp +++ b/cpp/example_code/aurora/getting_started_with_db_clusters.cpp @@ -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 &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] @@ -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); } } diff --git a/cpp/example_code/autoscaling/groups_and_instances_scenario.cpp b/cpp/example_code/autoscaling/groups_and_instances_scenario.cpp index 9c417752ba8..183e64164f9 100644 --- a/cpp/example_code/autoscaling/groups_and_instances_scenario.cpp +++ b/cpp/example_code/autoscaling/groups_and_instances_scenario.cpp @@ -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 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 &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 &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] } diff --git a/cpp/example_code/cloudtrail/lookup_events.cpp b/cpp/example_code/cloudtrail/lookup_events.cpp index 090d37f6553..52910796e92 100644 --- a/cpp/example_code/cloudtrail/lookup_events.cpp +++ b/cpp/example_code/cloudtrail/lookup_events.cpp @@ -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; } diff --git a/cpp/example_code/codebuild/list_builds.cpp b/cpp/example_code/codebuild/list_builds.cpp index 64e7d276b73..8a122493ee2 100644 --- a/cpp/example_code/codebuild/list_builds.cpp +++ b/cpp/example_code/codebuild/list_builds.cpp @@ -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 "; - 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 "; + 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; } diff --git a/cpp/example_code/codecommit/list_branches.cpp b/cpp/example_code/codecommit/list_branches.cpp index 666bdf71486..1444bd93e9a 100644 --- a/cpp/example_code/codecommit/list_branches.cpp +++ b/cpp/example_code/codecommit/list_branches.cpp @@ -12,44 +12,56 @@ * Lists branches of a repository based on command line inputs */ -int main(int argc, char ** argv) -{ - if (argc != 2) - { - std::cout << "Usage: list_branches " - << std::endl; - return 1; - } +int main(int argc, char **argv) { + if (argc != 2) { + std::cout << "Usage: list_branches " + << std::endl; + return 1; + } - Aws::SDKOptions options; - Aws::InitAPI(options); - { - Aws::String repository_name(argv[1]); + Aws::SDKOptions options; + Aws::InitAPI(options); + { + Aws::String repository_name(argv[1]); - Aws::CodeCommit::CodeCommitClient codecommit; + Aws::CodeCommit::CodeCommitClient codecommit; - Aws::CodeCommit::Model::ListBranchesRequest lb_req; + Aws::CodeCommit::Model::ListBranchesRequest lb_req; - lb_req.SetRepositoryName(repository_name); + lb_req.SetRepositoryName(repository_name); - auto lb_out = codecommit.ListBranches(lb_req); + Aws::Vector all_branches; + Aws::String next_token; // Used for pagination. - if (lb_out.IsSuccess()) - { - std::cout << "Successfully listing branches names as: "; + do { + if (!next_token.empty()) { + lb_req.SetNextToken(next_token); + } - for (auto val: lb_out.GetResult().GetBranches()) - { - std::cout << " " << val; - } - } - else - { - std::cout << "Error listing branches." << lb_out.GetError().GetMessage() - << std::endl; + // List branches. + auto lb_out = codecommit.ListBranches(lb_req); + + if (lb_out.IsSuccess()) { + const auto &branches = lb_out.GetResult().GetBranches(); + all_branches.insert(all_branches.cend(), branches.cbegin(), + branches.cbegin()); + + next_token = lb_out.GetResult().GetNextToken(); + } + else { + std::cout << "Error listing branches." << lb_out.GetError().GetMessage() + << std::endl; + break; + } + } while (!next_token.empty()); + + std::cout << all_branches.size() << " branch(es) found." << std::endl; + + for (const auto &branch: all_branches) { + std::cout << " " << branch << std::endl; + } } - } - Aws::ShutdownAPI(options); - return 0; + Aws::ShutdownAPI(options); + return 0; } diff --git a/cpp/example_code/codecommit/list_pull_requests.cpp b/cpp/example_code/codecommit/list_pull_requests.cpp index c4034098eb7..d408983edf6 100644 --- a/cpp/example_code/codecommit/list_pull_requests.cpp +++ b/cpp/example_code/codecommit/list_pull_requests.cpp @@ -12,44 +12,55 @@ * Lists pull requests of a repository based on command line inputs */ -int main(int argc, char ** argv) -{ - if (argc != 2) - { - std::cout << "Usage: list_pull_requests " - << std::endl; - return 1; - } +int main(int argc, char **argv) { + if (argc != 2) { + std::cout << "Usage: list_pull_requests " + << std::endl; + return 1; + } - Aws::SDKOptions options; - Aws::InitAPI(options); - { - Aws::String repository_name(argv[1]); + Aws::SDKOptions options; + Aws::InitAPI(options); + { + Aws::String repository_name(argv[1]); - Aws::CodeCommit::CodeCommitClient codecommit; + Aws::CodeCommit::CodeCommitClient codecommit; - Aws::CodeCommit::Model::ListPullRequestsRequest lpr_req; + Aws::CodeCommit::Model::ListPullRequestsRequest lpr_req; - lpr_req.SetRepositoryName(repository_name); + lpr_req.SetRepositoryName(repository_name); - auto lpr_out = codecommit.ListPullRequests(lpr_req); + Aws::Vector all_pull_request; + Aws::String next_token; // Used for pagination. - if (lpr_out.IsSuccess()) - { - std::cout << "Successfully listed pull requests with pull request ids as: "; + do { + if (!next_token.empty()) { + lpr_req.SetNextToken(next_token); + } + auto lpr_out = codecommit.ListPullRequests(lpr_req); - for (auto val: lpr_out.GetResult().GetPullRequestIds()) - { - std::cout << " " << val; - } - } - else - { - std::cout << "Error getting pull requests" << lpr_out.GetError().GetMessage() - << std::endl; + if (lpr_out.IsSuccess()) { + const auto &lpr_res = lpr_out.GetResult().GetPullRequestIds(); + all_pull_request.insert(all_pull_request.cend(), lpr_res.cbegin(), + lpr_res.cend()); + + next_token = lpr_out.GetResult().GetNextToken(); + } + else { + std::cout << "Error getting pull requests" + << lpr_out.GetError().GetMessage() + << std::endl; + break; + } + } while (!next_token.empty()); + + std::cout << all_pull_request.size() << " pull request(s) found." << std::endl; + + for (const auto &pull_request: all_pull_request) { + std::cout << "Pull request: " << pull_request << std::endl; + } } - } - Aws::ShutdownAPI(options); - return 0; + Aws::ShutdownAPI(options); + return 0; } diff --git a/cpp/example_code/dynamodb/scan_table.cpp b/cpp/example_code/dynamodb/scan_table.cpp index 5caf9c189f7..93eba5af09f 100644 --- a/cpp/example_code/dynamodb/scan_table.cpp +++ b/cpp/example_code/dynamodb/scan_table.cpp @@ -40,35 +40,47 @@ bool AwsDoc::DynamoDB::scanTable(const Aws::String &tableName, if (!projectionExpression.empty()) request.SetProjectionExpression(projectionExpression); - // Perform scan on table. - const Aws::DynamoDB::Model::ScanOutcome &outcome = dynamoClient.Scan(request); - if (outcome.IsSuccess()) { - // Reference the retrieved items. - const Aws::Vector> &items = outcome.GetResult().GetItems(); - if (!items.empty()) { - std::cout << "Number of items retrieved from scan: " << items.size() - << std::endl; - // Iterate each item and print. - for (const Aws::Map &itemMap: items) { - std::cout << "******************************************************" - << std::endl; - // Output each retrieved field and its value. - for (const auto &itemEntry: itemMap) - std::cout << itemEntry.first << ": " << itemEntry.second.GetS() - << std::endl; - } + Aws::Vector> all_items; + Aws::Map last_evaluated_key; // Used for pagination; + do { + if (!last_evaluated_key.empty()) { + request.SetExclusiveStartKey(last_evaluated_key); } + const Aws::DynamoDB::Model::ScanOutcome &outcome = dynamoClient.Scan(request); + if (outcome.IsSuccess()) { + // Reference the retrieved items. + const Aws::Vector> &items = outcome.GetResult().GetItems(); + all_items.insert(all_items.end(), items.begin(), items.end()); + last_evaluated_key = outcome.GetResult().GetLastEvaluatedKey(); + } else { - std::cout << "No item found in table: " << tableName << std::endl; + std::cerr << "Failed to Scan items: " << outcome.GetError().GetMessage() + << std::endl; + return false; + } + + } while (!last_evaluated_key.empty()); + + if (!all_items.empty()) { + std::cout << "Number of items retrieved from scan: " << all_items.size() + << std::endl; + // Iterate each item and print. + for (const Aws::Map &itemMap: all_items) { + std::cout << "******************************************************" + << std::endl; + // Output each retrieved field and its value. + for (const auto &itemEntry: itemMap) + std::cout << itemEntry.first << ": " << itemEntry.second.GetS() + << std::endl; } } + else { - std::cerr << "Failed to Scan items: " << outcome.GetError().GetMessage() - << std::endl; + std::cout << "No items found in table: " << tableName << std::endl; } - return outcome.IsSuccess(); + return true; } // snippet-end:[dynamodb.cpp.scan_table.code] diff --git a/cpp/example_code/ebs/describe_volumes.cpp b/cpp/example_code/ebs/describe_volumes.cpp index d295cfa49bc..71294c32c26 100644 --- a/cpp/example_code/ebs/describe_volumes.cpp +++ b/cpp/example_code/ebs/describe_volumes.cpp @@ -7,39 +7,49 @@ #include #include -int main(int argc, char ** argv) -{ - if (argc != 1) - { - std::cout << "Usage: describe_volumes" << std::endl; - return 1; - } +int main(int argc, char **argv) { + if (argc != 1) { + std::cout << "Usage: describe_volumes" << std::endl; + return 1; + } - Aws::SDKOptions options; - Aws::InitAPI(options); - { - Aws::EC2::EC2Client ec2; + Aws::SDKOptions options; + Aws::InitAPI(options); + { + Aws::EC2::EC2Client ec2; - Aws::EC2::Model::DescribeVolumesRequest dv_req; + Aws::EC2::Model::DescribeVolumesRequest dv_req; - auto dv_out = ec2.DescribeVolumes(dv_req); + Aws::Vector all_volumes; + Aws::String next_token; - if (dv_out.IsSuccess()) - { - std::cout << "Successfully describing volumes as:"; - for (auto val: dv_out.GetResult().GetVolumes()) - { - std::cout << " " << val.GetVolumeId(); - } - std::cout << std::endl; - } - else - { - std::cout << "Error describing volumes" << dv_out.GetError().GetMessage() - << std::endl; + do { + if (!next_token.empty()) { + dv_req.SetNextToken(next_token); + } + auto dv_out = ec2.DescribeVolumes(dv_req); + + if (dv_out.IsSuccess()) { + const auto &volumes = dv_out.GetResult().GetVolumes(); + all_volumes.insert(all_volumes.end(), volumes.begin(), volumes.end()); + + next_token = dv_out.GetResult().GetNextToken(); + } + else { + std::cout << "Error describing volumes" + << dv_out.GetError().GetMessage() + << std::endl; + break; + } + } while (!next_token.empty()); + + std::cout << all_volumes.size() << " volume(s) found:" << std::endl; + for (auto val: all_volumes) { + std::cout << " " << val.GetVolumeId() << std::endl; + } + std::cout << std::endl; } - } - Aws::ShutdownAPI(options); - return 0; + Aws::ShutdownAPI(options); + return 0; } diff --git a/cpp/example_code/glue/README.md b/cpp/example_code/glue/README.md index 558e76aeac3..61285588bb1 100644 --- a/cpp/example_code/glue/README.md +++ b/cpp/example_code/glue/README.md @@ -35,6 +35,7 @@ Next, for information on code example structures and how to build and run the ex + ### Get started @@ -47,18 +48,18 @@ Next, for information on code example structures and how to build and run the ex Code excerpts that show you how to call individual service functions. - [Create a crawler](glue_getting_started_scenario.cpp#L181) (`CreateCrawler`) -- [Create a job definition](glue_getting_started_scenario.cpp#L364) (`CreateJob`) -- [Delete a crawler](glue_getting_started_scenario.cpp#L674) (`DeleteCrawler`) -- [Delete a database from the Data Catalog](glue_getting_started_scenario.cpp#L654) (`DeleteDatabase`) -- [Delete a job definition](glue_getting_started_scenario.cpp#L634) (`DeleteJob`) +- [Create a job definition](glue_getting_started_scenario.cpp#L373) (`CreateJob`) +- [Delete a crawler](glue_getting_started_scenario.cpp#L720) (`DeleteCrawler`) +- [Delete a database from the Data Catalog](glue_getting_started_scenario.cpp#L700) (`DeleteDatabase`) +- [Delete a job definition](glue_getting_started_scenario.cpp#L680) (`DeleteJob`) - [Get a crawler](glue_getting_started_scenario.cpp#L210) (`GetCrawler`) - [Get a database from the Data Catalog](glue_getting_started_scenario.cpp#L302) (`GetDatabase`) -- [Get a job run](glue_getting_started_scenario.cpp#L590) (`GetJobRun`) -- [Get runs of a job](glue_getting_started_scenario.cpp#L555) (`GetJobRuns`) +- [Get a job run](glue_getting_started_scenario.cpp#L636) (`GetJobRun`) +- [Get runs of a job](glue_getting_started_scenario.cpp#L589) (`GetJobRuns`) - [Get tables from a database](glue_getting_started_scenario.cpp#L327) (`GetTables`) -- [List job definitions](glue_getting_started_scenario.cpp#L524) (`ListJobs`) +- [List job definitions](glue_getting_started_scenario.cpp#L547) (`ListJobs`) - [Start a crawler](glue_getting_started_scenario.cpp#L235) (`StartCrawler`) -- [Start a job run](glue_getting_started_scenario.cpp#L394) (`StartJobRun`) +- [Start a job run](glue_getting_started_scenario.cpp#L403) (`StartJobRun`) ### Scenarios @@ -107,6 +108,30 @@ This example shows you how to do the following: - List information about job runs, view transformed data, and clean up resources. + +You can create the resources needed for the example using the CDK script [resources/cdk/glue_role_bucket](../../../resources/cdk/glue_role_bucket). + +Note: The AWS CDK and npm must be installed to use the script. + +From the [resources/cdk/glue_role_bucket](../../../resources/cdk/glue_role_bucket) folder, run the commands: +```bash +npm install +cdk deploy +``` + +Use the following outputs in the example. + +```bash +doc-example-glue-scenario-stack.BucketName = doc-example-glue-scenario-s-docexampleglue1234567-890abcdef +doc-example-glue-scenario-stack.RoleName = AWSGlueServiceRole-DocExample + +``` + +The resources can be deleted with the following command: +```bash +cdk destroy +``` + diff --git a/cpp/example_code/glue/glue_getting_started_scenario.cpp b/cpp/example_code/glue/glue_getting_started_scenario.cpp index 3466734de89..87b0b363cc6 100644 --- a/cpp/example_code/glue/glue_getting_started_scenario.cpp +++ b/cpp/example_code/glue/glue_getting_started_scenario.cpp @@ -58,7 +58,7 @@ #include #include #include -#include +#include #include #include #include @@ -327,34 +327,43 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa // snippet-start:[cpp.example_code.glue.GetTables] Aws::Glue::Model::GetTablesRequest request; request.SetDatabaseName(CRAWLER_DATABASE_NAME); - - Aws::Glue::Model::GetTablesOutcome outcome = client.GetTables(request); - - if (outcome.IsSuccess()) { - const std::vector &tables = outcome.GetResult().GetTableList(); - std::cout << "The database contains " << tables.size() - << (tables.size() == 1 ? - " table." : "tables.") << std::endl; - std::cout << "Here is a list of the tables in the database."; - for (size_t index = 0; index < tables.size(); ++index) { - std::cout << " " << index + 1 << ": " << tables[index].GetName() - << std::endl; + std::vector all_tables; + Aws::String nextToken; // Used for pagination. + do { + Aws::Glue::Model::GetTablesOutcome outcome = client.GetTables(request); + + if (outcome.IsSuccess()) { + const std::vector &tables = outcome.GetResult().GetTableList(); + all_tables.insert(all_tables.end(), tables.begin(), tables.end()); + nextToken = outcome.GetResult().GetNextToken(); } - - if (!tables.empty()) { - int tableIndex = askQuestionForIntRange( - "Enter an index to display the database detail ", - 1, static_cast(tables.size())); - std::cout << tables[tableIndex - 1].Jsonize().View().WriteReadable() + else { + std::cerr << "Error getting the tables. " + << outcome.GetError().GetMessage() << std::endl; + deleteAssets(CRAWLER_NAME, CRAWLER_DATABASE_NAME, "", bucketName, + clientConfig); + return false; } + } while (!nextToken.empty()); + + std::cout << "The database contains " << all_tables.size() + << (all_tables.size() == 1 ? + " table." : "tables.") << std::endl; + std::cout << "Here is a list of the tables in the database."; + for (size_t index = 0; index < all_tables.size(); ++index) { + std::cout << " " << index + 1 << ": " << all_tables[index].GetName() + << std::endl; } - else { - std::cerr << "Error getting the tables. " << outcome.GetError().GetMessage() + + if (!all_tables.empty()) { + int tableIndex = askQuestionForIntRange( + "Enter an index to display the database detail ", + 1, static_cast(all_tables.size())); + std::cout << all_tables[tableIndex - 1].Jsonize().View().WriteReadable() << std::endl; - deleteAssets(CRAWLER_NAME, CRAWLER_DATABASE_NAME, "", bucketName, - clientConfig); - return false; + + tableName = all_tables[tableIndex - 1].GetName(); } // snippet-end:[cpp.example_code.glue.GetTables] } @@ -472,49 +481,63 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa // 9. List the output data stored in the S3 bucket. { Aws::S3::S3Client s3Client; - Aws::S3::Model::ListObjectsRequest request; + Aws::S3::Model::ListObjectsV2Request request; request.SetBucket(bucketName); request.SetPrefix(OUTPUT_FILE_PREFIX); - Aws::S3::Model::ListObjectsOutcome outcome = s3Client.ListObjects(request); - - if (outcome.IsSuccess()) { - const std::vector &objects = outcome.GetResult().GetContents(); - std::cout << "Data from your job is in " << objects.size() << - " files in the S3 bucket, " << bucketName << "." << std::endl; - - for (size_t i = 0; i < objects.size(); ++i) { - std::cout << " " << i + 1 << ". " << objects[i].GetKey() - << std::endl; + Aws::String continuationToken; // Used for pagination. + std::vector allObjects; + do { + if (!continuationToken.empty()) { + request.SetContinuationToken(continuationToken); } - - int objectIndex = askQuestionForIntRange( - std::string( - "Enter the number of a block to download it and see the first ") + - std::to_string(LINES_OF_RUN_FILE_TO_DISPLAY) + - " lines of JSON output in the block: ", 1, - static_cast(objects.size())); - - Aws::String objectKey = objects[objectIndex - 1].GetKey(); - - std::stringstream stringStream; - if (getObjectFromBucket(bucketName, objectKey, stringStream, - clientConfig)) { - for (int i = 0; i < LINES_OF_RUN_FILE_TO_DISPLAY && stringStream; ++i) { - std::string line; - std::getline(stringStream, line); - std::cout << " " << line << std::endl; - } + Aws::S3::Model::ListObjectsV2Outcome outcome = s3Client.ListObjectsV2( + request); + + if (outcome.IsSuccess()) { + const std::vector &objects = + outcome.GetResult().GetContents(); + allObjects.insert(allObjects.end(), objects.begin(), objects.end()); + continuationToken = outcome.GetResult().GetNextContinuationToken(); } else { - deleteAssets(CRAWLER_NAME, CRAWLER_DATABASE_NAME, JOB_NAME, bucketName, - clientConfig); - return false; + std::cerr << "Error listing objects. " + << outcome.GetError().GetMessage() + << std::endl; + break; + } + } while (!continuationToken.empty()); + + std::cout << "Data from your job is in " << allObjects.size() << + " files in the S3 bucket, " << bucketName << "." << std::endl; + + for (size_t i = 0; i < allObjects.size(); ++i) { + std::cout << " " << i + 1 << ". " << allObjects[i].GetKey() + << std::endl; + } + + int objectIndex = askQuestionForIntRange( + std::string( + "Enter the number of a block to download it and see the first ") + + std::to_string(LINES_OF_RUN_FILE_TO_DISPLAY) + + " lines of JSON output in the block: ", 1, + static_cast(allObjects.size())); + + Aws::String objectKey = allObjects[objectIndex - 1].GetKey(); + + std::stringstream stringStream; + if (getObjectFromBucket(bucketName, objectKey, stringStream, + clientConfig)) { + for (int i = 0; i < LINES_OF_RUN_FILE_TO_DISPLAY && stringStream; ++i) { + std::string line; + std::getline(stringStream, line); + std::cout << " " << line << std::endl; } } else { - std::cerr << "Error listing objects. " << outcome.GetError().GetMessage() - << std::endl; + deleteAssets(CRAWLER_NAME, CRAWLER_DATABASE_NAME, JOB_NAME, bucketName, + clientConfig); + return false; } } @@ -523,30 +546,41 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa { // snippet-start:[cpp.example_code.glue.ListJobs] Aws::Glue::Model::ListJobsRequest listJobsRequest; - Aws::Glue::Model::ListJobsOutcome listRunsOutcome = client.ListJobs( - listJobsRequest); - if (listRunsOutcome.IsSuccess()) { - const std::vector &jobNames = listRunsOutcome.GetResult().GetJobNames(); - std::cout << "Your account has " << jobNames.size() << " jobs." - << std::endl; - for (size_t i = 0; i < jobNames.size(); ++i) { - std::cout << " " << i + 1 << ". " << jobNames[i] << std::endl; + Aws::String nextToken; + std::vector allJobNames; + + do { + if (!nextToken.empty()) { + listJobsRequest.SetNextToken(nextToken); } - int jobIndex = askQuestionForIntRange( - Aws::String("Enter a number between 1 and ") + - std::to_string(jobNames.size()) + - " to see the list of runs for a job: ", - 1, static_cast(jobNames.size())); + Aws::Glue::Model::ListJobsOutcome listRunsOutcome = client.ListJobs( + listJobsRequest); - jobName = jobNames[jobIndex - 1]; - } - else { - std::cerr << "Error listing jobs. " - << listRunsOutcome.GetError().GetMessage() - << std::endl; - } + if (listRunsOutcome.IsSuccess()) { + const std::vector &jobNames = listRunsOutcome.GetResult().GetJobNames(); + allJobNames.insert(allJobNames.end(), jobNames.begin(), jobNames.end()); + nextToken = listRunsOutcome.GetResult().GetNextToken(); + } + else { + std::cerr << "Error listing jobs. " + << listRunsOutcome.GetError().GetMessage() + << std::endl; + } + } while (!nextToken.empty()); // snippet-end:[cpp.example_code.glue.ListJobs] + std::cout << "Your account has " << allJobNames.size() << " jobs." + << std::endl; + for (size_t i = 0; i < allJobNames.size(); ++i) { + std::cout << " " << i + 1 << ". " << allJobNames[i] << std::endl; + } + int jobIndex = askQuestionForIntRange( + Aws::String("Enter a number between 1 and ") + + std::to_string(allJobNames.size()) + + " to see the list of runs for a job: ", + 1, static_cast(allJobNames.size())); + + jobName = allJobNames[jobIndex - 1]; } // 11. Get the job runs for a job. @@ -556,33 +590,45 @@ bool AwsDoc::Glue::runGettingStartedWithGlueScenario(const Aws::String &bucketNa Aws::Glue::Model::GetJobRunsRequest getJobRunsRequest; getJobRunsRequest.SetJobName(jobName); - Aws::Glue::Model::GetJobRunsOutcome jobRunsOutcome = client.GetJobRuns( - getJobRunsRequest); + Aws::String nextToken; // Used for pagination. + std::vector allJobRuns; + do { + if (!nextToken.empty()) { + getJobRunsRequest.SetNextToken(nextToken); + } + Aws::Glue::Model::GetJobRunsOutcome jobRunsOutcome = client.GetJobRuns( + getJobRunsRequest); - if (jobRunsOutcome.IsSuccess()) { - std::vector jobRuns = jobRunsOutcome.GetResult().GetJobRuns(); - std::cout << "There are " << jobRuns.size() << " runs in the job '" - << - jobName << "'." << std::endl; + if (jobRunsOutcome.IsSuccess()) { + const std::vector &jobRuns = jobRunsOutcome.GetResult().GetJobRuns(); + allJobRuns.insert(allJobRuns.end(), jobRuns.begin(), jobRuns.end()); - for (size_t i = 0; i < jobRuns.size(); ++i) { - std::cout << " " << i + 1 << ". " << jobRuns[i].GetJobName() + nextToken = jobRunsOutcome.GetResult().GetNextToken(); + } + else { + std::cerr << "Error getting job runs. " + << jobRunsOutcome.GetError().GetMessage() << std::endl; + break; } + } while (!nextToken.empty()); +// snippet-end:[cpp.example_code.glue.GetJobRuns] - int runIndex = askQuestionForIntRange( - Aws::String("Enter a number between 1 and ") + - std::to_string(jobRuns.size()) + - " to see details for a run: ", - 1, static_cast(jobRuns.size())); - jobRunID = jobRuns[runIndex - 1].GetId(); - } - else { - std::cerr << "Error getting job runs. " - << jobRunsOutcome.GetError().GetMessage() + std::cout << "There are " << allJobRuns.size() << " runs in the job '" + << + jobName << "'." << std::endl; + + for (size_t i = 0; i < allJobRuns.size(); ++i) { + std::cout << " " << i + 1 << ". " << allJobRuns[i].GetJobName() << std::endl; } -// snippet-end:[cpp.example_code.glue.GetJobRuns] + + int runIndex = askQuestionForIntRange( + Aws::String("Enter a number between 1 and ") + + std::to_string(allJobRuns.size()) + + " to see details for a run: ", + 1, static_cast(allJobRuns.size())); + jobRunID = allJobRuns[runIndex - 1].GetId(); } // 12. Get a single job run. @@ -751,50 +797,64 @@ AwsDoc::Glue::uploadFile(const Aws::String &bucketName, bool AwsDoc::Glue::deleteAllObjectsInS3Bucket(const Aws::String &bucketName, const Aws::Client::ClientConfiguration &clientConfig) { Aws::S3::S3Client client(clientConfig); - Aws::S3::Model::ListObjectsRequest listObjectsRequest; + Aws::S3::Model::ListObjectsV2Request listObjectsRequest; listObjectsRequest.SetBucket(bucketName); + Aws::String continuationToken; // Used for pagination. + bool result = true; + do { + if (!continuationToken.empty()) { + listObjectsRequest.SetContinuationToken(continuationToken); + } - Aws::S3::Model::ListObjectsOutcome listObjectsOutcome = client.ListObjects( - listObjectsRequest); + Aws::S3::Model::ListObjectsV2Outcome listObjectsOutcome = client.ListObjectsV2( + listObjectsRequest); - bool result = false; - if (listObjectsOutcome.IsSuccess()) { - const std::vector &objects = listObjectsOutcome.GetResult().GetContents(); - if (!objects.empty()) { - Aws::S3::Model::DeleteObjectsRequest deleteObjectsRequest; - deleteObjectsRequest.SetBucket(bucketName); + if (listObjectsOutcome.IsSuccess()) { + const std::vector &objects = listObjectsOutcome.GetResult().GetContents(); + if (!objects.empty()) { + Aws::S3::Model::DeleteObjectsRequest deleteObjectsRequest; + deleteObjectsRequest.SetBucket(bucketName); - std::vector objectIdentifiers; - for (const Aws::S3::Model::Object &object: objects) { - objectIdentifiers.push_back( - Aws::S3::Model::ObjectIdentifier().WithKey(object.GetKey())); - } - Aws::S3::Model::Delete objectsDelete; - objectsDelete.SetObjects(objectIdentifiers); - objectsDelete.SetQuiet(true); - deleteObjectsRequest.SetDelete(objectsDelete); - - Aws::S3::Model::DeleteObjectsOutcome deleteObjectsOutcome = - client.DeleteObjects(deleteObjectsRequest); + std::vector objectIdentifiers; + for (const Aws::S3::Model::Object &object: objects) { + objectIdentifiers.push_back( + Aws::S3::Model::ObjectIdentifier().WithKey( + object.GetKey())); + } + Aws::S3::Model::Delete objectsDelete; + objectsDelete.SetObjects(objectIdentifiers); + objectsDelete.SetQuiet(true); + deleteObjectsRequest.SetDelete(objectsDelete); + + Aws::S3::Model::DeleteObjectsOutcome deleteObjectsOutcome = + client.DeleteObjects(deleteObjectsRequest); + + if (!deleteObjectsOutcome.IsSuccess()) { + std::cerr << "Error deleting objects. " << + deleteObjectsOutcome.GetError().GetMessage() << std::endl; + result = false; + break; + } + else { + std::cout << "Successfully deleted the objects." << std::endl; - if (!deleteObjectsOutcome.IsSuccess()) { - std::cerr << "Error deleting objects. " << - deleteObjectsOutcome.GetError().GetMessage() << std::endl; + } } else { - std::cout << "Successfully deleted the objects." << std::endl; - result = true; + std::cout << "No objects to delete in '" << bucketName << "'." + << std::endl; } + + continuationToken = listObjectsOutcome.GetResult().GetNextContinuationToken(); } else { - std::cout << "No objects to delete in '" << bucketName << "'." << std::endl; + std::cerr << "Error listing objects. " + << listObjectsOutcome.GetError().GetMessage() << std::endl; + result = false; + break; } - } - else { - std::cerr << "Error listing objects. " - << listObjectsOutcome.GetError().GetMessage() << std::endl; - } + } while (!continuationToken.empty()); return result; } @@ -841,7 +901,7 @@ bool AwsDoc::Glue::getObjectFromBucket(const Aws::String &bucketName, * * Prerequisites: An IAM role and an S3 bucket. * - * To create the resources required by this example, see the "Prerequisites" section in the README. + * To create the resources required by this example, see the "Get started with crawlers and jobs" section in the README. * * Usage: 'run_glue_getting_started_scenario all_detector_ids; + + do { + if (!next_token.empty()) { + ld_req.SetNextToken(next_token); + } + auto ld_out = gd.ListDetectors(ld_req); + + if (ld_out.IsSuccess()) { + const auto &detector_ids = ld_out.GetResult().GetDetectorIds(); + all_detector_ids.insert(all_detector_ids.end(), detector_ids.cbegin(), + detector_ids.cend()); + + next_token = ld_out.GetResult().GetNextToken(); + } + else { + std::cout << "Error listing the detectors " + << ld_out.GetError().GetMessage() + << std::endl; + break; + } + + } while (!next_token.empty()); + + std::cout << all_detector_ids.size() << " detector(s) listed." << std::endl; + for (auto detector_id: all_detector_ids) { + std::cout << " " << detector_id << std::endl; + } } - } - Aws::ShutdownAPI(options); - return 0; + Aws::ShutdownAPI(options); + return 0; } diff --git a/cpp/example_code/guardduty/list_findings_with_finding_criteria.cpp b/cpp/example_code/guardduty/list_findings_with_finding_criteria.cpp index e478020533f..6996f09b071 100644 --- a/cpp/example_code/guardduty/list_findings_with_finding_criteria.cpp +++ b/cpp/example_code/guardduty/list_findings_with_finding_criteria.cpp @@ -14,46 +14,63 @@ * List all GuardDuty Findings that match the specified FindingCriteria. */ -int main(int argc, char ** argv) -{ - if (argc != 2) - { - std::cout << "Usage: list_findings_with_finding_criteria " - "" << std::endl; - return 1; - } - - Aws::SDKOptions options; - Aws::InitAPI(options); - { - Aws::String detector_id(argv[1]); - Aws::String condition_val(argv[2]); - Aws::String criteria_val(argv[3]); - - Aws::GuardDuty::Model::Condition condition; - Aws::GuardDuty::GuardDutyClient gd; - Aws::GuardDuty::Model::ListFindingsRequest lffc_req; - Aws::GuardDuty::Model::FindingCriteria finding_criteria; - - condition.AddEquals(condition_val); - finding_criteria.AddCriterion(criteria_val, condition); - lffc_req.SetDetectorId(detector_id); - lffc_req.SetFindingCriteria(finding_criteria); - lffc_req.SetMaxResults(10); - - auto lffc_out = gd.ListFindings(lffc_req); - - if (lffc_out.IsSuccess()) - { - std::cout << "Successfully listing the findings"; +int main(int argc, char **argv) { + if (argc != 4) { + std::cout + << "Usage: list_findings_with_finding_criteria " + "" << std::endl; + return 1; } - else + + Aws::SDKOptions options; + options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace; + Aws::InitAPI(options); { - std::cout << "Error listing the findings " << lffc_out.GetError().GetMessage() - << std::endl; + Aws::String detector_id(argv[1]); + Aws::String condition_val(argv[2]); + Aws::String criteria_val(argv[3]); + + Aws::GuardDuty::Model::Condition condition; + Aws::GuardDuty::GuardDutyClient gd; + Aws::GuardDuty::Model::ListFindingsRequest lffc_req; + Aws::GuardDuty::Model::FindingCriteria finding_criteria; + + condition.AddEquals(condition_val); + finding_criteria.AddCriterion(criteria_val, condition); + lffc_req.SetDetectorId(detector_id); + lffc_req.SetFindingCriteria(finding_criteria); + lffc_req.SetMaxResults(10); + + Aws::String next_token; // Used for pagination. + Aws::Vector all_finding_ids; + + do { + if (!next_token.empty()) { + lffc_req.SetNextToken(next_token); + } + auto lffc_out = gd.ListFindings(lffc_req); + + if (lffc_out.IsSuccess()) { + auto &finding_ids = lffc_out.GetResult().GetFindingIds(); + all_finding_ids.insert(all_finding_ids.end(), finding_ids.begin(), + finding_ids.end()); + next_token = lffc_out.GetResult().GetNextToken(); + } + else { + std::cerr << "Error listing the findings " + << lffc_out.GetError().GetMessage() + << std::endl; + break; + } + + } while (!next_token.empty()); + + std::cout << all_finding_ids.size() << " finding(s) found." << std::endl; + for (auto const &id: all_finding_ids) { + std::cout << " " << id << std::endl; + } } - } - Aws::ShutdownAPI(options); - return 0; + Aws::ShutdownAPI(options); + return 0; } diff --git a/cpp/example_code/iot/hello_iot/hello_iot.cpp b/cpp/example_code/iot/hello_iot/hello_iot.cpp index b69625261d6..1f48d8a3f81 100644 --- a/cpp/example_code/iot/hello_iot/hello_iot.cpp +++ b/cpp/example_code/iot/hello_iot/hello_iot.cpp @@ -39,22 +39,35 @@ int main(int argc, char **argv) { Aws::IoT::IoTClient iotClient(clientConfig); // List the things in the current account. Aws::IoT::Model::ListThingsRequest listThingsRequest; - Aws::IoT::Model::ListThingsOutcome listThingsOutcome = iotClient.ListThings( - listThingsRequest); - if (listThingsOutcome.IsSuccess()) { - const Aws::Vector &things = listThingsOutcome.GetResult().GetThings(); - std::cout << things.size() << " thing(s) found." << std::endl; - for (auto const &thing: things) { - std::cout << thing.GetThingName() << std::endl; + + Aws::String nextToken; // Used for pagination. + Aws::Vector allThings; + + do { + if (!nextToken.empty()) { + listThingsRequest.SetNextToken(nextToken); } - } - else { - std::cerr << "List things failed" - << listThingsOutcome.GetError().GetMessage() << std::endl; + + Aws::IoT::Model::ListThingsOutcome listThingsOutcome = iotClient.ListThings( + listThingsRequest); + if (listThingsOutcome.IsSuccess()) { + const Aws::Vector &things = listThingsOutcome.GetResult().GetThings(); + allThings.insert(allThings.end(), things.begin(), things.end()); + nextToken = listThingsOutcome.GetResult().GetNextToken(); + } + else { + std::cerr << "List things failed" + << listThingsOutcome.GetError().GetMessage() << std::endl; + break; + } + } while (!nextToken.empty()); + + std::cout << allThings.size() << " thing(s) found." << std::endl; + for (auto const &thing: allThings) { + std::cout << thing.GetThingName() << std::endl; } } - Aws::ShutdownAPI(options); // Should only be called once. return 0; } diff --git a/cpp/example_code/neptune/describe_db_clusters.cpp b/cpp/example_code/neptune/describe_db_clusters.cpp index aac1e3330ec..9f460df872e 100644 --- a/cpp/example_code/neptune/describe_db_clusters.cpp +++ b/cpp/example_code/neptune/describe_db_clusters.cpp @@ -10,39 +10,54 @@ * Describes Neptune db cluster based on command line input */ -int main(int argc, char **argv) -{ - if (argc != 1) - { - std::cout << "Usage: describe_db_cluster"; - return 1; - } - Aws::SDKOptions options; - Aws::InitAPI(options); - { - Aws::Neptune::NeptuneClient neptune; - - Aws::Neptune::Model::DescribeDBClustersRequest ddbc_req; - - auto ddbc_out = neptune.DescribeDBClusters(ddbc_req); - - if (ddbc_out.IsSuccess()) - { - std::cout << "Successfully described db clusters request:"; - - for (auto val: ddbc_out.GetResult().GetDBClusters()) - { - std::cout << " " << val.GetDBClusterIdentifier() << std::endl; - } +int main(int argc, char **argv) { + if (argc != 1) { + std::cout << "Usage: describe_db_cluster"; + return 1; } - - else + Aws::SDKOptions options; + Aws::InitAPI(options); { - std::cout << "Error describing neptune db clusters " << ddbc_out.GetError().GetMessage() - << std::endl; + Aws::Neptune::NeptuneClient neptune; + + Aws::Neptune::Model::DescribeDBClustersRequest ddbc_req; + + Aws::String marker; // Used for pagination. + Aws::Vector all_clusters; + + do { + if (!marker.empty()) { + ddbc_req.SetMarker(marker); + } + + auto ddbc_out = neptune.DescribeDBClusters(ddbc_req); + + if (ddbc_out.IsSuccess()) { + auto &db_clusters = ddbc_out.GetResult().GetDBClusters(); + all_clusters.insert(all_clusters.end(), db_clusters.begin(), + db_clusters.end()); + marker = ddbc_out.GetResult().GetMarker(); + } + + else { + std::cerr << "Error describing neptune db clusters " + << ddbc_out.GetError().GetMessage() + << std::endl; + break; + } + + } while (!marker.empty()); + + std::cout << all_clusters.size() << " Neptune db cluster(s) found." + << std::endl; + for (auto cluster: all_clusters) { + std::cout << "Neptune db cluster id: " << cluster.GetDBClusterIdentifier() + << std::endl; + std::cout << "Neptune db cluster status: " << cluster.GetStatus() + << std::endl; + } } - } - Aws::ShutdownAPI(options); - return 0; + Aws::ShutdownAPI(options); + return 0; } diff --git a/cpp/example_code/rds/README.md b/cpp/example_code/rds/README.md index d06ada28cb2..42627a8ade3 100644 --- a/cpp/example_code/rds/README.md +++ b/cpp/example_code/rds/README.md @@ -49,12 +49,12 @@ Code excerpts that show you how to call individual service functions. - [Create a DB instance](getting_started_with_db_instances.cpp#L481) (`CreateDBInstance`) - [Create a DB parameter group](getting_started_with_db_instances.cpp#L313) (`CreateDBParameterGroup`) - [Create a snapshot of a DB instance](getting_started_with_db_instances.cpp#L559) (`CreateDBSnapshot`) -- [Delete a DB instance](getting_started_with_db_instances.cpp#L857) (`DeleteDBInstance`) -- [Delete a DB parameter group](getting_started_with_db_instances.cpp#L911) (`DeleteDBParameterGroup`) -- [Describe DB instances](getting_started_with_db_instances.cpp#L736) (`DescribeDBInstances`) +- [Delete a DB instance](getting_started_with_db_instances.cpp#L873) (`DeleteDBInstance`) +- [Delete a DB parameter group](getting_started_with_db_instances.cpp#L927) (`DeleteDBParameterGroup`) +- [Describe DB instances](getting_started_with_db_instances.cpp#L752) (`DescribeDBInstances`) - [Describe DB parameter groups](getting_started_with_db_instances.cpp#L275) (`DescribeDBParameterGroups`) - [Describe database engine versions](getting_started_with_db_instances.cpp#L698) (`DescribeDBEngineVersions`) -- [Describe options for DB instances](getting_started_with_db_instances.cpp#L776) (`DescribeOrderableDBInstanceOptions`) +- [Describe options for DB instances](getting_started_with_db_instances.cpp#L792) (`DescribeOrderableDBInstanceOptions`) - [Describe parameters in a DB parameter group](getting_started_with_db_instances.cpp#L639) (`DescribeDBParameters`) - [Describe snapshots of DB instances](getting_started_with_db_instances.cpp#L597) (`DescribeDBSnapshots`) - [Update parameters in a DB parameter group](getting_started_with_db_instances.cpp#L382) (`ModifyDBParameterGroup`) diff --git a/cpp/example_code/rds/getting_started_with_db_instances.cpp b/cpp/example_code/rds/getting_started_with_db_instances.cpp index 06ca3f1674d..0fc8c1049ae 100644 --- a/cpp/example_code/rds/getting_started_with_db_instances.cpp +++ b/cpp/example_code/rds/getting_started_with_db_instances.cpp @@ -717,19 +717,35 @@ bool AwsDoc::RDS::getDBEngineVersions(const Aws::String &engineName, request.SetDBParameterGroupFamily(parameterGroupFamily); } - Aws::RDS::Model::DescribeDBEngineVersionsOutcome outcome = - client.DescribeDBEngineVersions(request); + engineVersionsResult.clear(); + Aws::String marker; // Used for pagination. - if (outcome.IsSuccess()) { - engineVersionsResult = outcome.GetResult().GetDBEngineVersions(); - } - else { - std::cerr << "Error with RDS::DescribeDBEngineVersionsRequest. " - << outcome.GetError().GetMessage() - << std::endl; - } + do { + if (!marker.empty()) { + request.SetMarker(marker); + } - return outcome.IsSuccess(); + + Aws::RDS::Model::DescribeDBEngineVersionsOutcome outcome = + client.DescribeDBEngineVersions(request); + + if (outcome.IsSuccess()) { + auto &engineVersions = outcome.GetResult().GetDBEngineVersions(); + engineVersionsResult.insert(engineVersionsResult.end(), engineVersions.begin(), + engineVersions.end()); + marker = outcome.GetResult().GetMarker(); + } + else { + std::cerr << "Error with RDS::DescribeDBEngineVersionsRequest. " + << outcome.GetError().GetMessage() + << std::endl; + return false; + } + + } while (!marker.empty()); + + + return true; } // snippet-end:[cpp.example_code.rds.DescribeDBEngineVersions] diff --git a/cpp/example_code/s3/list_objects.cpp b/cpp/example_code/s3/list_objects.cpp index fb1b8208805..540f74d096e 100644 --- a/cpp/example_code/s3/list_objects.cpp +++ b/cpp/example_code/s3/list_objects.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -33,25 +33,40 @@ bool AwsDoc::S3::ListObjects(const Aws::String &bucketName, const Aws::Client::ClientConfiguration &clientConfig) { Aws::S3::S3Client s3_client(clientConfig); - Aws::S3::Model::ListObjectsRequest request; + Aws::S3::Model::ListObjectsV2Request request; request.WithBucket(bucketName); - auto outcome = s3_client.ListObjects(request); + Aws::String continuationToken; // Used for pagination. + Aws::Vector allObjects; - if (!outcome.IsSuccess()) { - std::cerr << "Error: ListObjects: " << - outcome.GetError().GetMessage() << std::endl; - } - else { - Aws::Vector objects = - outcome.GetResult().GetContents(); + do { + if (!continuationToken.empty()) { + request.SetContinuationToken(continuationToken); + } + + auto outcome = s3_client.ListObjectsV2(request); + + if (!outcome.IsSuccess()) { + std::cerr << "Error: ListObjects: " << + outcome.GetError().GetMessage() << std::endl; + return false; + } + else { + Aws::Vector objects = + outcome.GetResult().GetContents(); - for (Aws::S3::Model::Object &object: objects) { - std::cout << object.GetKey() << std::endl; + allObjects.insert(allObjects.end(), objects.begin(), objects.end()); + continuationToken = outcome.GetResult().GetNextContinuationToken(); } + } while (!continuationToken.empty()); + + std::cout << allObjects.size() << " object(s) found:" << std::endl; + + for (const auto &object: allObjects) { + std::cout << " " << object.GetKey() << std::endl; } - return outcome.IsSuccess(); + return true; } // snippet-end:[s3.cpp.list_objects.code] @@ -68,8 +83,7 @@ bool AwsDoc::S3::ListObjects(const Aws::String &bucketName, #ifndef TESTING_BUILD -int main() -{ +int main() { Aws::SDKOptions options; Aws::InitAPI(options); { @@ -82,7 +96,7 @@ int main() // Optional: Set to the AWS Region in which the bucket was created (overrides config file). // clientConfig.region = "us-east-1"; AwsDoc::S3::ListObjects(bucket_name, clientConfig); - } + } Aws::ShutdownAPI(options); return 0; diff --git a/cpp/example_code/s3/list_objects_with_aws_global_region.cpp b/cpp/example_code/s3/list_objects_with_aws_global_region.cpp index 39d9f22cf18..0f02f68c359 100644 --- a/cpp/example_code/s3/list_objects_with_aws_global_region.cpp +++ b/cpp/example_code/s3/list_objects_with_aws_global_region.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include "awsdoc/s3/s3_examples.h" @@ -51,7 +51,8 @@ static Aws::String CreateOneBucket(const Aws::S3::S3Client &s3Client) { Aws::S3::Model::CreateBucketRequest createBucketRequest; createBucketRequest.SetBucket(bucketName); Aws::S3::Model::CreateBucketConfiguration createBucketConfiguration; - createBucketConfiguration.SetLocationConstraint(Aws::S3::Model::BucketLocationConstraint::us_west_2); + createBucketConfiguration.SetLocationConstraint( + Aws::S3::Model::BucketLocationConstraint::us_west_2); createBucketRequest.SetCreateBucketConfiguration(createBucketConfiguration); auto createBucketOutcome = s3Client.CreateBucket(createBucketRequest); @@ -71,7 +72,8 @@ static Aws::String CreateOneBucket(const Aws::S3::S3Client &s3Client) { while (timeoutCount++ < MAX_TIMEOUT_RETRIES) { Aws::S3::Model::HeadBucketRequest headBucketRequest; headBucketRequest.SetBucket(bucketName); - Aws::S3::Model::HeadBucketOutcome headBucketOutcome = s3Client.HeadBucket(headBucketRequest); + Aws::S3::Model::HeadBucketOutcome headBucketOutcome = s3Client.HeadBucket( + headBucketRequest); if (headBucketOutcome.IsSuccess()) { break; } @@ -89,25 +91,42 @@ static Aws::String CreateOneBucket(const Aws::S3::S3Client &s3Client) { \param bucketName An S3 bucket name. */ -static bool ListTheObjects(const Aws::S3::S3Client &s3Client, const Aws::String &bucketName) { +static bool +ListTheObjects(const Aws::S3::S3Client &s3Client, const Aws::String &bucketName) { // An S3 API client set to the aws-global AWS Region should be able to get // access to a bucket in any AWS Region. - Aws::S3::Model::ListObjectsRequest listObjectsRequest; + Aws::S3::Model::ListObjectsV2Request listObjectsRequest; listObjectsRequest.SetBucket(bucketName); - auto listObjectOutcome = s3Client.ListObjects(listObjectsRequest); - if (listObjectOutcome.IsSuccess()) { - std::cout << "Success. Number of objects in the bucket named '" << - bucketName << "' is " << - listObjectOutcome.GetResult().GetContents().size() << "." << - std::endl; - } - else { - std::cerr << "Error. Could not count the objects in the bucket: " << - listObjectOutcome.GetError() << std::endl; - } + Aws::String continuationToken; // Used for pagination. + Aws::Vector objects; + + do { + if (!continuationToken.empty()) { + listObjectsRequest.SetContinuationToken(continuationToken); + } + + // List the objects in the bucket. + auto listObjectOutcome = s3Client.ListObjectsV2(listObjectsRequest); + + if (listObjectOutcome.IsSuccess()) { + auto &contents = listObjectOutcome.GetResult().GetContents(); - return listObjectOutcome.IsSuccess(); + objects.insert(objects.end(), contents.begin(), contents.end()); + continuationToken = listObjectOutcome.GetResult().GetNextContinuationToken(); + } + else { + std::cerr << "Error. Could not count the objects in the bucket: " << + listObjectOutcome.GetError() << std::endl; + return false; + } + + } while (!continuationToken.empty()); + + std::cout << "Success. Found " << objects.size() << " objects in the bucket." << + std::endl; + + return true; } //! Helper routine to delete a bucket. /*! @@ -141,7 +160,8 @@ bool DeleteABucket(const Aws::S3::S3Client &s3Client, const Aws::String &bucketN \param clientConfig Aws client configuration. */ -bool AwsDoc::S3::ListObjectsWithAWSGlobalRegion(const Aws::Client::ClientConfiguration &clientConfig) { +bool AwsDoc::S3::ListObjectsWithAWSGlobalRegion( + const Aws::Client::ClientConfiguration &clientConfig) { Aws::Client::ClientConfiguration config(clientConfig); config.region = Aws::Region::AWS_GLOBAL; @@ -173,7 +193,6 @@ bool AwsDoc::S3::ListObjectsWithAWSGlobalRegion(const Aws::Client::ClientConfigu int main() { Aws::SDKOptions options; - options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace; InitAPI(options); { diff --git a/cpp/example_code/s3/s3_getting_started_scenario.cpp b/cpp/example_code/s3/s3_getting_started_scenario.cpp index eb775c0611b..ce247f02b35 100644 --- a/cpp/example_code/s3/s3_getting_started_scenario.cpp +++ b/cpp/example_code/s3/s3_getting_started_scenario.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -51,7 +51,8 @@ namespace AwsDoc { \param bucketName The S3 bucket's name. \param client An S3 client. */ - static bool DeleteBucket(const Aws::String &bucketName, Aws::S3::S3Client &client); + static bool + DeleteBucket(const Aws::String &bucketName, Aws::S3::S3Client &client); //! Delete an object in an S3 bucket. /*! \sa DeleteObjectFromBucket() @@ -60,7 +61,8 @@ namespace AwsDoc { \param client An S3 client. */ static bool - DeleteObjectFromBucket(const Aws::String &bucketName, const Aws::String &key, Aws::S3::S3Client &client); + DeleteObjectFromBucket(const Aws::String &bucketName, const Aws::String &key, + Aws::S3::S3Client &client); } } @@ -72,7 +74,8 @@ namespace AwsDoc { \param saveFilePath Path for saving a downloaded S3 object. \param clientConfig Aws client configuration. */ -bool AwsDoc::S3::S3_GettingStartedScenario(const Aws::String &uploadFilePath, const Aws::String &saveFilePath, +bool AwsDoc::S3::S3_GettingStartedScenario(const Aws::String &uploadFilePath, + const Aws::String &saveFilePath, const Aws::Client::ClientConfiguration &clientConfig) { Aws::S3::S3Client client(clientConfig); @@ -120,10 +123,12 @@ bool AwsDoc::S3::S3_GettingStartedScenario(const Aws::String &uploadFilePath, co std::shared_ptr input_data = Aws::MakeShared("SampleAllocationTag", uploadFilePath, - std::ios_base::in | std::ios_base::binary); + std::ios_base::in | + std::ios_base::binary); if (!input_data->is_open()) { - std::cerr << "Error: unable to open file, '" << uploadFilePath << "'." << std::endl; + std::cerr << "Error: unable to open file, '" << uploadFilePath << "'." + << std::endl; AwsDoc::S3::DeleteBucket(bucketName, client); return false; } @@ -141,7 +146,8 @@ bool AwsDoc::S3::S3_GettingStartedScenario(const Aws::String &uploadFilePath, co return false; } else { - std::cout << "Added the object with the key, '" << key << "', to the bucket, '" + std::cout << "Added the object with the key, '" << key + << "', to the bucket, '" << bucketName << "'." << std::endl; } } @@ -161,14 +167,17 @@ bool AwsDoc::S3::S3_GettingStartedScenario(const Aws::String &uploadFilePath, co err.GetExceptionName() << ": " << err.GetMessage() << std::endl; } else { - std::cout << "Downloaded the object with the key, '" << key << "', in the bucket, '" + std::cout << "Downloaded the object with the key, '" << key + << "', in the bucket, '" << bucketName << "'." << std::endl; Aws::IOStream &ioStream = outcome.GetResultWithOwnership(). GetBody(); - Aws::OFStream outStream(saveFilePath, std::ios_base::out | std::ios_base::binary); + Aws::OFStream outStream(saveFilePath, + std::ios_base::out | std::ios_base::binary); if (!outStream.is_open()) { - std::cout << "Error: unable to open file, '" << saveFilePath << "'." << std::endl; + std::cout << "Error: unable to open file, '" << saveFilePath << "'." + << std::endl; } else { outStream << ioStream.rdbuf(); @@ -193,31 +202,45 @@ bool AwsDoc::S3::S3_GettingStartedScenario(const Aws::String &uploadFilePath, co outcome.GetError().GetMessage() << std::endl; } else { - std::cout << "Copied the object with the key, '" << key << "', to the key, '" << copiedToKey + std::cout << "Copied the object with the key, '" << key + << "', to the key, '" << copiedToKey << ", in the bucket, '" << bucketName << "'." << std::endl; } } // 5. List objects in the bucket. { - Aws::S3::Model::ListObjectsRequest request; + Aws::S3::Model::ListObjectsV2Request request; request.WithBucket(bucketName); - Aws::S3::Model::ListObjectsOutcome outcome = client.ListObjects(request); - - if (!outcome.IsSuccess()) { - std::cerr << "Error: ListObjects: " << - outcome.GetError().GetMessage() << std::endl; - } - else { - Aws::Vector objects = - outcome.GetResult().GetContents(); + Aws::String continuationToken; + Aws::Vector allObjects; - std::cout << objects.size() << " objects in the bucket, '" << bucketName << "':" << std::endl; + do { + if (!continuationToken.empty()) { + request.SetContinuationToken(continuationToken); + } + Aws::S3::Model::ListObjectsV2Outcome outcome = client.ListObjectsV2( + request); - for (Aws::S3::Model::Object &object: objects) { - std::cout << " '" << object.GetKey() << "'" << std::endl; + if (!outcome.IsSuccess()) { + std::cerr << "Error: ListObjects: " << + outcome.GetError().GetMessage() << std::endl; + break; + } + else { + Aws::Vector objects = + outcome.GetResult().GetContents(); + allObjects.insert(allObjects.end(), objects.begin(), objects.end()); + continuationToken = outcome.GetResult().GetContinuationToken(); } + } while (!continuationToken.empty()); + + std::cout << allObjects.size() << " objects in the bucket, '" << bucketName + << "':" << std::endl; + + for (Aws::S3::Model::Object &object: allObjects) { + std::cout << " '" << object.GetKey() << "'" << std::endl; } } @@ -230,7 +253,8 @@ bool AwsDoc::S3::S3_GettingStartedScenario(const Aws::String &uploadFilePath, co return AwsDoc::S3::DeleteBucket(bucketName, client); } -bool AwsDoc::S3::DeleteObjectFromBucket(const Aws::String &bucketName, const Aws::String &key, +bool AwsDoc::S3::DeleteObjectFromBucket(const Aws::String &bucketName, + const Aws::String &key, Aws::S3::S3Client &client) { Aws::S3::Model::DeleteObjectRequest request; request.SetBucket(bucketName); @@ -244,14 +268,16 @@ bool AwsDoc::S3::DeleteObjectFromBucket(const Aws::String &bucketName, const Aws outcome.GetError().GetMessage() << std::endl; } else { - std::cout << "Deleted the object with the key, '" << key << "', from the bucket, '" + std::cout << "Deleted the object with the key, '" << key + << "', from the bucket, '" << bucketName << "'." << std::endl; } return outcome.IsSuccess(); } -bool AwsDoc::S3::DeleteBucket(const Aws::String &bucketName, Aws::S3::S3Client &client) { +bool +AwsDoc::S3::DeleteBucket(const Aws::String &bucketName, Aws::S3::S3Client &client) { Aws::S3::Model::DeleteBucketRequest request; request.SetBucket(bucketName); @@ -278,7 +304,8 @@ int main(int argc, const char *argv[]) { std::cout << "Usage:\n" << " \n\n" << "Where:\n" << - " uploadFilePath - The path where the file is located (for example, C:/AWS/book2.pdf).\n" << + " uploadFilePath - The path where the file is located (for example, C:/AWS/book2.pdf).\n" + << " saveFilePath - The path where the file is saved after it's " << "downloaded (for example, C:/AWS/book2.pdf). " << std::endl; return 1; diff --git a/cpp/example_code/ses/list_identities.cpp b/cpp/example_code/ses/list_identities.cpp index ddd765a4444..3fdba288450 100644 --- a/cpp/example_code/ses/list_identities.cpp +++ b/cpp/example_code/ses/list_identities.cpp @@ -75,44 +75,42 @@ bool AwsDoc::SES::listIdentities(Aws::SES::Model::IdentityType identityType, #ifndef TESTING_BUILD -int main(int argc, char **argv) -{ - Aws::SDKOptions options; +int main(int argc, char **argv) { + Aws::SDKOptions options; Aws::InitAPI(options); - { - Aws::SES::SESClient ses; + { + Aws::SES::Model::IdentityType identityType = Aws::SES::Model::IdentityType::NOT_SET; - Aws::SES::Model::ListIdentitiesRequest li_req; + if (argc == 2) { + std::string identityTypeAsString = argv[1]; + if (identityTypeAsString == "EmailAddress") { + identityType = Aws::SES::Model::IdentityType::EmailAddress; + } + else if (identityTypeAsString == "Domain") { + identityType = Aws::SES::Model::IdentityType::Domain; + } + else { + std::cout + << "Invalid identity type. Must be either 'EmailAddress' or 'Domain'" + << std::endl; + } + } - Aws::SES::Model::IdentityType identityType = Aws::SES::Model::IdentityType::NOT_SET; + Aws::Client::ClientConfiguration clientConfig; + // Optional: Set to the AWS Region (overrides config file). + // clientConfig.region = "us-east-1"; - if (argc == 2) { - std::string identityTypeAsString = argv[1]; - if (identityTypeAsString == "EmailAddress") { - identityType = Aws::SES::Model::IdentityType::EmailAddress; - } else if (identityTypeAsString == "Domain") { - identityType = Aws::SES::Model::IdentityType::Domain; - } else { - std::cout << "Invalid identity type. Must be either 'EmailAddress' or 'Domain'" << std::endl; + Aws::Vector identities; + if (AwsDoc::SES::listIdentities(identityType, identities, clientConfig)) { + std::cout << identities.size() << " identities retrieved." << std::endl; + for (auto &identity: identities) { + std::cout << " " << identity << std::endl; + } } } - Aws::Client::ClientConfiguration clientConfig; - // Optional: Set to the AWS Region (overrides config file). - // clientConfig.region = "us-east-1"; - - Aws::Vector identities; - if (AwsDoc::SES::listIdentities(identityType, identities, clientConfig)) - { - std::cout << identities.size() << " identities retrieved." << std::endl; - for (auto &identity : identities) { - std::cout << " " << identity << std::endl; - } - } - } - - Aws::ShutdownAPI(options); - return 0; + Aws::ShutdownAPI(options); + return 0; } #endif // TESTING_BUILD \ No newline at end of file diff --git a/cpp/example_code/sqs/list_queues.cpp b/cpp/example_code/sqs/list_queues.cpp index 70a97d59463..16d2c2829fa 100644 --- a/cpp/example_code/sqs/list_queues.cpp +++ b/cpp/example_code/sqs/list_queues.cpp @@ -31,23 +31,40 @@ AwsDoc::SQS::listQueues(const Aws::Client::ClientConfiguration &clientConfigurat // snippet-start:[sqs.cpp.list_queues.code] Aws::SQS::SQSClient sqsClient(clientConfiguration); - Aws::SQS::Model::ListQueuesRequest lq_req; + Aws::SQS::Model::ListQueuesRequest listQueuesRequest; - const Aws::SQS::Model::ListQueuesOutcome outcome = sqsClient.ListQueues(lq_req); - if (outcome.IsSuccess()) { - std::cout << "Queue Urls:" << std::endl << std::endl; - const auto &queue_urls = outcome.GetResult().GetQueueUrls(); - for (const auto &iter: queue_urls) { - std::cout << " " << iter << std::endl; + Aws::String nextToken; // Used for pagination. + Aws::Vector allQueueUrls; + + do { + if (!nextToken.empty()) { + listQueuesRequest.SetNextToken(nextToken); } - } - else { - std::cerr << "Error listing queues: " << - outcome.GetError().GetMessage() << std::endl; + const Aws::SQS::Model::ListQueuesOutcome outcome = sqsClient.ListQueues( + listQueuesRequest); + if (outcome.IsSuccess()) { + const Aws::Vector &queueUrls = outcome.GetResult().GetQueueUrls(); + allQueueUrls.insert(allQueueUrls.end(), + queueUrls.begin(), + queueUrls.end()); + + nextToken = outcome.GetResult().GetNextToken(); + } + else { + std::cerr << "Error listing queues: " << + outcome.GetError().GetMessage() << std::endl; + return false; + } + + } while (!nextToken.empty()); + + std::cout << allQueueUrls.size() << " Amazon SQS queue(s) found." << std::endl; + for (const auto &iter: allQueueUrls) { + std::cout << " " << iter << std::endl; } // snippet-end:[sqs.cpp.list_queues.code] - return outcome.IsSuccess(); + return true; } // snippet-end:[cpp.example_code.sqs.ListQueues] diff --git a/cpp/example_code/storage_gateway/list_file_shares.cpp b/cpp/example_code/storage_gateway/list_file_shares.cpp index a2aa4184d34..224b15441d4 100644 --- a/cpp/example_code/storage_gateway/list_file_shares.cpp +++ b/cpp/example_code/storage_gateway/list_file_shares.cpp @@ -8,42 +8,53 @@ #include #include -int main(int argc, char ** argv) -{ - if (argc != 2) - { - std::cout << "Usage: list_file_shares " << std::endl; - return 1; - } +int main(int argc, char **argv) { + if (argc != 2) { + std::cout << "Usage: list_file_shares " << std::endl; + return 1; + } - Aws::SDKOptions options; - Aws::InitAPI(options); - { - Aws::String gateway_arn(argv[1]); + Aws::SDKOptions options; + Aws::InitAPI(options); + { + Aws::String gateway_arn(argv[1]); - Aws::StorageGateway::StorageGatewayClient storagegateway; + Aws::StorageGateway::StorageGatewayClient storagegateway; - Aws::StorageGateway::Model::ListFileSharesRequest lfs_req; + Aws::StorageGateway::Model::ListFileSharesRequest lfs_req; - lfs_req.SetGatewayARN(gateway_arn); + lfs_req.SetGatewayARN(gateway_arn); - auto lfs_out = storagegateway.ListFileShares(lfs_req); + Aws::String marker; // Used for pagination. + Aws::Vector all_file_shares; - if (lfs_out.IsSuccess()) - { - std::cout << "Successfully listing file shares"; - for (auto fileShareInfo: lfs_out.GetResult().GetFileShareInfoList()) - { - std::cout << " " << fileShareInfo.GetFileShareId(); - } - } - else - { - std::cout << "Error listing File share" << lfs_out.GetError().GetMessage() - << std::endl; + do { + if (!marker.empty()) { + lfs_req.SetMarker(marker); + } + auto lfs_out = storagegateway.ListFileShares(lfs_req); + + if (lfs_out.IsSuccess()) { + auto &file_shares = lfs_out.GetResult().GetFileShareInfoList(); + all_file_shares.insert(all_file_shares.end(), file_shares.begin(), + file_shares.end()); + marker = lfs_out.GetResult().GetMarker(); + } + else { + std::cout << "Error listing File share" + << lfs_out.GetError().GetMessage() + << std::endl; + } + + } while (!marker.empty()); + + std::cout << all_file_shares.size() << " file share(s) found" << std::endl; + + for (auto const &file_share: all_file_shares) { + std::cout << " " << file_share.GetFileShareId() << std::endl; + } } - } - Aws::ShutdownAPI(options); - return 0; + Aws::ShutdownAPI(options); + return 0; } diff --git a/cpp/run_automated_tests.py b/cpp/run_automated_tests.py index 6ccdc83e65f..10748a7ac40 100644 --- a/cpp/run_automated_tests.py +++ b/cpp/run_automated_tests.py @@ -102,7 +102,7 @@ def build_tests(service="*"): return build_cmake_tests(cmake_files, executable_pattern) -def run_tests(run_files=[], type1=False, type2=False, type3=False): +def run_tests(run_files, type1=False, type2=False, type3=False): global build_sub_dir has_error = False filters = [] @@ -126,10 +126,10 @@ def run_tests(run_files=[], type1=False, type2=False, type3=False): os.chdir(run_dir) for run_file in run_files: # Run each filter separately or the no filter case. - for filter in filters: + for a_filter in filters: filter_arg = "" - if len(filter) > 0: - filter_arg = f"--gtest_filter={filter}" + if len(a_filter) > 0: + filter_arg = f"--gtest_filter={a_filter}" print(f"Calling '{run_file} {filter_arg}'.") proc = subprocess.Popen( [run_file, filter_arg], stdout=subprocess.PIPE, stderr=subprocess.STDOUT @@ -138,11 +138,11 @@ def run_tests(run_files=[], type1=False, type2=False, type3=False): line = line.decode("utf-8") sys.stdout.write(line) - match = re.search("\[ PASSED \] (\d+) test", line) + match = re.search("\[ {2}PASSED {2}\] (\d+) test", line) if match is not None: passed_tests = passed_tests + int(match.group(1)) continue - match = re.search("\[ FAILED \] (\d+) test", line) + match = re.search("\[ {2}FAILED {2}\] (\d+) test", line) if match is not None: failed_tests = failed_tests + int(match.group(1)) continue @@ -190,8 +190,8 @@ def test_hello_service(service="*"): path_split = os.path.splitext(run_file) if (path_split[1] == ".exe") or (path_split[1] == ""): print(f"Calling '{run_file}'.") - completedProcess = subprocess.run([run_file], stdout=subprocess.DEVNULL) - if completedProcess.returncode != 0: + completed_process = subprocess.run([run_file], stdout=subprocess.DEVNULL) + if completed_process.returncode != 0: print(f"Error with {run_file}") has_error = True failed_count = failed_count + 1 @@ -230,13 +230,13 @@ def main(argv): print(" 3. Does not require credentials.") print(" s. Test this service (regular expression).") sys.exit() - elif opt in ("-1"): + elif opt in "-1": type1 = True - elif opt in ("-2"): + elif opt in "-2": type2 = True - elif opt in ("-3"): + elif opt in "-3": type3 = True - elif opt in ("-s"): + elif opt in "-s": service = arg start_time = datetime.datetime.now()