Set up CloudWatch monitoring and alarms
✓Works with OpenClaudeYou are an AWS CloudWatch expert. The user wants to set up CloudWatch monitoring and alarms to track metrics, detect anomalies, and trigger notifications.
What to check first
- Verify AWS CLI is installed and configured:
aws sts get-caller-identity - Confirm IAM permissions include
cloudwatch:PutMetricAlarm,cloudwatch:PutMetricData, andsns:Publish - Check if SNS topic exists for notifications:
aws sns list-topics
Steps
- Create an SNS topic for alarm notifications using
aws sns create-topic --name cloudwatch-alarms - Subscribe your email to the SNS topic:
aws sns subscribe --topic-arn arn:aws:sns:region:account:cloudwatch-alarms --protocol email --notification-endpoint your-email@example.com - Confirm the SNS subscription by clicking the email link AWS sends
- Identify the metric namespace and dimensions for your resource (e.g.,
AWS/EC2for EC2 instances) - Create a threshold alarm using
PutMetricAlarmthat triggers when a metric exceeds a statistic over a specified period - Set the
ComparisonOperator(GreaterThanThreshold, LessThanThreshold, etc.) andEvaluationPeriods(consecutive periods before alarm triggers) - Bind the alarm to your SNS topic in the
AlarmActionsparameter so notifications are sent when the alarm state changes - Test the alarm by publishing a test metric:
aws cloudwatch put-metric-data --metric-name TestMetric --value 100
Code
import boto3
from datetime import datetime
cloudwatch = boto3.client('cloudwatch')
sns = boto3.client('sns')
# Step 1: Create SNS topic (if not exists)
topic_response = sns.create_topic(Name='cloudwatch-alarms')
topic_arn = topic_response['TopicArn']
print(f"SNS Topic ARN: {topic_arn}")
# Step 2: Create a high CPU alarm for EC2 instance
cloudwatch.put_metric_alarm(
AlarmName='High-CPU-Usage-Production',
ComparisonOperator='GreaterThanThreshold',
EvaluationPeriods=2,
MetricName='CPUUtilization',
Namespace='AWS/EC2',
Period=300, # 5 minutes
Statistic='Average',
Threshold=80.0,
ActionsEnabled=True,
AlarmActions=[topic_arn],
AlarmDescription='Alert when EC2 CPU exceeds 80% for 10 minutes',
Dimensions=[
{
'Name': 'InstanceId',
'Value': 'i-0123456789abcdef0' # Replace with your instance ID
}
]
)
print("CPU
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Cloud (AWS/GCP/Azure) Skills
Other Claude Code skills in the same category — free to download.
Lambda Function
Create AWS Lambda function with handler
S3 Operations
Set up S3 bucket operations (upload, download, presigned URLs)
DynamoDB CRUD
Create DynamoDB CRUD operations
SQS Setup
Set up SQS queue producer and consumer
SNS Notifications
Configure SNS for push notifications
CloudFront Setup
Set up CloudFront CDN distribution
Cognito Auth
Implement AWS Cognito authentication
RDS Setup
Configure RDS database connection
Want a Cloud (AWS/GCP/Azure) skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.