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
2019-04-26 18:24:29 +00:00
Use the `aws_cloudwatch_alarm` Chef InSpec audit resource to test properties of a single Cloudwatch Alarm.
2017-11-22 19:04:13 +00:00
2018-02-20 03:09:51 +00:00
Cloudwatch Alarms are currently identified using the metric name and metric namespace. Future work may allow other approaches to identifying alarms.
2017-11-22 19:04:13 +00:00
<br>
2018-08-09 12:34:49 +00:00
## Availability
### Installation
2019-04-26 18:24:29 +00:00
This resource is distributed along with Chef InSpec itself. You can use it automatically.
2018-08-09 12:34:49 +00:00
### Version
This resource first became available in v2.0.16 of InSpec.
2017-11-22 19:04:13 +00:00
## Syntax
2018-02-20 03:09:51 +00:00
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.
2017-11-22 19:04:13 +00:00
# Look for a specific alarm
aws_cloudwatch_alarm(
2018-04-12 19:26:32 +00:00
metric_name: 'my-metric-name',
2017-11-22 19:04:13 +00:00
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
2019-04-26 18:24:29 +00:00
The following examples show how to use this Chef 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',
2018-05-10 18:57:53 +00:00
) do
2018-02-13 19:30:07 +00:00
its('alarm_actions') { should_not be_empty }
2018-05-10 18:57:53 +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
2018-02-20 03:09:51 +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',
2018-05-10 18:57:53 +00:00
) do
2017-11-22 19:04:13 +00:00
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
2019-04-26 18:24:29 +00:00
This Chef 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',
2018-05-10 18:57:53 +00:00
) do
2017-11-22 19:04:13 +00:00
it { should exist }
end
# Disallow alarms based on bad-metric
describe aws_cloudwatch_alarm(
metric: 'bed-metric',
metric_namespace: 'my-metric-namespace',
2018-05-10 18:57:53 +00:00
) do
2017-11-22 19:04:13 +00:00
it { should_not exist }
end
2018-05-10 18:57:53 +00:00
## AWS Permissions
Your [Principal](https://docs.aws.amazon.com/IAM/latest/UserGuide/intro-structure.html#intro-structure-principal) will need the `cloudwatch:DescribeAlarmsForMetric` action with Effect set to Allow.
You can find detailed documentation at [Actions, Resources, and Condition Keys for Amazon CloudWatch](https://docs.aws.amazon.com/IAM/latest/UserGuide/list_amazoncloudwatch.html).