Skip to main content

AWS Resource Scheduler

AWS Resource Scheduler is an open-source Python module that automates the start and stop operations for various AWS resources, including EC2 instances, Auto Scaling Groups (ASG), ECS services, RDS databases, and Aurora clusters.

Features

  • Create a bundle of resources using names or tags that need to be started or stopped for a project or team.
  • Combine resources from multiple regions or accounts.
  • The application checks for resources to become healthy before moving to the next resource, allowing you to decide the sequence and dependency of resources.
  • Doesn't require any changes to Tags or infrastructure, making it compatible with resources managed by IaC tools like CDK or Terraform.
  • Start and stop AWS resources like EC2 instances, RDS databases, Aurora clusters.
  • Scale up and down Auto Scaling Groups and ECS services.
  • Schedule operations based on predefined configurations.
  • Send notifications to Google Chat, Slack, or Microsoft Teams.

Installation

pip install aws-resource-scheduler

Configuration

Create a configuration like below, based on your need. You can keep more then workload in the same file an decide which one to use for the action.

workspaces:
  stage:
    aws_region: us-west-2
    role_arn: arn:aws:iam::123456789012:role/SchedulerRole
    storage:
      method: parameter_store  # Options: 'parameter_store' or 'dynamodb' to store last min,max,desire value for ecs and asg
      dynamodb_table: 'ResourceSchedulerTable'  # Required if method is 'dynamodb'
    notification:
      enable: true
      platform: google
      webhook_url: https://chat.googleapis.com/v1/spaces/XXX/messages?key=YYY&token=ZZZ
    ec2:
      name:
      - instance1
      - instance2
      tags:
        Environment: development
    asg:
      name:
      - asg1
      - asg2
    ecs:
      my-cluster:
      - service2
        services:
         - service1
       tags:
         name: service2
    rds:
      name:
      - db-instance1
      - db-instance2
    aurora:
      name: 
      - aurora-cluster1
      tags:
        Environment: development

Use service like YAML Checker https://yamlchecker.com to validate your yml config. Also use the status action to make sure that you are targeting correct resource with tags config.

Arguments

-f, --filename: The configuration file -w, --workspace: The workspace to use from the config file -r, --resource: Comma-separated list of AWS resources (e.g., ec2, rds, asg, ecs, aurora) -a, --action: The action to perform (start, stop, status) -n, --no-wait: Do not wait for resources to reach desired state after starting or stopping -t, --threads: Number of threads to use for parallel operations (default: 10)

Example Usage

To stop EC2 instances, ASG, and ECS services in the stage workspace:

aws-resource-scheduler -f config-stage.yml -w stage -r ec2,rds,asg,ecs -a stop

To start EC2 instances, ASG, and ECS services:

aws-resource-scheduler -f config-stage.yml -w stage -r ec2,asg,ecs -a start

IAM Role and Permission

