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.
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, 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.
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:
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
from ..ec2 import NightyNightForEc2, WakeyWakeyForEc2
class NightyNightStack(Stack):
def __init__(self, scope, id, props):
super().__init__(scope, id, props)
# The code that defines your stack goes here
NightyNightForEc2(self, "nighty-night", instance_id="i-123123123123")
WakeyWakeyForEc2(self, "wakey-wakey", instance_id="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
Hashes for mbonig.nightynight-1.89.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a77bacd04b70de1cb08ad421c8bc0d55717e5308323d0d8276df81a2b58c5146 |
|
MD5 | 3060aaf0e85782be1ab24c31f3581bbd |
|
BLAKE2b-256 | 77267428e5d1c419f3ad2e0d4ffff3545c929a29d8d5ed0bdf3214a8de1f1840 |
Hashes for mbonig.nightynight-1.89.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b815289049d843f8152eca264dc8cd0bf489dddb964b83cb42005d7f1ac8da29 |
|
MD5 | e4d2249d9a4cc2dfdbf49d721d6d6c13 |
|
BLAKE2b-256 | 08dc561e5ece3b22d9ee92b7740d9a23fbd3ef3de69a64e712f08ef143abe68f |