本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
DeleteSubscriptionFilter
与 Amazon SDK 或 CLI 配合使用
以下代码示例演示如何使用 DeleteSubscriptionFilter
。
- C++
-
- SDK for C++
-
注意
还有更多相关信息 GitHub。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 包含所需的文件。
#include <aws/core/Aws.h> #include <aws/core/utils/Outcome.h> #include <aws/logs/CloudWatchLogsClient.h> #include <aws/logs/model/DeleteSubscriptionFilterRequest.h> #include <iostream>
删除订阅筛选条件。
Aws::CloudWatchLogs::CloudWatchLogsClient cwl; Aws::CloudWatchLogs::Model::DeleteSubscriptionFilterRequest request; request.SetFilterName(filter_name); request.SetLogGroupName(log_group); auto outcome = cwl.DeleteSubscriptionFilter(request); if (!outcome.IsSuccess()) { std::cout << "Failed to delete CloudWatch log subscription filter " << filter_name << ": " << outcome.GetError().GetMessage() << std::endl; } else { std::cout << "Successfully deleted CloudWatch logs subscription " << "filter " << filter_name << std::endl; }
-
有关 API 的详细信息,请参阅 Amazon SDK for C++ API 参考DeleteSubscriptionFilter中的。
-
- Java
-
- 适用于 Java 2.x 的 SDK
-
注意
还有更多相关信息 GitHub。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 import software.amazon.awssdk.services.cloudwatch.model.CloudWatchException; import software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsClient; import software.amazon.awssdk.services.cloudwatchlogs.model.DeleteSubscriptionFilterRequest; /** * 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 DeleteSubscriptionFilter { public static void main(String[] args) { final String usage = """ Usage: <filter> <logGroup> Where: filter - The name of the subscription filter (for example, MyFilter). logGroup - The name of the log group. (for example, testgroup). """; if (args.length != 2) { System.out.println(usage); System.exit(1); } String filter = args[0]; String logGroup = args[1]; CloudWatchLogsClient logs = CloudWatchLogsClient.builder() .build(); deleteSubFilter(logs, filter, logGroup); logs.close(); } public static void deleteSubFilter(CloudWatchLogsClient logs, String filter, String logGroup) { try { DeleteSubscriptionFilterRequest request = DeleteSubscriptionFilterRequest.builder() .filterName(filter) .logGroupName(logGroup) .build(); logs.deleteSubscriptionFilter(request); System.out.printf("Successfully deleted CloudWatch logs subscription filter %s", filter); } catch (CloudWatchException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
-
有关 API 的详细信息,请参阅 Amazon SDK for Java 2.x API 参考DeleteSubscriptionFilter中的。
-
- JavaScript
-
- 适用于 JavaScript (v3) 的软件开发工具包
-
注意
还有更多相关信息 GitHub。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 import { DeleteSubscriptionFilterCommand } from "@aws-sdk/client-cloudwatch-logs"; import { client } from "../libs/client.js"; const run = async () => { const command = new DeleteSubscriptionFilterCommand({ // The name of the filter. filterName: process.env.CLOUDWATCH_LOGS_FILTER_NAME, // 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();
-
有关 API 的详细信息,请参阅 Amazon SDK for JavaScript API 参考DeleteSubscriptionFilter中的。
-
- 适用于 JavaScript (v2) 的软件开发工具包
-
注意
还有更多相关信息 GitHub。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 // 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 = { filterName: "FILTER", logGroupName: "LOG_GROUP", }; cwl.deleteSubscriptionFilter(params, function (err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data); } });
-
有关更多信息,请参阅 Amazon SDK for JavaScript 开发人员指南。
-
有关 API 的详细信息,请参阅 Amazon SDK for JavaScript API 参考DeleteSubscriptionFilter中的。
-
- Kotlin
-
- 适用于 Kotlin 的 SDK
-
注意
还有更多相关信息 GitHub。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 suspend fun deleteSubFilter( filter: String?, logGroup: String?, ) { val request = DeleteSubscriptionFilterRequest { filterName = filter logGroupName = logGroup } CloudWatchLogsClient { region = "us-west-2" }.use { logs -> logs.deleteSubscriptionFilter(request) println("Successfully deleted CloudWatch logs subscription filter named $filter") } }
-
有关 API 的详细信息,请参阅适用DeleteSubscriptionFilter
于 K otlin 的Amazon SDK API 参考。
-
有关 S Amazon DK 开发者指南和代码示例的完整列表,请参阅在 Amazon SDK 中使用 CloudWatch 日志。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。