Skip to content

fforloff/hammertime

 
 

Repository files navigation

Build Status

codecov

hammertime

Serverless power cycling for AWS EC2 instances and Auto Scaling Groups based on a schedule.

Stop! Hammer Time!

Getting Started

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.

Usage

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.

Enabling/Disabling

You can enable/disable hammertime using the environment variable HAMMERTIME_ENABLED at the time of deployment. 'true' enables hammertime.

Dry run

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.

Deployment

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

Built With

  • serverless framework

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the releases on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

AWS EC2 Power cycling

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%