Automatically Turn Off EC2 Instances Upon Inactivity
Stopping your EC2 instances when they’re not actually being used can help you or your company cut down on costs. For example, if you are running a Tableau server on your EC2 instance, you might want to turn it off whenever there are no active sessions for a certain time period.
Lambda
The first step would be to setup a Lambda function that can turn off specified ec2 instance(s). It can be as simple as this:
Note that your Lambda function also needs to have all the necessary permissions for example to access EC2.
SNS Queue
AWS Simple Notification Service is a fully managed pub/sub messaging service. Amazon SNS supports Lambda functions as a target for messages sent to a topic. This means that you can process your SNS notifications via a Lambda function by subscribing your function to an SNS topic.
To begin with, first head to AWS SNS and create a topic.