manda1238
manda1238

Reputation: 103

how to stop an EC2 instance after checking the memory utilization

I want to stop my EC2 instances if the memory utilization is more than x% from my Lambda function(python) , is their any possibility to check the memory utilization of an EC2 instance

Upvotes: 1

Views: 477

Answers (2)

Chris Williams
Chris Williams

Reputation: 35188

For EC2 by default it will only have the host level metrics be accessible, this includes CPU, Disk Performance and Network Performance but does not include other metrics such as Memory Utilization.

For this you will need to push a custom metric from the EC2 instance into AWS, this can be performed by installing the CloudWatch Agent.

Once you have the memory metric being pushed into CloudWatch you can create an alarm that will trigger on a specific threshold being exceeded, allowing you to trigger an SNS topic. This can have a Lambda subscribe to the topic to be triggered under the condition.

Upvotes: 1

Mark B
Mark B

Reputation: 200607

You need to install the CloudWatch agent on the EC2 instances, if it's not there already. Then the memory usage will be a metric in CloudWatch that your Lambda function can query.

Upvotes: 1

Related Questions