- Newest
- Most votes
- Most comments
Yes, you can use the Elastic Beanstalk (EB) Extensions feature to set "metric alarms" from within Beanstalk during deployment. EB Extensions allow you to run custom scripts on instances in your Elastic Beanstalk environment. You can use these scripts to set up monitoring and alarms for your instances.
To set up alarms that use the instance ID as a dimension, you can use the AWS SDK for your preferred programming language (Java, Python, etc.) in your EB Extension script to retrieve the instance ID of the instances in your environment, and then use that information to set up the alarms.
You can use the CloudWatch.Client.put_metric_alarm() method to create an alarm and set dimensions by passing them as a dictionary. example :
dimensions = [{'Name': 'InstanceId', 'Value': instance_id}]
cloudwatch.put_metric_alarm(
AlarmName='RootFilesystemUtil',
MetricName='RootFilesystemUtil',
Namespace='AWS/ElasticBeanstalk',
ComparisonOperator='GreaterThanOrEqualToThreshold',
EvaluationPeriods=1,
Period=60,
Threshold=90.0,
AlarmActions=[sns_arn],
Dimensions=dimensions
)
Alternatively, you can also use CloudFormation Custom Resources to create Alarms and pass the instance ids as parameter.
In any case, you would need to manage the lifecycle of the alarms. If an instance is terminated or replaced, you would need to delete the corresponding alarm.
Relevant content
- Accepted Answerasked 4 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 10 months ago
- AWS OFFICIALUpdated 6 months ago
Thanks for the Answer, its helpful and re-enforces some of the limitations and challenges that I have already identified. We currently have an approach using cdk and its fully automated and leverages Cloudwatch cdk directly. We plan to run overnight ci/cd scheduled task to check the diff and keep the monitoring per env or instance up to date. Would you think this approach be more robust or eb-extension scripts ? Also, just to confirm, using the approach I mentioned above in my original question, I can't directly somehow reference the instance ID, for the dimension right ?