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 17 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/core/utils/Outcome.h>
#include <aws/cloudtrail/CloudTrailClient.h>
#include <aws/cloudtrail/model/CreateTrailRequest.h>
#include <aws/cloudtrail/model/CreateTrailResult.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.
*
**/
// 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;
2021-11-15 13:15:43 +00:00
}
else {
std::cerr << "Failed to create trail " << trailName <<
": " << outcome.GetError().GetMessage() << std::endl;
}
return outcome.IsSuccess();
}
// snippet-end:[cpp.example_code.cloudtrail.CreateTrail]
2021-11-15 13:15:43 +00:00
/*
*
* main function
*
* Usage: 'run_create_trail <trail_name> <bucket_name>'
*
* Prerequisites: An existing Amazon S3 bucket.
*
*/
#ifndef TESTING_BUILD
int main(int argc, char **argv) {
if (argc != 3) {
std::cout << "Usage: 'run_create_trail <trail_name> <bucket_name>'";
return 1;
}
Aws::SDKOptions options;
Aws::InitAPI(options);
2021-11-15 13:15:43 +00:00
{
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);
2021-11-15 13:15:43 +00:00
}
Aws::ShutdownAPI(options);
return 0;
2021-11-15 13:15:43 +00:00
}
#endif // TESTING_BUILD