To securely interact with AWS resources, create an IAM role with the necessary permissions. Follow these steps:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "SSMDescribeParameters",
            "Effect": "Allow",
            "Action": [
                "ssm:DescribeParameters"
            ],
            "Resource": "*"
        },
        {
            "Sid": "SSMGetPutParameters",
            "Effect": "Allow",
            "Action": [
                "ssm:GetParameter",
                "ssm:PutParameter"
            ],
            "Resource": "arn:aws:ssm:*:*:parameter/scheduler/*"
        },
        {
            "Sid": "EC2DescribeInstances",
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeInstances",
                "ec2:DescribeTags"
            ],
            "Resource": "*"
        },
        {
            "Sid": "EC2StartStopInstances",
            "Effect": "Allow",
            "Action": [
                "ec2:StartInstances",
                "ec2:StopInstances"
            ],
            "Resource": "*"
        },
        {
            "Sid": "RDSDescribeInstances",
            "Effect": "Allow",
            "Action": [
                "rds:DescribeDBInstances",
                "rds:ListTagsForResource"
            ],
            "Resource": "*"
        },
        {
            "Sid": "RDSStartStopInstances",
            "Effect": "Allow",
            "Action": [
                "rds:StartDBInstance",
                "rds:StopDBInstance"
            ],
            "Resource": "arn:aws:rds:*:*:db:*"
        },
        {
            "Sid": "RDSDescribeClusters",
            "Effect": "Allow",
            "Action": [
                "rds:DescribeDBClusters",
                "rds:ListTagsForResource"
            ],
            "Resource": "*"
        },
        {
            "Sid": "RDSStartStopClusters",
            "Effect": "Allow",
            "Action": [
                "rds:StartDBCluster",
                "rds:StopDBCluster"
            ],
            "Resource": "arn:aws:rds:*:*:cluster:*"
        },
        {
            "Sid": "AutoScalingDescribe",
            "Effect": "Allow",
            "Action": [
                "autoscaling:DescribeAutoScalingGroups",
                "application-autoscaling:DescribeScalableTargets",
                "application-autoscaling:RegisterScalableTarget",
                "application-autoscaling:DeregisterScalableTarget",
                "application-autoscaling:DescribeScalingPolicies",
                "application-autoscaling:PutScalingPolicy"
            ],
            "Resource": "*"
        },
        {
            "Sid": "AutoScalingUpdateGroups",
            "Effect": "Allow",
            "Action": [
                "autoscaling:UpdateAutoScalingGroup"
            ],
            "Resource": "arn:aws:autoscaling:*:*:autoScalingGroup:*:autoScalingGroupName/*"
        },
        {
            "Sid": "ECSDescribeServices",
            "Effect": "Allow",
            "Action": [
                "ecs:DescribeServices",
                "ecs:ListTagsForResource",
                "ecs:ListServices"
            ],
            "Resource": "*"
        },
        {
            "Sid": "ECSUpdateServices",
            "Effect": "Allow",
            "Action": [
                "ecs:UpdateService"
            ],
            "Resource": "arn:aws:ecs:*:*:service/*"
        },
        {
          "Sid": "DynamodbStorage",
          "Effect": "Allow",
          "Action": [
            "dynamodb:PutItem",
            "dynamodb:GetItem",
            "dynamodb:UpdateItem"
          ],
        "Resource": "arn:aws:dynamodb:*:*:table/ResourceSchedulerTable"
        }
    ]
}

You can use Start and stop actions are allowed only on instances tagged with scheduler=true. Other Services (RDS, Auto Scaling Groups, ECS): Similar tag-based restrictions are applied.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "EC2StartStopInstances",
            "Effect": "Allow",
            "Action": [
                "ec2:StartInstances",
                "ec2:StopInstances"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "ec2:ResourceTag/scheduler": "true"
                }
            }
        }
    ]
}

Metadata

Release files for aws-resource-scheduler 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-resource-scheduler 0.1.0
File Size Uploaded Provenance
aws_resource_scheduler-0.1.0.tar.gz 19.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-resource-scheduler 0.1.0
File Interpreter ABI Platform
aws_resource_scheduler-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.3 kB

Release files / aws_resource_scheduler-0.1.0.tar.gz

Download URL aws_resource_scheduler-0.1.0.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ddf6a2f397720e45cd5ff4b828363f0750f9f9ab8f7846ae27b8802a1dd22380
BLAKE2b-256 checksum
How to use checksums
c97ccd7f2a498de9fd09f1c5ad67e996c6a01dcd3de19ff37f466cd410a7558a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release files / aws_resource_scheduler-0.1.0-py3-none-any.whl

Download URL aws_resource_scheduler-0.1.0-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ee67e4e5f288fb84bbf0ca084a7c0054042e06bedbfae392119ca67f25364e5
BLAKE2b-256 checksum
How to use checksums
9124f3c92d53f2999ad795b84977160961b5d191d520bbd8f7a842dbdd172c13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Security for aws-resource-scheduler 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page