- Newest
- Most votes
- Most comments
To set up alerts for EC2 capacity errors when provisioning instances, you can use CloudWatch alarms with On-Demand Capacity Reservations (ODCR) monitoring. This approach will help you track capacity utilization and receive notifications when capacity issues might occur.
Here's how to set up the alert:
-
First, you'll need to create a CloudWatch alarm that monitors capacity utilization metrics. AWS provides CloudWatch dimensions specifically for monitoring ODCR, which can help you track capacity by AvailabilityZone, InstanceType, and other dimensions.
-
You can use a Python script to set up the alarm with the following parameters:
- Dimension: AvailabilityZone (to monitor capacity in specific zones)
- MetricName: InstanceUtilization
- ComparisonOperator: LessThanOrEqualToThreshold
- Threshold: 75.0 (or another value that makes sense for your use case)
- Protocol: email (for notifications)
- TopicName: EC2CapacityErrorAlerts (or your preferred name)
- Run the Python script with your desired parameters:
python3 by_availabilityZone.py --RegionName <your-region> --EmailAddress <your-email> --AvailabilityZone <your-az>
- This will create an SNS topic that will send you email notifications when the alarm is triggered.
Alternatively, you can create status check alarms through the EC2 console:
- Open the Amazon EC2 console
- Navigate to Instances
- Select your instance
- Go to the Status Checks tab
- Choose Actions, then Create status check alarm
- Configure the alarm notification with your email address
- Set the appropriate alarm thresholds for your use case
When you receive an "Insufficient capacity" error, it means AWS doesn't have enough available On-Demand capacity to fulfill your request in that specific Availability Zone. By setting up these alerts, you'll be notified before capacity becomes critically low, allowing you to take proactive measures such as:
- Trying different instance types
- Launching instances in different Availability Zones
- Adjusting your provisioning schedule to times when capacity is more likely to be available
This monitoring approach will help you anticipate and mitigate capacity issues before they impact your daily EC2 provisioning scripts.
Sources
Efficiently monitor your On Demand Capacity Reservations (ODCR) by Grouping on CloudWatch Dimensions | AWS Compute Blog
Efficiently monitor your On Demand Capacity Reservations (ODCR) by Grouping on CloudWatch Dimensions | AWS Storage Blog
Create CloudWatch alarms for Amazon EC2 instances that fail status checks - Amazon Elastic Compute Cloud
insufficient capacity | AWS re:Post
EC2 - out of capacity | AWS re:Post
answered a year ago
