0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cloudwatch アラーム作成 CLI方式

Last updated at Posted at 2025-08-29

https://docs.aws.amazon.com/zh_cn/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html
PutMetricAlarm CPI ドキュメント

put-composite-alarm
https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/put-composite-alarm.html

アラーム作成
aws cloudwatch put-metric-alarm
--alarm-name "CPU使用率監視"
--alarm-description "EC2のCPU使用率監視"
--alarm-actions SNSトピックのARN
--ok-actions SNSトピックのARN
--namespace AWS/EC2
--dimensions "Name=InstanceId,Value=インスタンスID"
--metric-name CPUUtilization
--threshold 90 \ 
--comparison-operator GreaterThanOrEqualToThreshold
--period 300
--evaluation-periods 1
--datapoints-to-alarm 1
--statistic Average
--treat-missing-data missing
--comparison-operator
超える(GreaterThanThreshold)
以上(GreaterThanOrEqualToThreshold)
未満(LessThanThreshold)
以下(LessThanOrEqualToThreshold)

複合アラーム
aws cloudwatch put-composite-alarm
--alarm-name ProdAlarm
--alarm-rule "ALARM(CPUUtilizationTooHigh) AND ALARM(MemUsageTooHigh)"
--alarm-actions arn:aws:sns:us-east-1:123456789012:demo
--actions-enabled

サブスクリプションフィルター
CloudFormationでの例(YAML)

Resources:
MySubscriptionFilter:
Type: AWS::Logs::SubscriptionFilter
Properties:
LogGroupName: "your-log-group-name" # ロググループ名を指定
FilterPattern: "ERROR" # 特定のログパターンを指定(例: エラーログのみ)
DestinationArn: !GetAtt YourFirehoseDeliveryStream.Arn # Kinesis Data FirehoseのARNを指定
RoleArn: !GetAtt YourDeliveryRole.Arn # IAMロールのARNを指定
Distribution: "Random" # Random or All
Method: "Firehose"

LogGroupName:
ログをフィルターするCloudWatch Logsのロググループ名を指定します。
FilterPattern:
ログをフィルタリングするためのパターンを指定します。例えば、ERRORと指定するとエラーログのみがFirehoseに送信されます。
DestinationArn:
ログの送信先となるKinesis Data Firehoseの配信ストリームのARNを指定します。
RoleArn:
CloudWatch LogsがKinesis Data Firehoseにログを配信するための権限を持つIAMロールのARNを指定します。
Distribution:
ログの配信方法を指定します。Random(ランダムに配信)またはAll(全てのFirehoseに配信)が選択できます。
Method:
連携するサービスを指定します。ここではFirehoseを設定します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?