There are more AWS SDK examples available in the AWS Doc SDK Examples
Use DescribeSubscriptionFilters
with an AWS SDK
The following code examples show how to use DescribeSubscriptionFilters
.
- 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
. Include the required files.
#include <aws/core/Aws.h> #include <aws/core/utils/Outcome.h> #include <aws/logs/CloudWatchLogsClient.h> #include <aws/logs/model/DescribeSubscriptionFiltersRequest.h> #include <aws/logs/model/DescribeSubscriptionFiltersResult.h> #include <iostream> #include <iomanip>
List the subscription filters.
Aws::CloudWatchLogs::CloudWatchLogsClient cwl; Aws::CloudWatchLogs::Model::DescribeSubscriptionFiltersRequest request; request.SetLogGroupName(log_group); request.SetLimit(1); bool done = false; bool header = false; while (!done) { auto outcome = cwl.DescribeSubscriptionFilters( request); if (!outcome.IsSuccess()) { std::cout << "Failed to describe CloudWatch subscription filters " << "for log group " << log_group << ": " << outcome.GetError().GetMessage() << std::endl; break; } if (!header) { std::cout << std::left << std::setw(32) << "Name" << std::setw(64) << "FilterPattern" << std::setw(64) << "DestinationArn" << std::endl; header = true; } const auto &filters = outcome.GetResult().GetSubscriptionFilters(); for (const auto &filter : filters) { std::cout << std::left << std::setw(32) << filter.GetFilterName() << std::setw(64) << filter.GetFilterPattern() << std::setw(64) << filter.GetDestinationArn() << std::endl; } const auto &next_token = outcome.GetResult().GetNextToken(); request.SetNextToken(next_token); done = next_token.empty(); }
-
For API details, see DescribeSubscriptionFilters in AWS SDK for C++ API Reference.
-
- Java
-
- SDK for Java 2.x
-
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 software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.services.cloudwatch.model.CloudWatchException; import software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsClient; import software.amazon.awssdk.services.cloudwatchlogs.model.DescribeSubscriptionFiltersRequest; import software.amazon.awssdk.services.cloudwatchlogs.model.DescribeSubscriptionFiltersResponse; import software.amazon.awssdk.services.cloudwatchlogs.model.SubscriptionFilter; /** * Before running this Java V2 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-java/latest/developer-guide/get-started.html */ public class DescribeSubscriptionFilters { public static void main(String[] args) { final String usage = """ Usage: <logGroup> Where: logGroup - A log group name (for example, myloggroup). """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String logGroup = args[0]; CloudWatchLogsClient logs = CloudWatchLogsClient.builder() .credentialsProvider(ProfileCredentialsProvider.create()) .build(); describeFilters(logs, logGroup); logs.close(); } public static void describeFilters(CloudWatchLogsClient logs, String logGroup) { try { boolean done = false; String newToken = null; while (!done) { DescribeSubscriptionFiltersResponse response; if (newToken == null) { DescribeSubscriptionFiltersRequest request = DescribeSubscriptionFiltersRequest.builder() .logGroupName(logGroup) .limit(1).build(); response = logs.describeSubscriptionFilters(request); } else { DescribeSubscriptionFiltersRequest request = DescribeSubscriptionFiltersRequest.builder() .nextToken(newToken) .logGroupName(logGroup) .limit(1).build(); response = logs.describeSubscriptionFilters(request); } for (SubscriptionFilter filter : response.subscriptionFilters()) { System.out.printf("Retrieved filter with name %s, " + "pattern %s " + "and destination arn %s", filter.filterName(), filter.filterPattern(), filter.destinationArn()); } if (response.nextToken() == null) { done = true; } else { newToken = response.nextToken(); } } } catch (CloudWatchException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } System.out.printf("Done"); } }
-
For API details, see DescribeSubscriptionFilters in AWS SDK for Java 2.x 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 { DescribeSubscriptionFiltersCommand } from "@aws-sdk/client-cloudwatch-logs"; import { client } from "../libs/client.js"; const run = async () => { // This will return a list of all subscription filters in your account // matching the log group name. const command = new DescribeSubscriptionFiltersCommand({ logGroupName: process.env.CLOUDWATCH_LOGS_LOG_GROUP, limit: 1, }); try { return await client.send(command); } catch (err) { console.error(err); } }; export default run();
-
For API details, see DescribeSubscriptionFilters in AWS SDK for JavaScript API Reference.
-
- SDK for JavaScript (v2)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. // Load the AWS SDK for Node.js var AWS = require("aws-sdk"); // Set the region AWS.config.update({ region: "REGION" }); // Create the CloudWatchLogs service object var cwl = new AWS.CloudWatchLogs({ apiVersion: "2014-03-28" }); var params = { logGroupName: "GROUP_NAME", limit: 5, }; cwl.describeSubscriptionFilters(params, function (err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data.subscriptionFilters); } });
-
For more information, see AWS SDK for JavaScript Developer Guide.
-
For API details, see DescribeSubscriptionFilters in AWS SDK for JavaScript API Reference.
-
- Kotlin
-
- SDK for Kotlin
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. suspend fun describeFilters(logGroup: String) { val request = DescribeSubscriptionFiltersRequest { logGroupName = logGroup limit = 1 } CloudWatchLogsClient { region = "us-west-2" }.use { cwlClient -> val response = cwlClient.describeSubscriptionFilters(request) response.subscriptionFilters?.forEach { filter -> println("Retrieved filter with name ${filter.filterName} pattern ${filter.filterPattern} and destination ${filter.destinationArn}") } } }
-
For API details, see DescribeSubscriptionFilters
in AWS SDK for Kotlin API reference.
-