// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 #include #include #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.CreateTrail] // Routine which creates an AWS CloudTrail trail. /*! \param trailName: The name of the CloudTrail trail. \param bucketName: The Amazon S3 bucket designate for publishing logs. \param clientConfig: Aws client configuration. \return bool: Function succeeded. */ bool AwsDoc::CloudTrail::createTrail(const Aws::String trailName, const Aws::String bucketName, const Aws::Client::ClientConfiguration &clientConfig) { Aws::CloudTrail::CloudTrailClient trailClient(clientConfig); Aws::CloudTrail::Model::CreateTrailRequest request; request.SetName(trailName); request.SetS3BucketName(bucketName); Aws::CloudTrail::Model::CreateTrailOutcome outcome = trailClient.CreateTrail( request); if (outcome.IsSuccess()) { std::cout << "Successfully created trail " << trailName << std::endl; } else { std::cerr << "Failed to create trail " << trailName << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); } // snippet-end:[cpp.example_code.cloudtrail.CreateTrail] /* * * main function * * Usage: 'run_create_trail ' * * Prerequisites: An existing Amazon S3 bucket. * */ #ifndef TESTING_BUILD int main(int argc, char **argv) { if (argc != 3) { std::cout << "Usage: 'run_create_trail '"; return 1; } Aws::SDKOptions options; Aws::InitAPI(options); { Aws::String trailName(argv[1]); Aws::String bucketName(argv[2]); Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; AwsDoc::CloudTrail::createTrail(trailName, bucketName, clientConfig); } Aws::ShutdownAPI(options); return 0; } #endif // TESTING_BUILD