{"id":20790496,"url":"https://github.com/docker-production-aws/lambda-lifecycle-hooks","last_synced_at":"2025-06-11T08:36:22.197Z","repository":{"id":176607459,"uuid":"112042981","full_name":"docker-production-aws/lambda-lifecycle-hooks","owner":"docker-production-aws","description":"AWS Lambda Function for draining ECS container instances in response to EC2 auto scaling lifecycle hooks","archived":false,"fork":false,"pushed_at":"2017-11-26T01:13:31.000Z","size":5,"stargazers_count":5,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-05T20:52:35.893Z","etag":null,"topics":["autoscaling","aws-ecs","aws-lambda","containers","docker","ec2-container-service","ec2-lifecycle-hooks","ecs","ecs-container-instance-draining","lambda","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-25T23:59:00.000Z","updated_at":"2020-07-27T03:31:34.000Z","dependencies_parsed_at":"2024-02-06T01:32:55.728Z","dependency_job_id":null,"html_url":"https://github.com/docker-production-aws/lambda-lifecycle-hooks","commit_stats":null,"previous_names":["docker-production-aws/lambda-lifecycle-hooks"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docker-production-aws%2Flambda-lifecycle-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docker-production-aws%2Flambda-lifecycle-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docker-production-aws%2Flambda-lifecycle-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docker-production-aws%2Flambda-lifecycle-hooks/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-lifecycle-hooks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docker-production-aws%2Flambda-lifecycle-hooks/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259230699,"owners_count":22825445,"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-ecs","aws-lambda","containers","docker","ec2-container-service","ec2-lifecycle-hooks","ecs","ecs-container-instance-draining","lambda","python"],"created_at":"2024-11-17T15:35:27.572Z","updated_at":"2025-06-11T08:36:22.174Z","avatar_url":"https://github.com/docker-production-aws.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker in Production using AWS EC2 Lifecycle Hooks Lambda Function\n\nThis repository defines a Lamdba function called `lifecycleHooks`, 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 processes EC2 Auto Scaling Lifecycle Hooks generating for EC2 Auto Scaling groups that operate ECS clusters, and specifically ensures ECS container instances that are about to be terminated are drained of all running containers before signalling the EC2 Auto Scaling service to proceed with instance termination.\n\n## Branches\n\nThis repository contains two branches:\n\n- [`master`](https://github.com/docker-production-aws/lambda-lifecycle-hooks/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 **Managing ECS Infrastructure Lifecycle**.\n\n- [`final`](https://github.com/docker-production-aws/lambda-lifecycle-hooks/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-lifecycle-hooks.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- [EC2 Auto Scaling Lifecycle](http://docs.aws.amazon.com/autoscaling/latest/userguide/AutoScalingGroupLifecycle.html)\n- [EC2 Auto Scaling Lifecycle Hooks](http://docs.aws.amazon.com/autoscaling/latest/userguide/lifecycle-hooks.html)\n- [ECS Container Instance Draining](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-instance-draining.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 lifecycleHooks.zip...\n...\n...\nupdating: requirements.txt (stored 0%)\nupdating: setup.cfg (stored 0%)\nupdating: lifecycleHooks.py (deflated 63%)\n=\u003e Built build/lifecycleHooks.zip\n```\n\n### Function Naming\n\nThe default name for this function is `lifecycleHooks` and the corresponding ZIP package that is generated is called `lifecycleHooks.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/lifecycleHooks.zip\n=\u003e Publishing lifecycleHooks.zip to s3://123456789012-cfn-lambda...\n=\u003e Published to S3 URL: https://s3.amazonaws.com/123456789012-cfn-lambda/lifecycleHooks.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-lifecycle-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdocker-production-aws%2Flambda-lifecycle-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocker-production-aws%2Flambda-lifecycle-hooks/lists"}