Search code examples
amazon-web-servicesautoscalingamazon-ebsamazon-cloudwatch

Attach EBS volume to EC2 instance when cloudwatch alarm triggers


I have a business case when an EC2 instance runs out of space, we need to spawn new EBS volume, attach it to EC2 instance and format it.

I have created one cron job which keeps sending disk usage to cloud watch and trying to create one alarm this custom metric.

Now I am not able to find out any information regarding how to spawn an EBS volume when this alarm triggers.

So I would like to know if it is it possible to spawn EBS volume when cloudwatch alarm triggers? If yes, please give some steps or point to the document where I can find this information.

As if now all I have found out is that we can either spawn new instances or send some emails whenever alarm triggers.


Solution

  • You can fire an notification to an SNS topic when the CloudWatch alarm fires, and have a SQS queue as a subscriber to that topic. Then, an EC2 instance consuming that SQS queue can perform the desired change using the AWS CLI or SDKs.