SIGN IN SIGN UP

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.

0 0 1 Java
2021-11-15 13:31:25 +00:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
2021-11-15 13:15:43 +00:00
/*
2021-12-17 14:41:43 +00:00
/* ////////////////////////////////////////////////////////////////////////////
* Purpose: delete_alarm.cpp demonstrates how to delete an Amazon CloudWatch alarm.
*
2021-12-21 13:36:46 +00:00
* Prerequisites:
* - An Amazon CloudWatch metric alarm.
*
2021-12-17 14:41:43 +00:00
* Inputs:
2021-12-17 17:57:59 +00:00
* - alarm_name (entered as second argument in command line).
2021-12-17 14:41:43 +00:00
*
* ///////////////////////////////////////////////////////////////////////// */
2021-11-15 13:31:25 +00:00
2021-11-15 13:15:43 +00:00
// snippet-start:[cw.cpp.delete_alarm.inc]
#include <aws/core/Aws.h>
#include <aws/monitoring/CloudWatchClient.h>
#include <aws/monitoring/model/DeleteAlarmsRequest.h>
#include <iostream>
// snippet-end:[cw.cpp.delete_alarm.inc]
/**
* Deletes a CloudWatch alarm
*/
int main(int argc, char** argv)
{
if (argc != 2)
{
std::cout << "Usage: cw_delete_alarm <alarm_name>" << std::endl;
return 1;
}
Aws::SDKOptions options;
Aws::InitAPI(options);
{
Aws::String alarm_name(argv[1]);
// snippet-start:[cw.cpp.delete_alarm.code]
Aws::CloudWatch::CloudWatchClient cw;
Aws::CloudWatch::Model::DeleteAlarmsRequest request;
request.AddAlarmNames(alarm_name);
auto outcome = cw.DeleteAlarms(request);
if (!outcome.IsSuccess())
{
std::cout << "Failed to delete CloudWatch alarm:" <<
outcome.GetError().GetMessage() << std::endl;
}
else
{
std::cout << "Successfully deleted CloudWatch alarm " << alarm_name
<< std::endl;
}
// snippet-end:[cw.cpp.delete_alarm.code]
}
Aws::ShutdownAPI(options);
return 0;
}