A CDK construct that will automatically stop a running EC2 instance at a given time.
Project description
NightyNight and WakeyWakey!
Do you have a EC2 instance or an RDS instance that you only need during certain hours of the day? Do you want to reduce it's cost? How about just stopping it every night?
That's the NightyNight construct. It's very simple. Give it an instanceId
and it will create a Lambda and a CloudWatch Event Rule to fire the lambda at a specific time of day. If the instance is running, it's stopped.
There are currently two variations of the construct:
- NightyNightForEc2 - stops an EC2 instance at a given time.
- NightyNightForRds - stops an RDS instance at a given time.
- NightyNightForAsg - sets the desired capacity for an ASG at a given time.
- NightyNightForEcs - sets the desired capacity for an ECS service at a given time.
WakeyWakey
The WakeyWakey construct (from this repository) has been integrated into this library. You don't need to install a separate dependency anymore.
- WakeyWakeyForEc2 - start an EC2 instance at a given time.
- WakeyWakeyForRds - start an RDS instance at a given time.
There isn't a specific construct for starting ASGs or ECS services, since you can just set the count to whatever you want.
This is a pre-release!
This is a quick first-draft. All the options that will likely need to be added to accommodate a large number of use-cases are still needed. If you'd like to make requests or help update this construct, please open an Issue or a PR.
There are multiple versions of this library published. You should be using the v0.X.X versions for now. There are versions published that match the CDK version they depend on, but don't use those.
What it creates
- A Rule that will, on a given schedule, fire a lambda.
- A Lambda with permissions to describe ec2 instances. It will read the instance by the given
instanceId
and then stop the instance if it's in a running state.
Example:
import {NightyNightForEc2, WakeyWakeyForEc2} from "./ec2";
export class NightyNightStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps) {
super(scope, id, props);
// The code that defines your stack goes here
new NightyNightForEc2(this, 'nighty-night', {instanceId: 'i-123123123123'});
new WakeyWakeyForEc2(this, 'wakey-wakey', {instanceId: 'i-123123123123'})
}
}
This will stop the instance with id i-123123123123
at (the default) 4am UTC. It will then start the instance at 12am UTC.
API Doc
See the API Docs for more info.
Contributing
Please open Pull Requests and Issues on the Github Repo.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mbonig.nightynight-2.0.3.tar.gz
.
File metadata
- Download URL: mbonig.nightynight-2.0.3.tar.gz
- Upload date:
- Size: 27.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02474109d635359819ec2228e5caa8c44ffdf0b763ad2cb9aaa58270d8bc3404 |
|
MD5 | e124cc9c2ad89c492094c7a40c33173a |
|
BLAKE2b-256 | b17e496760375d142b7bf58fd14ec148d588bb140bdd97b16036a957e4b3dec5 |
File details
Details for the file mbonig.nightynight-2.0.3-py3-none-any.whl
.
File metadata
- Download URL: mbonig.nightynight-2.0.3-py3-none-any.whl
- Upload date:
- Size: 27.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93c06ab02cd634579b7d9beba252575f7040e75a90d4049c475551b13e8f8f7c |
|
MD5 | 71d4e81ebb5d83893c40f03c2ef72d1c |
|
BLAKE2b-256 | f5238c2e14233cd39a723731aba1f34c464807dfba7678e54bec53bcd0e6fff7 |