AWS SDK for Java 1.x 已end-of-support
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 CloudWatch 中的警示動作
使用 CloudWatch 警示動作,您可以建立警示來執行動作,例如自動停止、終止、重新啟動或復原Amazon EC2實例。
啟用警示動作
要啟用警報操作 CloudWatch 警報,請致電卓越亞馬遜關注客户端的enableAlarmActions
具有EnableAlarmActionsRequest包含一個或多個您想要啟用其動作的警示名稱。
匯入
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; import com.amazonaws.services.cloudwatch.AmazonCloudWatchClientBuilder; import com.amazonaws.services.cloudwatch.model.EnableAlarmActionsRequest; import com.amazonaws.services.cloudwatch.model.EnableAlarmActionsResult;
Code
final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient(); EnableAlarmActionsRequest request = new EnableAlarmActionsRequest() .withAlarmNames(alarm); EnableAlarmActionsResult response = cw.enableAlarmActions(request);
停用警示動作
若要禁用警報操作 CloudWatch 警報,請致電卓越亞馬遜關注客户端的disableAlarmActions
具有DisableAlarmActionsRequest包含一個或多個您想要停用其動作的警示名稱。
匯入
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; import com.amazonaws.services.cloudwatch.AmazonCloudWatchClientBuilder; import com.amazonaws.services.cloudwatch.model.DisableAlarmActionsRequest; import com.amazonaws.services.cloudwatch.model.DisableAlarmActionsResult;
Code
final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient(); DisableAlarmActionsRequest request = new DisableAlarmActionsRequest() .withAlarmNames(alarmName); DisableAlarmActionsResult response = cw.disableAlarmActions(request);
詳細資訊
-
建立警示以停止、終止、重新啟動或復原執行個體中的Amazon CloudWatch使用者指南
-
PutMetricAlarm中的Amazon CloudWatchAPI 參考
-
EnableAlarmActions中的Amazon CloudWatchAPI 參考
-
DisableAlarmActions中的Amazon CloudWatchAPI 參考