I am using python boto3 to create a CloudWatch alarm for a sub account (not a root account). I have stored the account id of that sub account in a variable called accnum . I need to stop an ec2 instance in that sub account once it exceeds a CPU % of 10. Going by the boto3 docs, we need to pass the arn value in the AlarmActions to start/stop/terminate an EC2 instance.
For root account, it is like this:
AlarmActions=[
'arn:aws:swf:us-east-2:{CUSTOMER_ACCOUNT}:action/actions/AWS_EC2.InstanceId.Stop/1.0'
],
How can I do the same for a sub account. I tried passing the accnum variable in the AlarmActions but it throws a syntax error.
I tried like this :
AlarmActions=[
'arn:aws:swf:us-east-2:',accnum,':action/actions/AWS_EC2.InstanceId.Stop/1.0'
],
But a syntax error is thrown like this :
botocore.exceptions.ClientError: An error occurred (ValidationError) when calling the PutMetricAlarm operation: Invalid arn syntax: arn:aws:swf:us-east-2:
How can I pass the accnum as a variable ? Or is there any other way to pass Alarm Actions to stop an ec2 instance ? Or is there an equivalent for sub account like {CUSTOMER_ACCOUNT} is for root account ?