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/DeleteTrailRequest.h>
# include <aws/cloudtrail/model/DeleteTrailResult.h>
# include <iostream>
2024-04-29 13:26:35 -04:00
# include "cloudtrail_samples.h"
2021-11-15 13:15:43 +00:00
/**
2024-04-29 13:26:35 -04: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
2024-04-29 13:26:35 -04:00
// snippet-start:[cpp.example_code.cloudtrail.DeleteTrail]
// Routine which deletes an AWS CloudTrail trail.
/*!
\param trailName: The name of the CloudTrail trail.
\param clientConfig: Aws client configuration.
\return bool: Function succeeded.
*/
bool AwsDoc : : CloudTrail : : deleteTrail ( const Aws : : String trailName ,
const Aws : : Client : : ClientConfiguration & clientConfig ) {
Aws : : CloudTrail : : CloudTrailClient trailClient ( clientConfig ) ;
2021-11-15 13:15:43 +00:00
2024-04-29 13:26:35 -04:00
Aws : : CloudTrail : : Model : : DeleteTrailRequest request ;
request . SetName ( trailName ) ;
2021-11-15 13:15:43 +00:00
2024-04-29 13:26:35 -04:00
auto outcome = trailClient . DeleteTrail ( request ) ;
if ( outcome . IsSuccess ( ) ) {
std : : cout < < " Successfully deleted trail " < < trailName < < std : : endl ;
}
else {
std : : cerr < < " Error deleting trail " < < trailName < < " " < <
outcome . GetError ( ) . GetMessage ( ) < < std : : endl ;
2021-11-15 13:15:43 +00:00
}
2024-04-29 13:26:35 -04:00
return outcome . IsSuccess ( ) ;
}
// snippet-end:[cpp.example_code.cloudtrail.DeleteTrail]
/*
*
* main function
*
* Usage: 'run_delete_trail <trail_name>'
*
* Prerequisites: An existing CloudTrail trail.
*
*/
# ifndef TESTING_BUILD
int main ( int argc , char * * argv ) {
if ( argc ! = 2 ) {
std : : cout < < " Usage: 'run_delete_trail <trail_name>' " ;
return 1 ;
}
Aws : : SDKOptions options ;
Aws : : InitAPI ( options ) ;
2021-11-15 13:15:43 +00:00
{
2024-04-29 13:26:35 -04:00
Aws : : String trailName ( argv [ 1 ] ) ;
Aws : : Client : : ClientConfiguration clientConfig ;
// Optional: Set to the AWS Region (overrides config file).
// clientConfig.region = "us-east-1";
AwsDoc : : CloudTrail : : deleteTrail ( trailName , clientConfig ) ;
2021-11-15 13:15:43 +00:00
}
2024-04-29 13:26:35 -04:00
Aws : : ShutdownAPI ( options ) ;
return 0 ;
2021-11-15 13:15:43 +00:00
}
2024-04-29 13:26:35 -04:00
# endif // TESTING_BUILD