View a markdown version of this page

Use DeleteAlarmMuteRule with an AWS SDK - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use DeleteAlarmMuteRule with an AWS SDK

The following code examples show how to use DeleteAlarmMuteRule.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

.NET
SDK for .NET (v4)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Delete an alarm mute rule. The alarms it targeted resume firing their actions. /// </summary> /// <param name="name">The name of the mute rule.</param> /// <returns>True if successful.</returns> public async Task<bool> DeleteAlarmMuteRule(string name) { var response = await _amazonCloudWatch.DeleteAlarmMuteRuleAsync( new DeleteAlarmMuteRuleRequest { AlarmMuteRuleName = name }); _logger.LogInformation($"Deleted alarm mute rule {name}."); return response.HttpStatusCode == System.Net.HttpStatusCode.OK; }
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/monitoring/CloudWatchClient.h> #include <aws/monitoring/model/DeleteAlarmMuteRuleRequest.h> #include <iostream>

Delete the alarm mute rule.

Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; Aws::CloudWatch::CloudWatchClient cw(clientConfig); Aws::CloudWatch::Model::DeleteAlarmMuteRuleRequest request; request.SetAlarmMuteRuleName(mute_rule_name); auto outcome = cw.DeleteAlarmMuteRule(request); if (!outcome.IsSuccess()) { std::cerr << "Failed to delete alarm mute rule: " << outcome.GetError().GetMessage() << std::endl; } else { std::cout << "Successfully deleted alarm mute rule " << mute_rule_name << std::endl; }
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.

/** * Deletes an alarm mute rule. The alarms it targeted resume firing their actions. * * @param cw the CloudWatch client * @param name the name of the mute rule */ public static void deleteAlarmMuteRule(CloudWatchClient cw, String name) { try { cw.deleteAlarmMuteRule(DeleteAlarmMuteRuleRequest.builder() .alarmMuteRuleName(name) .build()); System.out.printf("Deleted alarm mute rule %s.%n", name); } catch (CloudWatchException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
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 { DeleteAlarmMuteRuleCommand } from "@aws-sdk/client-cloudwatch"; import { client } from "../libs/client.js"; // Delete an alarm mute rule. The alarms it targeted resume firing their actions. const run = async () => { const command = new DeleteAlarmMuteRuleCommand({ AlarmMuteRuleName: process.env.CLOUDWATCH_MUTE_RULE_NAME, // Set CLOUDWATCH_MUTE_RULE_NAME to the name of an existing mute rule. }); try { return await client.send(command); } catch (err) { console.error(err); } }; export default run();
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 deleteAlarmMuteRule(muteRuleName: String) { val request = DeleteAlarmMuteRuleRequest { alarmMuteRuleName = muteRuleName } CloudWatchClient.fromEnvironment { region = "us-east-1" }.use { cwClient -> cwClient.deleteAlarmMuteRule(request) println("Successfully deleted alarm mute rule $muteRuleName") } }
Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

class CloudWatchOTelWrapper: """Encapsulates the OpenTelemetry-oriented Amazon CloudWatch operations.""" def __init__(self, cloudwatch_client): """ :param cloudwatch_client: A Boto3 CloudWatch client. The OpenTelemetry operations are only available on the client interface, not on the higher-level ``boto3.resource("cloudwatch")`` interface. """ self.cloudwatch_client = cloudwatch_client @classmethod def from_client(cls): """ Creates a wrapper backed by a default CloudWatch client. :return: A CloudWatchOTelWrapper. """ return cls(boto3.client("cloudwatch")) def delete_alarm_mute_rule(self, name): """ Deletes an alarm mute rule. :param name: The name of the mute rule. """ try: self.cloudwatch_client.delete_alarm_mute_rule(AlarmMuteRuleName=name) logger.info("Deleted alarm mute rule %s.", name) except ClientError: logger.exception("Couldn't delete alarm mute rule %s.", name) raise
Ruby
SDK for Ruby
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

# Deletes an alarm mute rule. The alarms it targeted resume firing their actions. # # @param cloudwatch_client [Aws::CloudWatch::Client] An initialized CloudWatch client. # @param name [String] The name of the mute rule. # @return [Boolean] true if the mute rule was deleted; otherwise, false. def alarm_mute_rule_deleted?(cloudwatch_client, name) cloudwatch_client.delete_alarm_mute_rule(alarm_mute_rule_name: name) true rescue StandardError => e puts "Error deleting alarm mute rule: #{e.message}" false end