{"id":20790497,"url":"https://github.com/docker-production-aws/lambda-ecs-capacity","last_synced_at":"2025-06-21T21:39:12.167Z","repository":{"id":176607456,"uuid":"112046807","full_name":"docker-production-aws/lambda-ecs-capacity","owner":"docker-production-aws","description":"AWS Lambda Function for calculating ECS cluster capacity","archived":false,"fork":false,"pushed_at":"2017-11-26T01:42:45.000Z","size":8,"stargazers_count":3,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T23:31:33.264Z","etag":null,"topics":["autoscaling","aws","aws-ecs","aws-lambda","docker","ecs","ecs-cluster","pluralsight","python"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/docker-production-aws.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-26T01:22:29.000Z","updated_at":"2022-04-26T06:56:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"374faf87-d2b8-45d8-9a1a-54f77d3c594b","html_url":"https://github.com/docker-production-aws/lambda-ecs-capacity","commit_stats":null,"previous_names":["docker-production-aws/lambda-ecs-capacity"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docker-production-aws%2Flambda-ecs-capacity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docker-production-aws%2Flambda-ecs-capacity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docker-production-aws%2Flambda-ecs-capacity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docker-production-aws%2Flambda-ecs-capacity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/docker-production-aws","download_url":"https://codeload.github.com/docker-production-aws/lambda-ecs-capacity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252573862,"owners_count":21770296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autoscaling","aws","aws-ecs","aws-lambda","docker","ecs","ecs-cluster","pluralsight","python"],"created_at":"2024-11-17T15:35:27.650Z","updated_at":"2025-05-05T20:44:09.967Z","avatar_url":"https://github.com/docker-production-aws.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker in Production using AWS ECS Capacity Manager Lambda Function\n\nThis repository defines a Lamdba function called `ecsCapacity`, which is included with the Pluralsight course [Docker in Production using Amazon Web Services](https://app.pluralsight.com/library/courses/docker-production-using-amazon-web-services/table-of-contents).\n\nThis function calculates the current capacity of an ECS cluster in terms of the following resources:\n\n- CPU\n- Memory\n- Network Ports\n\nThe function calculates two metrics and publishes the metrics to the AWS CloudWatch service:\n\n- **ContainerCapacity (integer)** - the current spare capacity of the ECS cluster, expressed in terms of number of containers.  Typically you would *scale out* your ECS cluster when this value drops below (\u003c) 1.\n- **IdleHostCapacity (float)** - the current number of idle hosts in the ECS cluster, express in terms of number of hosts.  Typically you would *scale in* your ECS cluster when this value is greater than (\u003e) 1.0.\n\nTo perform these calculations, this function expects the following environment variables to be configured:\n\n- `CONTAINER_MAX_MEMORY` (defaults to 993) - defines the maximum amount of memory in MB that needs to be reserved for any container supported by the cluster.\n- `CONTAINER_MAX_CPU` (defaults to 1024) - defines the maximum amount of CPU in CPU units that needs to be reserved for any container supported by the cluster.  For EC2 instances, each CPU core provides 1024 CPU units of capacity.\n- `TCP_PORT_RESOURCES` (optional) - defines a list of static mapped or host TCP ports served by all containers supported by the cluster.  This is expressed in the form `\u003cport1\u003e,\u003cport2\u003e,...\u003cportn\u003e` - e.g. `80,443,8080,8081`\n- `UDP_PORT_RESOURCES` (optional) - defines a list of static mapped or host UDP ports served by all containers supported by the cluster.  This is expressed in the form `\u003cport1\u003e,\u003cport2\u003e,...\u003cportn\u003e` - e.g. `80,443,8080,8081`\n\n## Branches\n\nThis repository contains two branches:\n\n- [`master`](https://github.com/docker-production-aws/lambda-ecs-capacity/tree/master) - represents the initial starting state of the repository as viewed in the course.  Specifically this is an empty repository that you are instructed to create in the module **Auto Scaling ECS Applications**.\n\n- [`final`](https://github.com/docker-production-aws/lambda-ecs-capacity/tree/final) - represents the final state of the repository after completing all configuration tasks as described in the course material.\n\n\u003e The `final` branch is provided as a convenience in the case you get stuck, or want to avoid manually typing out large configuration files.  In most cases however, you should attempt to configure this repository by following the course material.\n\nTo clone this repository and checkout a branch you can simply use the following commands:\n\n```\n$ git clone https://github.com/docker-production-aws/lambda-ecs-capacity.git\n...\n...\n$ git checkout final\nSwitched to branch 'final'\n$ git checkout master\nSwitched to branch 'master'\n```\n\n## Errata\n\nNo known issues.\n\n## Further Reading\n\n- [Amazon ECS Events](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_cwe_events.html)\n\n## Build Instructions\n\nTo complete the build process you need the following tools installed:\n\n- Python 2.7\n- PIP package manager\n- [AWS CLI](https://aws.amazon.com/cli/)\n\nAny dependencies need to defined in `src/requirements.txt`.  Note that you do not need to include `boto3`, as this is provided by AWS for Python Lambda functions.\n\nTo build the function and its dependencies:\n\n`make build`\n\nThis will create the necessary dependencies in the `src` folder and create a ZIP package in the `build` folder.  This file is suitable for upload to the AWS Lambda service to create a Lambda function.\n\n```\n$ make build\n=\u003e Building ecsCapacity.zip...\n...\n...\nupdating: requirements.txt (stored 0%)\nupdating: setup.cfg (stored 0%)\nupdating: ecsCapacity.py (deflated 63%)\n=\u003e Built build/ecsCapacity.zip\n```\n\n### Function Naming\n\nThe default name for this function is `ecsCapacity` and the corresponding ZIP package that is generated is called `ecsCapacity.zip`.\n\nIf you want to change the function name, you can either update the `FUNCTION_NAME` setting in the `Makefile` or alternatively configure an environment variable of the same name to override the default function name.\n\n## Publishing the Function\n\nWhen you publish the function, you are simply copying the built ZIP package to an S3 bucket.  Before you can do this, you must ensure you have created the S3 bucket and your environment is configured correctly with appropriate AWS credentials and/or profiles.\n\nTo specify the S3 bucket that the function should be published to, you can either configure the `S3_BUCKET` setting in the `Makefile` or alternatively configure an environment variable of the same name to override the default S3 bucket name.\n\n\u003e [Versioning](http://docs.aws.amazon.com/AmazonS3/latest/dev/Versioning.html) should be enabled on the S3 bucket\n\nTo deploy the built ZIP package:\n\n`make publish`\n\nThis will upload the built ZIP package to the configured S3 bucket.\n\n\u003e When a new or updated package is published, the S3 object version will be displayed.\n\n### Publish Example\n\n```\n$ make publish\n...\n...\n=\u003e Built build/ecsCapacity.zip\n=\u003e Publishing ecsCapacity.zip to s3://123456789012-cfn-lambda...\n=\u003e Published to S3 URL: https://s3.amazonaws.com/123456789012-cfn-lambda/ecsCapacity.zip\n=\u003e S3 Object Version: gyujkgVKoH.NVeeuLYTi_7n_NUburwa4\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocker-production-aws%2Flambda-ecs-capacity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdocker-production-aws%2Flambda-ecs-capacity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocker-production-aws%2Flambda-ecs-capacity/lists"}