Skip to content

Instantly share code, notes, and snippets.

View heidemn-faro's full-sized avatar

M. Heide heidemn-faro

  • FARO Scanner Production GmbH
View GitHub Profile
@tteskac
tteskac / simple-ec2-scheduler.js
Last active March 21, 2024 15:35
Simple EC2 scheduler with AWS Lambda function (start during working hours only, stop otherwise)
// Simple EC2 scheduler with AWS Lambda (NodeJs) function (start during working hours only, stop otherwise).
// https://gist.github.com/tteskac/0ab34617652433d70b8fc59eb444a85f
//
// The example code below checks if specific EC2 instance should be running or be stopped to save money.
// This is extremely useful e.g. for development/testing instances to be running only during working hours.
// Below in the code it is specified to run it Monday-Friday between 5-16 (UTC).
// In addition, it will not shutdown the instance if the CPU usage is above idle state,
// e.g. if someone is still using it a bit more outside working hours or some long processing is still happening.
// Use EventBridge (CloudWatch Events) to trigger this lambda function every hour.
//