Bootstrap FreeKB - Ansible - Create Amazon Web Services (AWS) Cloudwatch Alarm
Ansible - Create Amazon Web Services (AWS) Cloudwatch Alarm

Updated:   |  Ansible articles

If you are not familiar with modules, check out Ansible - Getting Started with Modules.

Prerequisites

Before creating an alarm, you will need:

  • The Amazon Resource Number (ARN) of one of your AWS Simple Notification Service (SNS) Topics
  • The ID of one or more of your EC2 instances

cloudwatch_metric_alarm can be used to create an Amazon Web Services (AWS) Cloudwatch Alarm. 

---
- name: main play
  hosts: localhost
  tasks:
  - name: pip install boto3
    pip:
      name: boto3
      state: latest

  - name: create Cloudwatch alarm
    amazon.aws.cloudwatch_metric_alarm:
      state: present
      region: us-east-1
      name: high-cpu
      metric_name: CPUUtilization
      namespace: AWS/EC2
      statistic: Average
      comparison: GreaterThanThreshold
      threshold: 50.0
      period: 300
      evaluation_periods: 2
      unit: Percent
      description: "EC2 Instance CPU exceeds 50%"
      dimensions: {"InstanceId":"i-09e2eabcdf1481234"}
      alarm_actions: ["arn:aws:sns:us-east-1:123456789012:my-topic"]
...

 

absent can be used to delete an alarm.

---
- name: main play
  hosts: localhost
  tasks:
  - name: pip install boto3
    pip:
      name: boto3
      state: latest

  - name: create Cloudwatch alarm
    amazon.aws.cloudwatch_metric_alarm:
      state: absent
      name: high-cpu
...

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 6bfbc1 in the box below so that we can be sure you are a human.