How to delete cloudwatch alarms that are attached to non-existent instances?
<p>When I create new EC2 instances I use an ansible <a href="http://docs.ansible.com/ansible/intro_dynamic_inventory.html#example-aws-ec2-external-inventory-script" rel="nofollow">dynamic inventory</a> to create new cloudwatch metrics alarms. So far so good:</p>

<pre class="lang-yaml prettyprint-override"><code>- name: set AWS CloudWatch alarms
  hosts: tag_env_production
  vars:
    alarm_slack: 'arn:aws:sns:123:metrics-alarms-slack'
  tasks:
    - name: "CPU &gt; 70%"
      ec2_metric_alarm:
        state: present
        name: "{{ ec2_tag_Name }}-CPU"
        region: "{{ ec2_region }}"
        dimensions:
          InstanceId: '{{ ec2_id }}'
        namespace: "AWS/EC2"
        metric: CPUUtilization
        statistic: Average
        comparison: "&gt;="
        threshold: 70.0
        unit: Percent
        period: 300
        evaluation_periods: 1
        description: Triggered when CPU utilization is more than 70% for 5 minutes
        alarm_actions: ['{{ alarm_slack }}']
      when: ec2_tag_group == 'lazyservers'
</code></pre>

<p>Executing as follows:</p>

<pre><code>ansible-playbook -v ec2_alarms.yml -i inventories/ec2/ec2.py
</code></pre>

<p>After creating the new instances I drop the old ones (manually). The problem is that I'd need to delete the alarms for existing metrics attached to the old instances.</p>

<p>Am I missing something or there is no way how to do this via the dynamic inventory?</p>

<p>My current idea is to delete the metrics for instances that are in the "Terminating" state, but the downside is that if I run the playbook after those instances are terminated, they simply won't be visible.</p>