SIGN IN SIGN UP

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.

0 0 14 Java
2021-11-15 13:15:43 +00:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#include <aws/core/Aws.h>
#include <aws/cloudtrail/CloudTrailClient.h>
#include <aws/cloudtrail/model/DescribeTrailsRequest.h>
#include <iostream>
#include "cloudtrail_samples.h"
2021-11-15 13:15:43 +00:00
/**
* 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.
*
**/
2021-11-15 13:15:43 +00:00
// 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.
*/
2021-11-15 13:15:43 +00:00
bool AwsDoc::CloudTrail::describeTrails(
const Aws::Client::ClientConfiguration &clientConfig) {
Aws::CloudTrail::CloudTrailClient cloudTrailClient(clientConfig);
Aws::CloudTrail::Model::DescribeTrailsRequest request;
2021-11-15 13:15:43 +00:00
auto outcome = cloudTrailClient.DescribeTrails(request);
if (outcome.IsSuccess()) {
const Aws::Vector<Aws::CloudTrail::Model::Trail> &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]
2021-11-15 13:15:43 +00:00
/*
*
* main function
*
* Usage: 'run_describe_trails'
*
*/
2021-11-15 13:15:43 +00:00
#ifndef TESTING_BUILD
2021-11-15 13:15:43 +00:00
int main(int argc, char **argv) {
Aws::SDKOptions options;
Aws::InitAPI(options);
2021-11-15 13:15:43 +00:00
{
Aws::Client::ClientConfiguration clientConfig;
// Optional: Set to the AWS Region (overrides config file).
// clientConfig.region = "us-east-1";
AwsDoc::CloudTrail::describeTrails(clientConfig);
2021-11-15 13:15:43 +00:00
}
Aws::ShutdownAPI(options);
return 0;
2021-11-15 13:15:43 +00:00
}
#endif // TESTING_BUILD