2017-11-22 19:04:13 +00:00
---
title: About the aws_cloudwatch_alarm Resource
2018-02-13 19:30:07 +00:00
platform: aws
2017-11-22 19:04:13 +00:00
---
2018-02-15 02:23:29 +00:00
# aws\_cloudwatch\_alarm
2017-11-22 19:04:13 +00:00
Use the `aws_cloudwatch_alarm` InSpec audit resource to test properties of a single Cloudwatch Alarm.
Cloudwatch Alarms are currently identified using the metric name and metric namespace. Future work may allow other approaches to identifying alarms.
<br>
## Syntax
An `aws_cloudwatch_alarm` resource block searches for a Cloudwatch Alarm, specified by several search options. If more than one Alarm matches, an error occurs.
# Look for a specific alarm
aws_cloudwatch_alarm(
metric: 'my-metric-name',
metric_namespace: 'my-metric-namespace',
) do
it { should exist }
end
<br>
2018-02-14 01:42:39 +00:00
## Examples
2018-02-13 19:30:07 +00:00
2018-02-14 01:42:39 +00:00
The following examples show how to use this InSpec audit resource.
2018-02-13 19:30:07 +00:00
2018-02-14 01:42:39 +00:00
### Ensure an Alarm has at least one alarm action
2018-02-13 19:30:07 +00:00
describe aws_cloudwatch_alarm(
2018-02-14 01:42:39 +00:00
metric: 'my-metric-name',
2018-02-13 19:30:07 +00:00
metric_namespace: 'my-metric-namespace',
) do
its('alarm_actions') { should_not be_empty }
2018-02-14 01:42:39 +00:00
end
2018-02-13 19:30:07 +00:00
<br>
2018-02-14 01:42:39 +00:00
## Properties
2017-11-22 19:04:13 +00:00
2018-02-14 01:42:39 +00:00
* `alarm_actions`
2017-11-22 19:04:13 +00:00
2018-02-14 01:42:39 +00:00
## Property Examples
2018-02-15 02:23:29 +00:00
### alarm\_actions
2018-02-14 01:42:39 +00:00
`alarm_actions` returns a list of strings. Each string is the ARN of an action that will be taken should the alarm be triggered.
2017-11-22 19:04:13 +00:00
2018-02-14 01:42:39 +00:00
# Ensure that the alarm has at least one action
2017-11-22 19:04:13 +00:00
describe aws_cloudwatch_alarm(
2018-02-14 01:42:39 +00:00
metric: 'bed-metric',
2017-11-22 19:04:13 +00:00
metric_namespace: 'my-metric-namespace',
) do
its('alarm_actions') { should_not be_empty }
2018-02-14 01:42:39 +00:00
end
2017-11-22 19:04:13 +00:00
<br>
## Matchers
2018-02-16 03:07:18 +00:00
This InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
2018-02-13 19:30:07 +00:00
2017-11-22 19:04:13 +00:00
### exists
2018-02-14 01:42:39 +00:00
The control will pass if a Cloudwatch Alarm could be found. Use `should_not` if you expect zero matches.
2017-11-22 19:04:13 +00:00
# Expect good metric
describe aws_cloudwatch_alarm(
metric: 'good-metric',
metric_namespace: 'my-metric-namespace',
) do
it { should exist }
end
# Disallow alarms based on bad-metric
describe aws_cloudwatch_alarm(
metric: 'bed-metric',
metric_namespace: 'my-metric-namespace',
) do
it { should_not exist }
end