Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

EC2 Office Hours Scheduler

1. Overview

This project automates the start and stop of EC2 instances based on office hours. It:

  • Starts instances at 09:00 IST and stops them at 20:00 IST (Monday–Saturday)
  • Targets instances tagged with AutoSchedule=OfficeHours
  • Skips instances in production (Environment=prod)
  • Sends notifications to a Google Chat channel when instances are started or stopped
  • Uses Terraform for infrastructure as code and manages Lambda, EventBridge rules, IAM roles, and backend state

High level architecture details

Application Workflow

  • This flow represents what happens during periodic operations when the scheduler runs.
flowchart LR
    EventBridgeStart[EventBridge Rule<br/>Start @ 09:00 IST]
    EventBridgeStop[EventBridge Rule<br/>Stop @ 20:00 IST]

    Lambda[Lambda Function<br/>ec2-office-hours-scheduler]

    EC2[EC2 Instances<br/>Tag: AutoSchedule=OfficeHours]
    CloudWatch[CloudWatch Logs]
    GoogleChat[Google Chat Channel]

    EventBridgeStart -->|invoke| Lambda
    EventBridgeStop -->|invoke| Lambda

    Lambda -->|start / stop| EC2
    Lambda -->|logs| CloudWatch
    Lambda -->|status notification| GoogleChat

Loading

2. Pre-requisites

Before setting up this project, ensure you have:

  • AWS Account with access to EC2, Lambda, IAM, S3, CloudWatch, and DynamoDB
  • S3 bucket created for Terraform backend, e.g.:
    coloredcow-devops-aws-bucket (we will use folder ec2-office-hours-scheduler/ inside this bucket)
  • Terraform v1.5+
  • AWS CLI v2 with a named profile (coloredcow or your project name)
  • Python 3.12+ (for Lambda function)
  • macOS (or Linux) terminal
  • Google Chat room with a Webhook URL

3. Detailed Documentation

For more detailed instructions, please refer to the docs/ folder:


4. Scripts

Script Purpose
build_lambda.sh Package Lambda code into a zip (optional if using Terraform archive_file)
deploy.sh Build Lambda (optional) + Terraform apply
destroy.sh Terraform destroy for cleaning up all resources

5. Logging & Monitoring

  • Lambda logs are available in CloudWatch Logs under /aws/lambda/ec2-office-hours-scheduler
  • EventBridge triggers are set up for start (09:00 IST) and stop (20:00 IST) - (Based on the time added in the envs/common.tfvars)
  • Google Chat notifications provide immediate feedback on actions taken

6. Notes for New Developers

  • Adding new dependencies to Lambda → update lambda/requirements.txt
  • Updating schedules → modify EventBridge cron expressions in Terraform
  • Skipping production instances → controlled via SKIP_ENVIRONMENT
  • Scripts can be integrated into CI/CD pipelines

7. DevOps Learnings

This repo is a DevOps spoke of ColoredCow/coloredcow-devops — the hub that consolidates what the fleet teaches. Project-specific DevOps learnings (and the patterns harvested up to the hub) live in DEVOPS_LEARNINGS.md.

When you complete work that teaches a DevOps-function lesson — a new cost lever, a safety guard, a scoping decision, a capability gained or a gap found — record one line there in the same change as the work (backward-integration: extract from work done, never pre-write). Tag it specific (stays here) or generic (also flagged for harvest to the hub). No secrets — no webhook URL, bucket/region, account or instance IDs; teach the pattern, not the asset. See the file's header for the full ritual.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages