// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 #include #include #include #include #include "cloudtrail_samples.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 * * For information on the structure of the code examples and how to build and run the examples, see * https://docs.aws.amazon.com/sdk-for-cpp/v1/developer-guide/getting-started-code-examples.html. * **/ // snippet-start:[cpp.example_code.cloudtrail.DescribeTrails] // Routine which describes the AWS CloudTrail trails in an account. /*! \param clientConfig: Aws client configuration. \return bool: Function succeeded. */ bool AwsDoc::CloudTrail::describeTrails( const Aws::Client::ClientConfiguration &clientConfig) { Aws::CloudTrail::CloudTrailClient cloudTrailClient(clientConfig); Aws::CloudTrail::Model::DescribeTrailsRequest request; auto outcome = cloudTrailClient.DescribeTrails(request); if (outcome.IsSuccess()) { const Aws::Vector &trails = outcome.GetResult().GetTrailList(); std::cout << trails.size() << " trail(s) found." << std::endl; for (const Aws::CloudTrail::Model::Trail &trail: trails) { std::cout << trail.GetName() << std::endl; } } else { std::cerr << "Failed to describe trails." << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); } // snippet-end:[cpp.example_code.cloudtrail.DescribeTrails] /* * * main function * * Usage: 'run_describe_trails' * */ #ifndef TESTING_BUILD int main(int argc, char **argv) { Aws::SDKOptions options; Aws::InitAPI(options); { Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; AwsDoc::CloudTrail::describeTrails(clientConfig); } Aws::ShutdownAPI(options); return 0; } #endif // TESTING_BUILD