Use DeleteTrail with an AWS SDK or CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use DeleteTrail with an AWS SDK or CLI

The following code examples show how to use DeleteTrail.

C++
SDK for C++
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

// 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); Aws::CloudTrail::Model::DeleteTrailRequest request; request.SetName(trailName); 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; } return outcome.IsSuccess(); }
  • For API details, see DeleteTrail in AWS SDK for C++ API Reference.

CLI
AWS CLI

To delete a trail

The following delete-trail command deletes a trail named Trail1:

aws cloudtrail delete-trail --name Trail1
  • For API details, see DeleteTrail in AWS CLI Command Reference.

PowerShell
Tools for PowerShell

Example 1: Deletes the specified trail. You will be prompted for confirmation before the command is run. To suppress confirmation, add the -Force switch parameter.

Remove-CTTrail -Name "awscloudtrail-example"
  • For API details, see DeleteTrail in AWS Tools for PowerShell Cmdlet Reference.

Ruby
SDK for Ruby
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

client.delete_trail({ name: trail_name # required }) puts "Successfully deleted trail: #{trail_name}" rescue StandardError => e puts "Got error trying to delete trail: #{trail_name}:" puts e exit 1 end
  • For API details, see DeleteTrail in AWS SDK for Ruby API Reference.