- AWS Code Sample demonstrates how to delete Amazon CloudWatch log subscription filters.


To run this Java (SDK V2) code example, ensure that you have set up your development environment, including your credentials. For more information, see AWS SDK for Java 2.x Developer Guide.

/* Copyright, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ package com.example.cloudwatch; import; import; import; /** * To run this Java V2 code example, ensure that you have setup your development environment, including your credentials. * * For information, see this documentation topic: * * */ public class DeleteSubscriptionFilter { public static void main(String[] args) { final String USAGE = "\n" + "Usage:\n" + " DeleteSubscriptionFilter <filter> <logGroup>\n\n" + "Where:\n" + " filter - the name of the subscription filter (for example, MyFilter).\n" + " logGroup - the name of the log group. (for example, testgroup).\n" ; 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); } } }

Sample Details

Service: Amazon CloudWatch

Last tested: 11/02/2020

Author: scmacdon - aws

Type: full-example