Skip to main content

Scales ASGs and authorises CodePipeline

Project description

ASG Scaler

Blue/Green CodeDeployments for Frugal Architects

license last-commit repo-top-language repo-language-count

Developed with the software and tools below.

Poetry Python GitHub%20Actions Pytest


Quick Links


Overview

asg-scaler simplifies AWS Auto Scaling Groups (ASGs) management for CodePipeline CodeDeploy deployments, enabling efficient blue/green deployment strategies without requiring excess instances. Traditionally, ASGs aim to maintain a fixed capacity, complicating blue/green deployments as they necessitate doubling the instance count temporarily. asg-scaler resolves this by dynamically adjusting ASG capacities to match the deployment phase, increasing for new deployments and reverting once stability is achieved.


Features

Feature Description
โš™๏ธ Architecture This project utilises AWS Lambda for auto-scaling AWS ASGs. It's designed to dynamically adjust ASG sizes and integrates with AWS CodePipeline for deployment automation.
๐Ÿ”ฉ Code Quality Adheres to PEP8 guidelines, enforced by flake8 and pylint. The code is structured around modular Python scripts, enhancing readability and maintainability.
๐Ÿ“„ Documentation Each main script and workflow is well-documented, explaining their roles within the auto-scaling and CI/CD process, though additional user guides or API docs could enhance usability.
๐Ÿ”Œ Integrations Integrates with AWS services like Lambda, Auto Scaling Groups, and CodePipeline. GitHub Actions is used for CI/CD, ensuring automated testing and deployment.
๐Ÿงฉ Modularity The project is modular, with distinct components for ASG management, CodePipeline interaction, and CI/CD automation, allowing for easy updates and scalability.
๐Ÿงช Testing Uses pytest and pytest-cov for running tests and measuring code coverage, ensuring reliability and functionality across updates.
๐Ÿ“ฆ Dependencies Depends on boto3 for AWS interactions, pytest, pytest-cov, and coverage for testing, and flake8 for linting. Managed with poetry for dependency resolution.
๐Ÿš€ Scalability Highly scalable, leveraging AWS Lambda and ASG capabilities to dynamically adjust infrastructure based on demand, within the architectural limits of those services.

Repository Structure

โ””โ”€โ”€ asg-scaler-lambda/
    โ”œโ”€โ”€ .github
    โ”‚   โ”œโ”€โ”€ scripts
    โ”‚   โ”‚   โ””โ”€โ”€ update_version.py
    โ”‚   โ””โ”€โ”€ workflows
    โ”‚       โ”œโ”€โ”€ build.yml
    โ”‚       โ”œโ”€โ”€ dry-run-release.yml
    โ”‚       โ””โ”€โ”€ release.yml
    โ”œโ”€โ”€ LICENSE
    โ”œโ”€โ”€ README.md
    โ”œโ”€โ”€ asg_scaler_lambda
    โ”‚   โ”œโ”€โ”€ asg_helper.py
    โ”‚   โ”œโ”€โ”€ asg_scaler.py
    โ”‚   โ””โ”€โ”€ codepipeline_event.py
    โ”œโ”€โ”€ poetry.lock
    โ”œโ”€โ”€ pylintrc
    โ”œโ”€โ”€ pyproject.toml
    โ”œโ”€โ”€ sonar-project.properties
    โ””โ”€โ”€ tests
        โ”œโ”€โ”€ test_asg_helper.py
        โ”œโ”€โ”€ test_asg_scaler.py
        โ””โ”€โ”€ test_codepipeline_event.py

Modules

.
File Summary
pylintrc The pylintrc file defines linting rules for the asg-scaler repository, aiming to enforce code quality standards and error prevention across the Python modules.
pyproject.toml This pyproject.toml configures the asg-scaler-lambda project, defining dependencies, build settings, and test configurations.
poetry.lock A record of all the exact versions of the dependencies used in asg-scaler
asg_scaler_lambda
File Summary
asg_scaler.py The asg_scaler.py is the entrypoint of asg-scaler, aimed at handling AWS events to dynamically adjust Auto Scaling Group (ASG) parameters and manage CodePipeline approvals. It processes CodePipeline job events to update ASG configurations based on user parameters and handles EventBridge events to automate CodePipeline approvals.
asg_helper.py asg_helper.py provides utility functions to update and validate Auto Scaling Group capacities in AWS. It chiefly transforms capacity parameters, ensures their logical consistency, and interfaces with AWS to adjust ASG settings.
codepipeline_event.py codepipeline_event.py interfaces with AWS CodePipeline for managing job states and approvals. It provides functions to report job success or failure, approve deployment actions automatically, and retrieve necessary tokens for approvals.
.github.scripts
File Summary
update_version.py update_version.py automates version updates in the project's pyproject.toml, ensuring consistent versioning across the asg-scaler-lambda repository.
.github.workflows
File Summary
build.yml .github/workflows/build.yml automates build tests.
release.yml release.yml automates versioning and deployment of the asg-scaler-lambda project.
dry-run-release.yml This YAML file automates pre-release verifications for the asg-scaler-lambda repository.

Getting Started

Requirements

Ensure you have the following dependencies installed on your system:

  • Python: version 3.8+
  • Poetry: version 1.8.2+

Installation

  1. Clone the asg-scaler-lambda repository:
git clone https://github.com/XargsUK/asg-scaler-lambda
  1. Change to the project directory:
cd asg-scaler-lambda
  1. Install the dependencies with Poetry:
poetry install

Running asg-scaler

Use the following command to run asg-scaler:

poetry run python asg_scaler.py

Tests

Use the following command to run tests:

poetry run pytest

Contributing

Contributions are welcome! Here are several ways you can contribute:

Contributing Guidelines
  1. Fork the Repository: Start by forking the project repository to your github account.
  2. Clone Locally: Clone the forked repository to your local machine using a git client.
    git clone https://github.com/XargsUK/asg-scaler-lambda
    
  3. Create a New Branch: Always work on a new branch, giving it a descriptive name.
    git checkout -b new-feature-x
    
  4. Make Your Changes: Develop and test your changes locally.
  5. Commit Your Changes: Commit with a clear message describing your updates.
    git commit -m 'Implemented new feature x.'
    
  6. Push to GitHub: Push the changes to your forked repository.
    git push origin new-feature-x
    
  7. Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.

Once your PR is reviewed and approved, it will be merged into the main branch.


License

This project is protected under the MIT License.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asg_scaler_lambda-0.1.1.tar.gz (13.6 kB view hashes)

Uploaded Source

Built Distribution

asg_scaler_lambda-0.1.1-py3-none-any.whl (9.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page