Use DeleteLogGroup with an Amazon SDK or CLI - Amazon CloudWatch Logs
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Use DeleteLogGroup with an Amazon SDK or CLI

The following code examples show how to use DeleteLogGroup.

.NET
Amazon SDK for .NET
Note

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

using System; using System.Threading.Tasks; using Amazon.CloudWatchLogs; using Amazon.CloudWatchLogs.Model; /// <summary> /// Uses the Amazon CloudWatch Logs Service to delete an existing /// CloudWatch Logs log group. /// </summary> public class DeleteLogGroup { public static async Task Main() { var client = new AmazonCloudWatchLogsClient(); string logGroupName = "cloudwatchlogs-example-loggroup"; var request = new DeleteLogGroupRequest { LogGroupName = logGroupName, }; var response = await client.DeleteLogGroupAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"Successfully deleted CloudWatch log group, {logGroupName}."); } } }
  • For API details, see DeleteLogGroup in Amazon SDK for .NET API Reference.

CLI
Amazon CLI

The following command deletes a log group named my-logs:

aws logs delete-log-group --log-group-name my-logs
  • For API details, see DeleteLogGroup in Amazon CLI Command Reference.

JavaScript
SDK for JavaScript (v3)
Note

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

import { DeleteLogGroupCommand } from "@aws-sdk/client-cloudwatch-logs"; import { client } from "../libs/client.js"; const run = async () => { const command = new DeleteLogGroupCommand({ // The name of the log group. logGroupName: process.env.CLOUDWATCH_LOGS_LOG_GROUP, }); try { return await client.send(command); } catch (err) { console.error(err); } }; export default run();
  • For API details, see DeleteLogGroup in Amazon SDK for JavaScript API Reference.

For a complete list of Amazon SDK developer guides and code examples, see Using CloudWatch Logs with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.