【问题标题】:Stopping an AWS EC2 Instance with a Cloudwatch Alarm in Java使用 Java 中的 Cloudwatch 警报停止 AWS EC2 实例
【发布时间】:2013-07-03 18:53:47
【问题描述】:

到目前为止,我已经以这样的方式设置了警报:

dim = new Dimension()
        .withName("InstanceId")
        .withValue(hashedId);

alarmreq = new PutMetricAlarmRequest()
              .withDimensions(dim)
              .withMetricName(metricName)
              .withNamespace(nameSpace)
              .withAlarmName(alarmName)
              .withActionsEnabled(true)
              .withStatistic(statistic)
              .withThreshold(threshold)
              .withComparisonOperator("GreaterThanThreshold")
              .withPeriod(period)
              .withEvaluationPeriods(evaluationPeriods)
              .withAlarmActions("arn:aws:sns:us-west-2:xxxxxxxxx:NotifyMe");

gCloudWatch.putMetricAlarm(alarmreq);

这会为执行 SNS NotifyMe 的指定实例创建一个警报。但是,我找不到有关如何添加到此警报或 SNS 以在警报进入 ALARM 状态时停止或终止实例的任何文档。

我拥有的唯一线索是,虽然 .withAlarmActions() 只接受 SNS 或 SQS 操作,但 SNS 可以发出 HTTP 请求,在最坏的情况下我可能能够处理。

我还知道可以将此功能添加到警报中,因为在 AWS Web 界面上,您可以创建停止或终止实例的警报。

【问题讨论】:

    标签: java amazon-web-services amazon-ec2 amazon-cloudwatch


    【解决方案1】:

    通过在亚马逊论坛中提问找到了答案。基本上,我认为 withAlarmActions 只接受 SNS 或 SQS 操作是错误的。它还可以接受“arn:aws:automate:us-west-2:ec2:stop”形式的停止或终止操作。编辑后要修复的最后一行代码如下所示:

    .withAlarmActions("arn:aws:sns:us-west-2:xxxxxxxxx:NotifyMe", "arn:aws:automate:us-west-2:ec2:stop");
    

    如果有人好奇,这里是完整的答案。 https://forums.aws.amazon.com/thread.jspa?messageID=466061&#466061

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-14
      • 2016-11-22
      • 1970-01-01
      • 2015-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多