Code Monkey home page Code Monkey logo

ecsservice's Introduction

ECS Infrastructure Scaling using Lambda function

This Python utility is designed to upscale or downscale ECS (Amazon Elastic Container Service) services, providing functionality to manage containerized applications efficiently. It utilizes Boto3, the AWS SDK for Python, along with AWS Lambda functions.

Key Features

  1. Upscale and Downscale ECS Services: Automatically adjust the desired task count for ECS services based on specified criteria such as CPU or memory utilization.

  2. Retrieve ECS Service Information: Obtain detailed information about ECS services including the number of tasks pending and running, aiding in monitoring and management.

  3. Production Environment Protection: Implements safeguards to restrict updates to ECS services in production environments, minimizing risks and ensuring stability.

Benefits

  1. Cost Optimization: Efficiently manage ECS resources to optimize costs by scaling up or down based on demand, avoiding unnecessary expenses.

  2. On-Demand Development and Staging Environments: Enable on-demand scaling for development and staging environments, allowing flexibility and agility in testing and development workflows.

Usage

There are two way to use this use this utility

1. Clone the repository and execute the utility as a standard Python project, allowing for customization and direct usage.
2. Configuration with AWS Lambda Function:

Prerequisites for Lambda functoin

  • AWS account with appropriate permissions to access ECS services.
  • Lambda function with the appropriate IAM role.
  • Postman for testing API endpoints.

Configuration with Lambda function

  • Set up a Lambda function with the provided IAM role.
{
    "Effect": "Allow",
    "Action": [
        "ecs:ListServices",
        "ecs:ListTasks",
        "ecs:ListContainerInstances",
        "ecs:ListTaskDefinitions",
        "ecs:ListClusters",
        "ecs:DescribeClusters",
        "ecs:DescribeServices",
        "ecs:DescribeTaskDefinition",
        "ecs:DescribeTasks",
        "ecs:UpdateService"
    ],
    "Resource": "*"
}
  • Attach an API Gateway to the Lambda function for external access. Consider implementing additional security measures such as API keys or IAM access.
  • Utilize HTTP POST/GET requests to interact with the API Gateway endpoint.
  • Provide the request body with parameters such as desired task count, cluster names, and environment details.

Example Request Body for Postman:

Use body object in case of Post man
{
    "desired_tasks": "0",
    "cluster_names": "all",
    "environment" : "dev,stage"
}


Production Resources Safty:

To ensure safety and prevent unintended actions, the Prefix class has been implemented with specific keywords designated for different access levels.

ALLOWED: This includes a list containing only the wildcard '*', which essentially allows unrestricted access to all resources.

RESTRICTED: This list contains 'prod', indicating restricted access specifically to production resources.

to change the  Constants.py you can chage safeguard

class Prefix(Enum):
    ALLOWED = ['*']
    RESTRICTED = ['prod']

Summary

The ECS Infrastructure Scaling Utility is a Python tool for automating ECS service scaling based on resource utilization. It offers monitoring features and safeguards for production environments, optimizing costs and enhancing flexibility.

ecsservice's People

Contributors

harsh2406 avatar ravimahey avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.