AWS Code Sample
Catalog

describe_subscription_filters.cpp

describe_subscription_filters.cpp demonstrates how to list the subscription filters for an Amazon CloudWatch Logs resource.

/* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #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> /** * Lists cloudwatch subscription filters associated with a log group */ int main(int argc, char** argv) { if (argc != 2) { std::cout << "Usage: describe_subscription_filters <log_group_name>" << std::endl; return 1; } Aws::String log_group(argv[1]); Aws::SDKOptions options; Aws::InitAPI(options); { 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(); } } Aws::ShutdownAPI(options); return 0; }

Sample Details

Service: logs

Author: AWS

Type: full-example

On this page: