Use CreateExportTask 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 CreateExportTask with an Amazon SDK or CLI

The following code example shows how to use CreateExportTask.

.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> /// Shows how to create an Export Task to export the contents of the Amazon /// CloudWatch Logs to the specified Amazon Simple Storage Service (Amazon S3) /// bucket. /// </summary> public class CreateExportTask { 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 taskName = "export-task-example"; string logGroupName = "cloudwatchlogs-example-loggroup"; string destination = "doc-example-bucket"; var fromTime = 1437584472382; var toTime = 1437584472833; var request = new CreateExportTaskRequest { From = fromTime, To = toTime, TaskName = taskName, LogGroupName = logGroupName, Destination = destination, }; var response = await client.CreateExportTaskAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"The task, {taskName} with ID: " + $"{response.TaskId} has been created successfully."); } } }

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.