I'm trying to create a CloudWatch billing alarm example pic:
it all seems fine, it's really strange I even get a HTTPStatusCode 200 when I run it but it does nothing, I've even waited 24 hours and checked but I can't see what I created... What am I missing? code below, please note I am using SSO and running against account id which I have not included in my code for privacy:
import boto3
sess = boto3.Session(profile_name='sso-account-here', region_name='us-east-1') #Billing region is US
cw = sess.client('cloudwatch')
cw.put_metric_alarm(
AlarmName='Test 2',
AlarmDescription='Test Alarm',
ActionsEnabled=True,
EvaluationPeriods=1,
Threshold=2000,
ComparisonOperator='GreaterThanOrEqualToThreshold',
TreatMissingData='missing',
Metrics=[
{
'Id': 'testalarm',
'MetricStat': {
'Metric': {
'Namespace': 'AWS/Billing',
'MetricName': 'EstimatedCharges',
'Dimensions': [
{
'Name':'Currency',
'Value':'USD'
},
{
'Name':'LinkedAccount',
'Value':'AWSACCOUNTIDHERE'
}
]
},
'Period': 21600,
'Stat': 'Maximum',
'Unit': 'Seconds'
},
'Label': 'EstimatedCharges > 1000 for 1 datapoints within 6 hours',
'ReturnData': True,
},
],
)
Thanks in advance for any help or advice.
Turns out this was working after all, but you must include:
AlarmActions=['arn:forsnstopic'],
and create a valid SNS topic and subscription first.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.