알람 구성을 JSON 파일로 생성
예제 JSON 파일:
$ cat alarm_config.json
{
"AlarmName": "DailyEstimatedCharges",
"AlarmDescription": "This alarm would be triggered if the daily estimated charges exceeds 50$",
"ActionsEnabled": true,
"AlarmActions": [
"arn:aws:sns:<REGION>:<ACCOUNT_ID>:<SNS_TOPIC_NAME>"
],
"EvaluationPeriods": 1,
"DatapointsToAlarm": 1,
"Threshold": 50,
"ComparisonOperator": "GreaterThanOrEqualToThreshold",
"TreatMissingData": "breaching",
"Metrics": [{
"Id": "m1",
"MetricStat": {
"Metric": {
"Namespace": "AWS/Billing",
"MetricName": "EstimatedCharges",
"Dimensions": [{
"Name": "Currency",
"Value": "USD"
}]
},
"Period": 86400,
"Stat": "Maximum"
},
"ReturnData": false
},
{
"Id": "e1",
"Expression": "IF(RATE(m1)>0,RATE(m1)*86400,0)",
"Label": "DailyEstimatedCharges",
"ReturnData": true
}]
}
참고: REGION, ACCOUNT_ID 및 SNS_TOPIC_NAME을 사용자 값으로 바꿉니다.
PutMetricAlarm API를 호출합니다.
API 호출 예시:
aws cloudwatch put-metric-alarm --cli-input-json file://alarm_config.json
(선택 사항) Maximum DailyEstimatedCharges 값에 대한 전날의 상위 10개 기여자를 찾으려면 다음 쿼리를 실행합니다.
$ cat top_contributors_query.json
{
"MetricDataQueries": [{
"Id": "e1",
"Expression": "SORT(RATE(SEARCH('{AWS/Billing,Currency,ServiceName} AWS/Billing ServiceName', 'Maximum', 86400))*86400, MAX, DESC, 10)",
"Label": "DailyEstimatedCharges",
"Period": 86400
}],
"ScanBy": "TimestampAscending"
}
$ aws cloudwatch get-metric-data --cli-input-json file://top_contributors_query.json --start-time `date -v -2d '+%Y-%m-%dT%H:%M:%SZ'` --end-time `date '+%Y-%m-%dT%H:%M:%SZ'` --region us-east-1
StartTime 및 EndTime에 대해 지원되는 DateTime 형식은 2020-01-01T00:00:00Z입니다.
중요: 앞의 명령은 각 GetMetricData API 호출이 검색하는 지표 수에 따라 요금이 부과됩니다. 자세한 내용은 Amazon CloudWatch 요금을 참조하세요.