A Python library to start and stop AWS resources (EC2, RDS, ECS) based on tags.
Project description
AWS Resource Toggler
A powerful Python package designed to automatically manage the state (start/stop/scale) of multiple AWS services (EC2, RDS, ECS) based on custom resource tags. This is ideal for managing non-production environments to save costs. Installation
Structure the files: Create the following directory structure:
.
├── setup.py
├── README.md
└── resource_toggler/
├── __init__.py
└── manager.py
Build the package: From the root directory (where setup.py is located), run:
python setup.py sdist
Install the package:
pip install dist/aws-resource-toggler-0.1.0.tar.gz
(Replace 0.1.0 with your package version)
Usage as a Library
The main function is toggle_resources. You must have AWS credentials configured (e.g., via AWS CLI or environment variables) for Boto3 to work. Example
import json from resource_toggler import toggle_resources
Define the tags you want to match
This example will toggle resources tagged with both 'Stage=Dev' AND 'Schedule=Workhours'
required_tags = [ {'Key': 'Stage', 'Value': 'Dev'}, {'Key': 'Schedule', 'Value': 'Workhours'} ]
Run the toggler for a specific region
try: report = toggle_resources( tag_filters=required_tags, region='us-east-1' # Specify your target region )
print("--- Execution Complete ---")
print(json.dumps(report, indent=4))
except Exception as e: print(f"An error occurred during execution: {e}")
Usage in AWS Lambda
The package retains the original lambda_handler for direct use as a Lambda entry point.
Lambda Handler: Set the Lambda handler to resource_toggler.manager.lambda_handler.
Environment Variables: Define the required tags as environment variables (e.g., TAG_0_KEY=Stage, TAG_0_VALUE=Dev).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file aws_resource_toggler-0.1.0.tar.gz.
File metadata
- Download URL: aws_resource_toggler-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85b9a54ed81171cc97208a9de0578abd877ab3a9f21eeb44d5bd943ded8edc4e
|
|
| MD5 |
b8c79a4f1eb729a41a5b1e384d04ef9c
|
|
| BLAKE2b-256 |
968107716cb10e204f5612e6adb8cb5f187060f8ef9f63a2b591bf32bfdc067a
|