CloudWatch Alarms
Backup & Restoration Guide
There is no native AWS backup feature for CloudWatch alarms.
As of writing, AWS does not have a native solution for this use case, so a custom automation has to be written. Before you start, make sure you:
- Only back up alarms that monitor active resources.
- Confirm the alarm configuration is correct.
- Use IaC for the restoration. It lowers administration effort and makes future deployments more flexible.
1.1 Confirm Alarms Managed by IaC
Identify IaC-managed alarms before deleting any resources.
These should be excluded from the backup/restore operation to avoid drift.
Tags added automatically by IaC tools
| Tool | Tags |
|---|---|
| CloudFormation | aws:cloudformation:stack-name aws:cloudformation:stack-id aws:cloudformation:logical-id |
| AWS CDK | Same as CloudFormation, since CDK deploys through it. The aws:cdk:path value lives in template metadata, not in resource tags. |
| AWS SAM | lambda:createdBy = SAM on Lambda functions, plus the CloudFormation tags |
| Service Catalog | aws:servicecatalog:provisionedProductArn aws:servicecatalog:productArn aws:servicecatalog:portfolioArn aws:servicecatalog:provisioningPrincipalArn |
| Elastic Beanstalk | elasticbeanstalk:environment-name elasticbeanstalk:environment-id, plus the CloudFormation tags |
| AWS Copilot | copilot-application copilot-environment copilot-service, plus the CloudFormation tags |
| No matching rows | |
Tags only added by convention (not automatic)
- Terraform: adds no tags by default. Teams usually set them with the provider's
default_tagsblock, for exampleManagedBy = "Terraform",terraform = "true", or a pointer to the state or workspace. The authoritative record is the state file, not tags.
Caveats when you use tags for detection
- Tags only show up on resource types that support tagging. Some resources a stack creates won't carry them.
- If nothing is tagged, that doesn't mean it isn't IaC-managed. Terraform and Pulumi resources look the same as hand-made ones unless you tagged them.
- To find tagged resources across an account, use the Resource Groups Tagging API or Tag Editor:
SHELL
% aws resourcegroupstaggingapi get-resources \
--tag-filters Key=aws:cloudformation:stack-name
- For CloudFormation,
describe-stack-resourcesis more reliable than tags:
SHELL
% aws cloudformation describe-stack-resources --stack-name <stack-name>
1.2 Inventory CloudWatch Alarms
- AWS-managed alarms (e.g. Auto Scaling, Application Insights) are created, modified and deleted by an AWS service.
- These are out of scope for backup.
- Exclude any alarms monitoring out-of-scope workloads or terminated resources.
- Review any alarms in
INSUFFICIENT_DATAstate. These may point to:- terminated resources
- misconfigured alarms
- Review any alarms monitoring resources that scale (e.g. EC2, EKS).
- These may be host- or node-level alarms.
- A
Dimensionidentifies a unique resource (e.g. EC2 Instance ID) that may change when the workload is launched in a different account or region. - Consider creating CloudWatch Alarms based on Metrics Insights.
- Metrics Insights alarms use a query to isolate the target resources. Even as the workload scales, they keep monitoring the underlying resources.
- An individual Metrics Insights alarm can monitor multiple resources and reduce the number of alarms required.
- Finalize the list of alarms to be backed up.
1.3 Retrieve Alarm Configuration
- Once the target alarms have been properly scoped, retrieve the active alarm configuration with the DescribeAlarms API.
1.4 Retrieve Alarm Actions Configuration
- Identify the SNS topics, Lambda functions, etc. invoked by CloudWatch alarms.
- Determine whether the SNS topics can be consolidated into fewer topics.
- Retrieve the resource configuration.
1.5 Build New IaC Template
- Incorporate the alarm action resource types (e.g. aws_lambda_function, aws_sns_topic) directly into the IaC template.
- In this way, they are available to the newly created alarms.
- Add relevant tags for
Name,Owner,Application, andCostCenter, which assist with cost allocation and incident response. - If applicable, add the IaC tags
ManagedBy = "Terraform"andterraform = "true". - CloudFormation AWS::CloudWatch::Alarm and Terraform aws_cloudwatch_metric_alarm resource types accept most of the DescribeAlarms output as input parameters.
- For one-off situations, a coding agent can be used to:
- Create a Lambda function that generates the CloudWatch alarm inventory.
- Create a Lambda function that accepts a CSV list of alarms and alarm actions.
- Generate the IaC template.
- Alternatively, an agent could be built to perform the same operations.
2.1 Deploy IaC Template
- Deploy using AWS CDK, CloudFormation, SAM or Terraform.
2.2 Inventory Newly Created Alarms
- Confirm no alarms are in
INSUFFICIENT_DATAstate. - Ideally, all alarms should report
OKstate. - Inspect alarms configured with
TreatMissingDataasnotBreachingmore closely.- These alarms are event-driven (e.g. alerting on
Errors,HTTP 5XX). - Consequently, under normal circumstances no metric data is expected and the alarm will report
OK. - It is less obvious when these alarms are misconfigured.
- These alarms are event-driven (e.g. alerting on
2.3 CloudWatch: Output Active Alarms
- Programmatically compare the resources created by Terraform against the active CloudWatch alarms.
SHELLterraform output
% terraform output
alarm_arns = {
"Duration" = "arn:aws:cloudwatch:us-east-1:123456789012:alarm:Synthetics-Alarm-visual-monitor-standalone-Duration"
"Failed" = "arn:aws:cloudwatch:us-east-1:123456789012:alarm:Synthetics-Alarm-visual-monitor-standalone-Failed"
"SuccessPercent" = "arn:aws:cloudwatch:us-east-1:123456789012:alarm:Synthetics-Alarm-visual-monitor-standalone-SuccessPercent"
}
alarm_names = [
"Synthetics-Alarm-visual-monitor-standalone-Duration",
"Synthetics-Alarm-visual-monitor-standalone-Failed",
"Synthetics-Alarm-visual-monitor-standalone-SuccessPercent",
]
sns_topic_arn = "arn:aws:sns:us-east-1:123456789012:Synthetics-Visual-Monitor-Alarm"
SHELLdescribe-alarms
# Outputs Alarm Names, Actions ARNs, Alarm State
% aws cloudwatch describe-alarms --region us-east-1 \
--alarm-name-prefix Synthetics-Alarm-visual-monitor \
--query 'MetricAlarms[].{Name:AlarmName,State:StateValue,Actions:AlarmActions}' \
--output table
--------------------------------------------------------------------------
| DescribeAlarms |
+--------------------------------------------------------------+---------+
| Name | State |
+--------------------------------------------------------------+---------+
| Synthetics-Alarm-visual-monitor-standalone-Duration | ALARM |
+--------------------------------------------------------------+---------+
|| Actions ||
|+----------------------------------------------------------------------+|
|| arn:aws:sns:us-east-1:123456789012:Synthetics-Visual-Monitor-Alarm ||
|+----------------------------------------------------------------------+|
| DescribeAlarms |
+-------------------------------------------------------------+----------+
| Name | State |
+-------------------------------------------------------------+----------+
| Synthetics-Alarm-visual-monitor-standalone-Failed | OK |
+-------------------------------------------------------------+----------+
|| Actions ||
|+----------------------------------------------------------------------+|
|| arn:aws:sns:us-east-1:123456789012:Synthetics-Visual-Monitor-Alarm ||
|+----------------------------------------------------------------------+|
| DescribeAlarms |
+--------------------------------------------------------------+---------+
| Name | State |
+--------------------------------------------------------------+---------+
| Synthetics-Alarm-visual-monitor-standalone-SuccessPercent | ALARM |
+--------------------------------------------------------------+---------+
|| Actions ||
|+----------------------------------------------------------------------+|
|| arn:aws:sns:us-east-1:123456789012:Synthetics-Visual-Monitor-Alarm ||
|+----------------------------------------------------------------------+|
2.4 SNS: Confirm Subscription Status
- By default, SNS subscriptions reflect the
PendingConfirmationstate until the email confirmation link is clicked.
Pending subscriptions receive nothing.
If an SNS subscription remains in
PendingConfirmation, CloudWatch alarm notifications will not be delivered.
SHELLlist-subscriptions-by-topic
% aws sns list-subscriptions-by-topic --region us-east-1 \
--topic-arn "$(terraform output -raw sns_topic_arn)"
{
"Subscriptions": [
{
"SubscriptionArn": "PendingConfirmation",
"Owner": "123456789012",
"Protocol": "email",
"Endpoint": "devteam@example.com",
"TopicArn": "arn:aws:sns:us-east-1:123456789012:Synthetics-Visual-Monitor-Alarm"
}
]
}
2.5 Validate Alarm Actions
- Use the SetAlarmState API to confirm alarm actions trigger as expected.
state-reason-datacan be injected into the alarm trigger.
SHELLset-alarm-state
# Include structured detail in the notification (must be valid JSON)
% aws cloudwatch set-alarm-state --region us-east-1 \
--alarm-name "Synthetics-Alarm-visual-monitor-standalone-Duration" \
--state-value ALARM \
--state-reason "Restore validation: testing alarm actions" \
--state-reason-data '{"test":"restore-validation","ticket":"CHG-12345"}'
- Retrieve the latest alarm history items to confirm the alarm triggered and the actions were executed.
SHELLdescribe-alarm-history
# Confirm the state change and that the action ran
% aws cloudwatch describe-alarm-history --region us-east-1 \
--alarm-name "Synthetics-Alarm-visual-monitor-standalone-Duration" \
--history-item-type Action \
--max-items 2
- Programmatically confirm the injected
state-reason-datais found in the alarm history.
OUTPUTalarm history
2026-11-11 22:34:01 Action Successfully executed action arn:aws:sns:us-east-1:123456789012:Synthetics-Visual-Monitor-Alarm
2026-11-11 22:34:01 State update Alarm updated from OK to In alarm.