- Auto-start-stop-instance(EC2,RDS)-cdk-template
- you can reduce costs by stopping instances(EC2,RDS) while not in use
- you can choice configure to suit your case
- only ec2 instance,rds cluster etc
- multiple ec2 and rds instances support
- you can notice to slack optionaly
git clone https://github.com/wano/auto-startstop-instance-cdk-template.git
- Note that the crone time is set in UTC
| ec2 | rds(cluster) | rds(instance) | Slack Notification | |
|---|---|---|---|---|
| case1 | ◯ | ◯ | ◯ | ◯ |
| case2 | ◯ | ◯ | ◯ | |
| case3 | ◯ |
- case1
{
"events": {
"cron": {
"start": "00 00 ? * MON-FRI *",
"stop": "00 11 ? * * *"
}
},
"targets": {
"ec2region": "your_region",
"instanceNames": ["your_instance_name_1","your_instance_name_ 2"],
"dbClusterIdentifies": ["your_cluster_name_1"],
"dbInstanceIdentifies": ["your_db_instance_name_1","your_db_instance_name_ 2"]
},
"slack": {
"webHookUrl":"https://hooks.slack.com/services/xxxxxxxxx/xxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxx",
"channel":"xxxxxxxxxxxxxx"
}
}- case2
{
"events": {
"cron": {
"start": "00 00 ? * MON-FRI *",
"stop": "00 11 ? * * *"
}
},
"targets": {
"ec2region": "your_region",
"instanceNames": ["your_instance_name_1","your_instance_name_ 2"],
"dbClusterIdentifies": [""],
"dbInstanceIdentifies": ["your_db_instance_name_1","your_db_instance_name_ 2"]
},
"slack": {
"webHookUrl":"https://hooks.slack.com/services/xxxxxxxxx/xxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxx",
"channel":"xxxxxxxxxxxxxx"
}
}- case3
{
"events": {
"cron": {
"start": "00 00 ? * MON-FRI *",
"stop": "00 11 ? * * *"
}
},
"targets": {
"ec2region": "ap-northeast-1",
"instanceNames": [""],
"dbClusterIdentifies": ["your_cluster_name_1"],
"dbInstanceIdentifies": [""]
},
"slack": {
"webHookUrl":"",
"channel":""
}
}npm install -g aws-cdk
cd ./auto_start_stop_instance_cdk
npm install @aws-cdk/core
npm install @aws-cdk/aws-lambda @aws-cdk/aws-iam @aws-cdk/aws-events @aws-cdk/aws-events-targets
npm run build
export AWS_ACCESS_KEY_ID="xxxxxxxxxxx"
export AWS_SECRET_ACCESS_KEY="xxxxxxxxxxx"
cdk bootstrap
cdk deploy
Following events already tested
- All start(EC2,RDS)
- All stop(EC2,RDS)
- EC2Instance and DBInstance start
- Only EC2Instance start and not notice to slack
- MacOS Mojave version 10.14.6
- Go 1.12.4
- TypeScript 3.6.2
- CDK z1.6.0