aws-resource-scheduler


Nameaws-resource-scheduler JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryAn open-source solution to start/stop AWS EC2, Autoscaling Group, RDS, Aurora, ECS, and Fargate.
upload_time2024-10-10 22:58:15
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords aws scheduler automation ec2 rds asg aurora
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```bash
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. 

```yaml
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:
```bash
aws-resource-scheduler -f config-stage.yml -w stage -r ec2,rds,asg,ecs -a stop
```

To start EC2 instances, ASG, and ECS services:
```bash
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:


```json
{
    "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.

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "aws-resource-scheduler",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Nitin Bhadauria <nitinb@cloudstaff.com>",
    "keywords": "aws, scheduler, automation, ec2, rds, asg, aurora",
    "author": null,
    "author_email": "Nitin Bhadauria <nitinb@cloudstaff.com>",
    "download_url": "https://files.pythonhosted.org/packages/c9/7c/cd7f2a498de9fd09f1c5ad67e996c6a01dcd3de19ff37f466cd410a7558a/aws_resource_scheduler-0.1.0.tar.gz",
    "platform": null,
    "description": "# AWS Resource Scheduler\n\nAWS 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.\n\n## Features\n\n- Create a bundle of resources using names or tags that need to be started or stopped for a project or team.\n- Combine resources from multiple regions or accounts.\n- The application checks for resources to become healthy before moving to the next resource, allowing you to decide the sequence and dependency of resources.\n- Doesn't require any changes to Tags or infrastructure, making it compatible with resources managed by IaC tools like CDK or Terraform.\n- Start and stop AWS resources like EC2 instances, RDS databases, Aurora clusters.\n- Scale up and down Auto Scaling Groups and ECS services.\n- Schedule operations based on predefined configurations.\n- Send notifications to Google Chat, Slack, or Microsoft Teams.\n\n## Installation\n\n```bash\npip install aws-resource-scheduler\n```\n\n### Configuration\n\nCreate a configuration like below, based on your need. \nYou can keep more then workload in the same file an decide which one to use for the action. \n\n```yaml\nworkspaces:\n  stage:\n    aws_region: us-west-2\n    role_arn: arn:aws:iam::123456789012:role/SchedulerRole\n    storage:\n      method: parameter_store  # Options: 'parameter_store' or 'dynamodb' to store last min,max,desire value for ecs and asg\n      dynamodb_table: 'ResourceSchedulerTable'  # Required if method is 'dynamodb'\n    notification:\n      enable: true\n      platform: google\n      webhook_url: https://chat.googleapis.com/v1/spaces/XXX/messages?key=YYY&token=ZZZ\n    ec2:\n      name:\n      - instance1\n      - instance2\n      tags:\n        Environment: development\n    asg:\n      name:\n      - asg1\n      - asg2\n    ecs:\n      my-cluster:\n      - service2\n        services:\n         - service1\n       tags:\n         name: service2\n    rds:\n      name:\n      - db-instance1\n      - db-instance2\n    aurora:\n      name: \n      - aurora-cluster1\n      tags:\n        Environment: development\n```\nUse 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.\n\n### Arguments\n-f, --filename: The configuration file\n-w, --workspace: The workspace to use from the config file\n-r, --resource: Comma-separated list of AWS resources (e.g., ec2, rds, asg, ecs, aurora)\n-a, --action: The action to perform (start, stop, status)\n-n, --no-wait: Do not wait for resources to reach desired state after starting or stopping\n-t, --threads: Number of threads to use for parallel operations (default: 10)\n\n### Example Usage\nTo stop EC2 instances, ASG, and ECS services in the stage workspace:\n```bash\naws-resource-scheduler -f config-stage.yml -w stage -r ec2,rds,asg,ecs -a stop\n```\n\nTo start EC2 instances, ASG, and ECS services:\n```bash\naws-resource-scheduler -f config-stage.yml -w stage -r ec2,asg,ecs -a start\n```\n\n### IAM Role and Permission\n\nTo securely interact with AWS resources, create an IAM role with the necessary permissions. Follow these steps:\n\n\n```json\n{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [\n        {\n            \"Sid\": \"SSMDescribeParameters\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"ssm:DescribeParameters\"\n            ],\n            \"Resource\": \"*\"\n        },\n        {\n            \"Sid\": \"SSMGetPutParameters\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"ssm:GetParameter\",\n                \"ssm:PutParameter\"\n            ],\n            \"Resource\": \"arn:aws:ssm:*:*:parameter/scheduler/*\"\n        },\n        {\n            \"Sid\": \"EC2DescribeInstances\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"ec2:DescribeInstances\",\n                \"ec2:DescribeTags\"\n            ],\n            \"Resource\": \"*\"\n        },\n        {\n            \"Sid\": \"EC2StartStopInstances\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"ec2:StartInstances\",\n                \"ec2:StopInstances\"\n            ],\n            \"Resource\": \"*\"\n        },\n        {\n            \"Sid\": \"RDSDescribeInstances\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"rds:DescribeDBInstances\",\n                \"rds:ListTagsForResource\"\n            ],\n            \"Resource\": \"*\"\n        },\n        {\n            \"Sid\": \"RDSStartStopInstances\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"rds:StartDBInstance\",\n                \"rds:StopDBInstance\"\n            ],\n            \"Resource\": \"arn:aws:rds:*:*:db:*\"\n        },\n        {\n            \"Sid\": \"RDSDescribeClusters\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"rds:DescribeDBClusters\",\n                \"rds:ListTagsForResource\"\n            ],\n            \"Resource\": \"*\"\n        },\n        {\n            \"Sid\": \"RDSStartStopClusters\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"rds:StartDBCluster\",\n                \"rds:StopDBCluster\"\n            ],\n            \"Resource\": \"arn:aws:rds:*:*:cluster:*\"\n        },\n        {\n            \"Sid\": \"AutoScalingDescribe\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"autoscaling:DescribeAutoScalingGroups\",\n                \"application-autoscaling:DescribeScalableTargets\",\n                \"application-autoscaling:RegisterScalableTarget\",\n                \"application-autoscaling:DeregisterScalableTarget\",\n                \"application-autoscaling:DescribeScalingPolicies\",\n                \"application-autoscaling:PutScalingPolicy\"\n            ],\n            \"Resource\": \"*\"\n        },\n        {\n            \"Sid\": \"AutoScalingUpdateGroups\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"autoscaling:UpdateAutoScalingGroup\"\n            ],\n            \"Resource\": \"arn:aws:autoscaling:*:*:autoScalingGroup:*:autoScalingGroupName/*\"\n        },\n        {\n            \"Sid\": \"ECSDescribeServices\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"ecs:DescribeServices\",\n                \"ecs:ListTagsForResource\",\n                \"ecs:ListServices\"\n            ],\n            \"Resource\": \"*\"\n        },\n        {\n            \"Sid\": \"ECSUpdateServices\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"ecs:UpdateService\"\n            ],\n            \"Resource\": \"arn:aws:ecs:*:*:service/*\"\n        },\n        {\n          \"Sid\": \"DynamodbStorage\",\n          \"Effect\": \"Allow\",\n          \"Action\": [\n            \"dynamodb:PutItem\",\n            \"dynamodb:GetItem\",\n            \"dynamodb:UpdateItem\"\n          ],\n        \"Resource\": \"arn:aws:dynamodb:*:*:table/ResourceSchedulerTable\"\n        }\n    ]\n}\n```\n\nYou can use Start and stop actions are allowed only on instances tagged with scheduler=true.\nOther Services (RDS, Auto Scaling Groups, ECS): Similar tag-based restrictions are applied.\n\n```json\n{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [\n        {\n            \"Sid\": \"EC2StartStopInstances\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"ec2:StartInstances\",\n                \"ec2:StopInstances\"\n            ],\n            \"Resource\": \"*\",\n            \"Condition\": {\n                \"StringEquals\": {\n                    \"ec2:ResourceTag/scheduler\": \"true\"\n                }\n            }\n        }\n    ]\n}\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An open-source solution to start/stop AWS EC2, Autoscaling Group, RDS, Aurora, ECS, and Fargate.",
    "version": "0.1.0",
    "project_urls": {
        "BugTracker": "https://github.com/cloudstaff-apps/aws-resource-scheduler/issues",
        "Documentation": "https://github.com/cloudstaff-apps/aws-resource-scheduler#readme",
        "Homepage": "https://github.com/cloudstaff-apps/aws-resource-scheduler",
        "Repository": "https://github.com/cloudstaff-apps/aws-resource-scheduler"
    },
    "split_keywords": [
        "aws",
        " scheduler",
        " automation",
        " ec2",
        " rds",
        " asg",
        " aurora"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9124f3c92d53f2999ad795b84977160961b5d191d520bbd8f7a842dbdd172c13",
                "md5": "69a260ba084255bec6f24e98026ea91e",
                "sha256": "0ee67e4e5f288fb84bbf0ca084a7c0054042e06bedbfae392119ca67f25364e5"
            },
            "downloads": -1,
            "filename": "aws_resource_scheduler-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "69a260ba084255bec6f24e98026ea91e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18764,
            "upload_time": "2024-10-10T22:58:13",
            "upload_time_iso_8601": "2024-10-10T22:58:13.395242Z",
            "url": "https://files.pythonhosted.org/packages/91/24/f3c92d53f2999ad795b84977160961b5d191d520bbd8f7a842dbdd172c13/aws_resource_scheduler-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c97ccd7f2a498de9fd09f1c5ad67e996c6a01dcd3de19ff37f466cd410a7558a",
                "md5": "945f738e12efbe6438188133a48a609a",
                "sha256": "ddf6a2f397720e45cd5ff4b828363f0750f9f9ab8f7846ae27b8802a1dd22380"
            },
            "downloads": -1,
            "filename": "aws_resource_scheduler-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "945f738e12efbe6438188133a48a609a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 19533,
            "upload_time": "2024-10-10T22:58:15",
            "upload_time_iso_8601": "2024-10-10T22:58:15.251364Z",
            "url": "https://files.pythonhosted.org/packages/c9/7c/cd7f2a498de9fd09f1c5ad67e996c6a01dcd3de19ff37f466cd410a7558a/aws_resource_scheduler-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-10 22:58:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cloudstaff-apps",
    "github_project": "aws-resource-scheduler",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aws-resource-scheduler"
}
        
Elapsed time: 0.51584s