(event, context)
| 3 | import os |
| 4 | |
| 5 | def handler(event, context): |
| 6 | sns_arn = 'arn:aws:sns:' + os.environ['region'] + ':' + os.environ['acct'] + ':' + os.environ['topic'] |
| 7 | ssm = boto3.client('ssm') |
| 8 | desc = event['detail']['alarmName'] |
| 9 | source = 'EC2' |
| 10 | title = event['detail-type'] |
| 11 | caller = context.invoked_function_arn |
| 12 | response = ssm.create_ops_item( |
| 13 | Description=desc, |
| 14 | OperationalData={ |
| 15 | '/aws/automations': { |
| 16 | "Value":"[{\"automationId\": \"AWS-RestartEC2Instance\", \"automationType\": \"AWS::SSM::Automation\"}]", |
| 17 | "Type": "SearchableString" |
| 18 | }, |
| 19 | '/aws/dedup': { |
| 20 | "Type": "SearchableString", |
| 21 | "Value":"{\"dedupString\":\"" + desc + "\"}" |
| 22 | } |
| 23 | }, |
| 24 | Notifications=[ |
| 25 | { |
| 26 | 'Arn': sns_arn |
| 27 | }, |
| 28 | ], |
| 29 | Priority=3, |
| 30 | RelatedOpsItems=[ |
| 31 | { |
| 32 | 'OpsItemId': 'oi-cebfda3fb3ec' |
| 33 | }, |
| 34 | ], |
| 35 | Source=source, |
| 36 | Title=title, |
| 37 | Tags=[ |
| 38 | { |
| 39 | 'Key': 'Source', |
| 40 | 'Value': caller |
| 41 | }, |
| 42 | ], |
| 43 | Category='Availability', |
| 44 | Severity='2', |
| 45 | ) |
| 46 | print(response) |
nothing calls this directly
no outgoing calls
no test coverage detected