Sample code supporting the AWS Research Cloud initiative.
This is a CloudFormation template that deploys a Lambda function which, when triggered, looks through every region and stops (or, in the case of instance-backed instances, terminates) EC2 instances that don't have a KeepRunning tag set.
Budget Safety Switch - README.md
Budget Safety Switch - CloudFormation Template
A repackaged version of the above template using the Serverless Application Model (SAM) framework. This version also allows you to define a specific tag key/value combination for the instances you want to keep.
Budget Safety Switch (SAM) - README.md
Budget Safety Switch (SAM) - CloudFormation Template
Budget Safety Switch (SAM) - Lambda Python Code
For more information, please refer to the AWS Research Cloud Program documentation.