Serverless power cycling for AWS EC2 instances and Auto Scaling Groups based on a schedule.
Edit serverless.yml where you can adjust
- scheduled run time,
- deployment s3 bucket (can be set as
DEPLOY_BUCKET
env var), - AWS region,
- stage between dev/test/production/other (can be set as
SLICE
env var), - anything else which takes your fancy.
To stop hammertime
- killing your EC2 instance tag with
hammertime:canttouchthis
- spinning your ASG down to 0 tag the ASG with
hammertime:canttouchthis
stop-hammertime
will stop all EC2 instances that are not tagged with hammertime:canttouchthis
and are not in an ASG. It will also set the desired instance count of all ASGs not tagged likewise to 0.
start-hammertime
will query the tags left by stop-hammertime
and return the instances and ASGs to their previous status.
Hammertime is intended to be run in response to a Lambda scheduled event, e.g
stop-hammertime
: run Monday-Friday at 6PM
start-hammertime
: run Monday-Friday at 6AM
Note when constructing schedule events in AWS, that times are in UTC.
You can enable/disable hammertime using the environment variable HAMMERTIME_ENABLED
at the time of deployment. 'true' enables hammertime.
Hammertime has a dry-run feature for when you are not quite ready to unleash the hammer pants on your entire fleet of EC2s just yet.
By setting HAMMERTIME_DRY_RUN
to 'true', you enable dry-run in which hammertime does not touch your EC2s but will still log what it would have touched.
Refer to the serverless framework for detailed instructions, but should be as simple as
- Install dependencies
npm i
-
Authenticate with AWS via your favourite CLI
-
then deploy
npm deploy
- serverless framework
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the releases on this repository.
- Ian Donaldson - Initial work - Ian Donaldson
- Hailey Martin - Made it work - Hailey Martin
- Kurt Gardiner - Busy work - Kurt Gardiner
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details