Skip to content
Menu
myCloud myCloud

Personal short notes about Cloud

  • XMPie
  • AWS
    • AWS Topics
    • AWS Architecture
    • AWS CLI
    • AWS Health
    • AWS Policies
    • AWS Cost
  • CHEAT SHEETS
myCloud myCloud

Personal short notes about Cloud

AWS Instance Scheduler

By mikado on March 12, 2022September 30, 2022

Schedule and automate custom start & stop of EC2 and RDS instances, by setting tags.

Cross accounts, cross regions

Set a “master” and “remotes” to use tags in additional accounts

CloudFormation templates

instance-scheduler.template
instance-scheduler-remote.template

Services used

  • CloudWatch
  • Lambda
  • DynamoDB
  • IAM
  • SNS
  • KMS
  • EC2 / RDS

Solution

We configure a CloudWatch event that triggers a λ function to start or stop EC2/RDS instances at pre-configured intervals.

  • λ checks the current state of each tagged instance against the targeted state defined in the associated schedule in DynamoDB.
  • λ records:
    • The name of the schedule
    • the number of instances associated with that schedule
    • the number of running instances (as an optional custom metric in CW)
    • Can be multi regions and cross accounts.

DynamoDB tables

ConfigTable

  • 1 config item (stores cross_account_roles, regions tagnames)

  • schedule items (includes the periods used, time zone)

  • period items (store weekdays, begin & end time)

StateTable

  • states every single tagged resource (either EC2 or RDS)

Adding a tag

  • Make sure the account is added to the master account (CloudFormation parameters)
  • Make sure the region is added/active (CloudFormation parameters)
  • Duplicate and set a new Period
  • Create a new schedule using the new Period
Category: AWS Topics

Categories

  • AWS (4)
  • AWS Architecture (8)
  • AWS CLI (5)
  • AWS Cost (3)
  • AWS Health (4)
  • AWS Policies (2)
  • AWS Topics (24)
  • CHEAT SHEETS (16)
  • Container (21)
  • Datadog (4)
  • Jenkins (2)
  • Linux (9)
  • Microsoft (7)
  • Python (1)
  • SCRIPTS (9)
  • Terraform (5)
  • XMPie (6)
©2025 myCloud
Click to Copy