Skip to content

Instantly share code, notes, and snippets.

@husobee
Created February 3, 2025 12:56
Show Gist options
  • Save husobee/804ad76587c6a459729ba5d724e29ba9 to your computer and use it in GitHub Desktop.
Save husobee/804ad76587c6a459729ba5d724e29ba9 to your computer and use it in GitHub Desktop.
example rollback trigger
AWSTemplateFormatVersion: "2010-09-09"
Description: "Example CloudFormation stack with rollback triggers using CloudWatch alarms"
Resources:
MyS3Bucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: !Sub "my-cloudformation-bucket-${AWS::AccountId}"
MyAlarm:
Type: "AWS::CloudWatch::Alarm"
Properties:
AlarmName: "HighCPUUsageAlarm"
ComparisonOperator: "GreaterThanThreshold"
EvaluationPeriods: 2
MetricName: "CPUUtilization"
Namespace: "AWS/EC2"
Period: 60
Statistic: "Average"
Threshold: 80
ActionsEnabled: false
AlarmDescription: "Alarm triggers when CPU utilization exceeds 80% for two consecutive periods"
Dimensions:
- Name: "InstanceId"
Value: "i-1234567890abcdef0" # Replace with actual instance ID
Unit: "Percent"
RollbackConfiguration:
RollbackTriggers:
- Arn: !GetAtt MyAlarm.Arn
Type: "AWS::CloudWatch::Alarm"
MonitoringTimeInMinutes: 10 # Rollback triggers will be monitored for 10 minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment