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).
Metadata
Release files for aws-resource-toggler 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aws_resource_toggler-0.1.0.tar.gz | 5.6 kB | Without provenance | Details |
Release files / aws_resource_toggler-0.1.0.tar.gz
| Download URL | aws_resource_toggler-0.1.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85b9a54ed81171cc97208a9de0578abd877ab3a9f21eeb44d5bd943ded8edc4e
|
|
BLAKE2b-256 checksum How to use checksums |
968107716cb10e204f5612e6adb8cb5f187060f8ef9f63a2b591bf32bfdc067a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Security for aws-resource-toggler 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.