DevOps / Scripts
bash
Intermediate
New
AWS EC2 Instance Scheduler
Stop and start EC2 instances by tag to save costs outside business hours.
bash
#!/bin/bash
ACTION=${1:-stop}
TAG_KEY=AutoSchedule
TAG_VALUE=true
IDS=$(aws ec2 describe-instances \
--filters "Name=tag:$TAG_KEY,Values=$TAG_VALUE" "Name=instance-state-name,Values=running,stopped" \
--query "Reservations[].Instances[].InstanceId" --output text)
if [ -z "$IDS" ]; then echo "No instances found."; exit 0; fi
aws ec2 ${ACTION}-instances --instance-ids $IDS
echo "$ACTION: $IDS"
Prerequisites
- aws-cli v2
- EC2 permissions
Pro Tips
- → Schedule with EventBridge Rules: stop at 20:00, start at 08:00 weekdays.
Commercial Licensing
Acquire a production access token or template license for enterprise deployment.
Module Info
- Language
- bash
- Level
- Intermediate
- Read time
- 3 min
- Published
- Sep 2026
- License
- Commercial License
Newsletter
New modules every week, directly to your inbox.
Similar Modules
Postgres S3 Backup
Dump a Postgres database, gzip it, push to S3 with AES256 encryption.
bash
·
Intermediate
Disk Usage Alert
Send an alert when any mounted filesystem exceeds a usage threshold.
bash
·
Beginner
Docker Image Cleanup Script
Remove dangling images, stopped containers and unused volumes in one pass.
bash
·
Intermediate