There are more AWS SDK examples available in the AWS Doc SDK Examples
Create a CloudWatch Logs log group using an AWS SDK
The following code examples show how to create a new CloudWatch Logs log group.
- .NET
-
- AWS SDK for .NET
-
Note There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. using System; using System.Threading.Tasks; using Amazon.CloudWatchLogs; using Amazon.CloudWatchLogs.Model; /// <summary> /// Shows how to create an Amazon CloudWatch Logs log group. The example /// was created using the AWS SDK for .NET version 3.7 and .NET Core 5.0. /// </summary> public class CreateLogGroup { public static async Task Main() { // This client object will be associated with the same AWS Region // as the default user on this system. If you need to use a // different AWS Region, pass it as a parameter to the client // constructor. var client = new AmazonCloudWatchLogsClient(); string logGroupName = "cloudwatchlogs-example-loggroup"; var request = new CreateLogGroupRequest { LogGroupName = logGroupName, }; var response = await client.CreateLogGroupAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"Successfully create log group with ID: {logGroupName}."); } else { Console.WriteLine("Could not create log group."); } } }
-
For API details, see CreateLogGroup in AWS SDK for .NET API 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 AWS Code Examples Repository
. import { CreateLogGroupCommand } from "@aws-sdk/client-cloudwatch-logs"; import { client } from "../libs/client.js"; const run = async () => { const command = new CreateLogGroupCommand({ // 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 CreateLogGroup in AWS SDK for JavaScript API Reference.
-