Ravi Patel
Ravi Patel

Reputation: 11

how to stop our instance if idle for 30 min in aws cloud watch

I have setup aws cloud watch

Here is below detail set in our cloud watch

EC2 action:

After 5 min our server still does not stop with the cloud watch in aws.

enter image description here

Upvotes: 1

Views: 1138

Answers (3)

x89
x89

Reputation: 3460

You can create an SQS queue whose target is a Python Lambda function. The python lambda function can use boto to turn off the ec2 instance.

Then you can set this SQS as an alarm action for your Cloudwatch Alarm. You can find more details here:

https://medium.com/geekculture/automatically-turn-off-ec2-instances-upon-inactivity-31fedd363cad

Terraform setup:

https://medium.com/geekculture/terraform-setup-for-automatically-turning-off-ec2-instances-upon-inactivity-d7f414390800

Upvotes: 1

Impermanence
Impermanence

Reputation: 184

At Feb 2022 you have these options:

  1. You can use Alarms to automate shutdown and terminate instances:

https://aws.amazon.com/blogs/aws-cloud-financial-management/launch-resource-optimization-recommendations/

  1. You can view idle instances in CUR recommendations : https://aws.amazon.com/about-aws/whats-new/2013/01/08/use-amazon-cloudwatch-to-detect-and-shut-down-unused-amazon-ec2-instances/

Upvotes: 2

Raul Barreto
Raul Barreto

Reputation: 1124

You can use CloudWatch Events to trigger a Lambda that will perform the stop instance call on the ec2 instance.

Upvotes: 0

Related Questions