We have a script to stop ec2 instances using python script based on tags.
Prerequisites
-
An AWS Account with An IAM User with IAM, Lambda, EC2 Access
-
Serverless framework installed
Launch EC2 instances
Launch instances and add tags, if instances already exists just add ec2: stop tags to instances.
Note: You may give your own tags
Here we have achieved this by Serverless Framework
Steps to Proceed
-
Clone the code in your local machine
-
Change the code as per your requirement
-
Deploy your code by below command and ensure that you have installed serverless framework in your local machine.
sls deploy --region --aws-profile --stage dev
Resource clean up that you did through Serverless
sls remove --region --aws-profile --stage dev
Happy Coding!!!!