PHPackages                             silinternational/ecs-deploy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. silinternational/ecs-deploy

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

silinternational/ecs-deploy
===========================

Simple shell script for initiated blue-green deployments on Amazon Elastic Container Service (ECS)

3.10.23(2mo ago)2.0k7.2k470MITShellCI passing

Since Jul 30Pushed 1mo ago36 watchersCompare

[ Source](https://github.com/sil-org/ecs-deploy)[ Packagist](https://packagist.org/packages/silinternational/ecs-deploy)[ Docs](https://github.com/sil-org/ecs-deploy)[ RSS](/packages/silinternational-ecs-deploy/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (54)Used By (0)

ecs-deploy
==========

[](#ecs-deploy)

[![Status for sil-org/ecs-deploy](https://github.com/sil-org/ecs-deploy/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/sil-org/ecs-deploy/actions/workflows/ci.yml/badge.svg?branch=master)

This script uses the Task Definition and Service entities in Amazon's ECS to instigate an automatic blue/green deployment.

NOTE: Maintenance Only
----------------------

[](#note-maintenance-only)

`ecs-deploy` is now in maintenance mode. In other words, we are considering it "feature complete" and will generally only consider PRs if they are bugfixes or are to add support for new AWS CLI features.

**We have migrated the container image to GHCR.**

Usage
-----

[](#usage)

```
One of the following is required:
    -n | --service-name     Name of service to deploy
    -d | --task-definition  Name of task definition to deploy

Required arguments:
    -k | --aws-access-key         AWS Access Key ID. May also be set as environment variable AWS_ACCESS_KEY_ID
    -s | --aws-secret-key         AWS Secret Access Key. May also be set as environment variable AWS_SECRET_ACCESS_KEY
    -r | --region                 AWS Region Name. May also be set as environment variable AWS_DEFAULT_REGION
    -p | --profile                AWS Profile to use - If you set this aws-access-key, aws-secret-key and region are not needed
       | --aws-instance-profile   Use the IAM role associated with the current AWS instance. Can only be used from within a running AWS instance. If you set this, aws-access-key and aws-secret-key are not needed
    -c | --cluster                Name of ECS cluster
    -n | --service-name           Name of service to deploy
    -i | --image                  Name of Docker image to run, ex: repo/image:latest
                                  Format: [domain][:port][/repo][/][image][:tag]
                                  Examples: mariadb, mariadb:latest, private.registry.com:8000/repo/image:tag

Optional arguments:
    -a | --aws-assume-role        ARN for AWS Role to assume for ecs-deploy operations.
    -D | --desired-count          The number of instantiations of the task to place and keep running in your service.
    -m | --min                    minumumHealthyPercent: The lower limit on the number of running tasks during a deployment. (default: 100)
    -M | --max                    maximumPercent: The upper limit on the number of running tasks during a deployment. (default: 200)
    -t | --timeout                Default is 90s. Script monitors ECS Service for new task definition to be running.
    -e | --tag-env-var            Get image tag name from environment variable. If provided this will override value specified in image name argument.
    -to | --tag-only              New tag to apply to all images defined in the task (multi-container task). If provided this will override value specified in image name argument.
    --max-definitions             Number of Task Definition Revisions to persist before deregistering oldest revisions.
                                  Note: This number must be 1 or higher (i.e. keep only the current revision ACTIVE).
                                        Max definitions causes all task revisions not matching criteria to be deregistered, even if they're created manually.
                                        Script will only perform deregistration if deployment succeeds.
    --task-definition-file        File used as task definition to deploy
    --enable-rollback             Rollback task definition if new version is not running before TIMEOUT
    --use-latest-task-def         Will use the most recently created task definition as it's base, rather than the last used.
    --force-new-deployment        Force a new deployment of the service. Default is false.
    --skip-deployments-check      Skip deployments check for services that take too long to drain old tasks
    --run-task                    Run created task now. If you set this, service-name are not needed.
    --wait-for-success            Wait for task execution to complete and to receive the exitCode 0.
    --launch-type                 The launch type on which to run your task. (https://docs.aws.amazon.com/cli/latest/reference/ecs/run-task.html)
    --platform-version            The Fargate platform version on which to run your task. (https://docs.aws.amazon.com/cli/latest/reference/ecs/run-task.html)
    --network-configuration       The network configuration for the task. This parameter is required for task definitions that use
                                      the awsvpc network mode to receive their own elastic network interface, and it is not supported
                                      for other network modes. (https://docs.aws.amazon.com/cli/latest/reference/ecs/run-task.html)
    --copy-task-definition-tags   Copy the existing task definition tags to the new task definition revision
    -v | --verbose                Verbose output
         --version                Display the version

Requirements:
    aws:  AWS Command Line Interface
    jq:   Command-line JSON processor

Examples:
  Simple deployment of a service (Using env vars for AWS settings):

    ecs-deploy -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container:latest

  All options:

    ecs-deploy -k ABC123 -s SECRETKEY -r us-east-1 -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container -m 50 -M 100 -t 240 -D 2 -e CI_TIMESTAMP -v

  Updating a task definition with a new image:

    ecs-deploy -d my-task-definition -i my.private.repo.com/frontend_container:17

  Using profiles (for STS delegated credentials, for instance):

    ecs-deploy -p my-profile -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container -t 240 -e CI_TIMESTAMP -v

  Update just the tag on whatever image is found in ECS Task (supports multi-container tasks):

    ecs-deploy -c staging -n core-service -to 0.1.899 -i ignore

Notes:
  - If a tag is not found in image and an ENV var is not used via -e, it will default the tag to "latest"

```

Installation
------------

[](#installation)

- Install and configure [aws-cli](http://docs.aws.amazon.com/cli/latest/userguide/tutorial-ec2-ubuntu.html#install-cli)
- Install [jq](https://github.com/stedolan/jq/wiki/Installation)
- Install ecs-deploy:

```
curl https://raw.githubusercontent.com/sil-org/ecs-deploy/master/ecs-deploy | sudo tee /usr/bin/ecs-deploy
sudo chmod +x /usr/bin/ecs-deploy

```

How it works
------------

[](#how-it-works)

*Note: Some nouns in the next paragraphs are capitalized to indicate that they are words which have specific meanings in AWS*

Remember that in the EC2 Container Service, the relationship between the group of containers which together provide a useful application (e.g. a database, web frontend, and perhaps some for maintenance/cron) is specified in a Task Definition. The Task Definition then acts a sort of template for actually running the containers in that group. That resulting group of containers is known as a Task. Due to the way docker implements networking, generally you can only run one Task per Task Definition per Container Instance (the virtual machines providing the cluster infrastructure).

Task Definitions are automatically version controlled---the actual name of a Task Definition is composed of two parts, the Family name, and a version number, like so: `phpMyAdmin:3`

Since a Task is supposed to be a fully self-contained "worker unit" of a broader application, Amazon uses another configuration entity, Services, to manage the number of Tasks running at any given time. As Tasks are just instantiations of Task Definitions, a Service is just a binding between a specified revision of a Task Definition, and the number of Tasks which should be run from it.

Conveniently, Amazon allows this binding to be updated, either to change the number of Tasks running or to change the Task Definition they are built from. In the former case, the Service will respond by building or killing Tasks to bring the count to specifications. In the latter case, however, it will do a blue/green deployment, that is, before killing any of the old Tasks, it will first ensure that a new Task is brought up and ready to use, so that there is no loss of service.

*Naturally, enough computing resources must be available in the ECS cluster for any of this to work.*

Consequently, all that is needed to deploy a new version of an application is to update the Service which is running its Tasks to point at a new version of the Task Definition. `ecs-deploy` uses the python `aws` utility to do this. It,

- Pulls the JSON representation of the in-use Task Definition; or the most recently created if using `--use-latest-task-def`
- Edits it
- Defines a new version, with the changes
- Updates the Service to use the new version
- Waits, querying Amazon's API to make sure that the Service has been able to create a new Task

The second step merits more explanation: since a Task Definition \[may\] define multiple containers, the question arises, "what must be changed to create a new revision?" Empirically, the surprising answer is nothing; Amazon allows you to create a new but identical version of a Task Definition, and the Service will still do a blue/green deployment of identical tasks.

Nevertheless, since the system uses docker, the assumption is that improvements to the application are built into its container images, which are then pushed into a repository (public or private), to then be pulled down for use by ECS. This script therefore uses the specified `image` parameter as a modification key to change the tag used by a container's image. It looks for images with the same repository name as the specified parameter, and updates its tag to the one in the specified parameter.

*A direct consequence of this is that if you define more than one container in your Task Definition to use the same image, all of them will be updated to the specified tag, even if you set them to use different tags initially. But this is considered to be an unlikely use case.*

This behavior allows two possible process to specify which images, and therefore which configurations, to deploy. First, you may set the tag to always be `latest` (or some other static value), like so:

```
ecs-deploy -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container:latest

```

This will result in identical new versions of the Task Definition being created, but the Service will still do a blue/green deployment, and will so will pull down the latest version (if you previously pushed it into the registry).

Alternatively, you may specify some other means of obtaining the tag, since the script `eval`s the image string. You could use git tags as a map to docker tags:

```
ecs-deploy -c my-cluster-name -n my-service-name -i 'my.private.repo.com/frontend_container:`git describe`'

```

Or perhaps just obtain read the docker tag from another file in your development:

```
ecs-deploy -c my-cluster-name -n my-service-name -i 'my.private.repo.com/frontend_container:$(< VERSION)'

```

In any case, just make sure your process builds, tags, and pushes the docker image you use to the repository before running this script.

Use Environment Variable for tag name value
-------------------------------------------

[](#use-environment-variable-for-tag-name-value)

In some cases you may want to use an environment variable for the tag name of your image. For example, we want to use a unique docker image/tag for each task definition. This gives us the ability to revert/rollback changes by just selecting a previous task definition and updating the service.

Using the `-e` argument you can provide the name of an environment variable that holds the value you wish to use for the tag.

For example:

```
ecs-deploy -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container -e CI_TIMESTAMP

```

AWS IAM Policy Configuration
----------------------------

[](#aws-iam-policy-configuration)

Here's an example of a suitable custom policy for [AWS IAM](https://aws.amazon.com/documentation/iam/):

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "ecs:DescribeServices",
                "ecs:UpdateService",
                "ecs:RegisterTaskDefinition",
                "ecs:DescribeTasks",
                "ecs:ListTasks"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:ecs:us-east-1:111111111111:service/cluster-name/service-name",
                "arn:aws:ecs:us-east-1:111111111111:task-definition/service-name:*",
                "arn:aws:ecs:us-east-1:111111111111:task/cluster-name/*",
                "arn:aws:ecs:us-east-1:111111111111:container-instance/cluster-name/*"
            ]
        },
        {
            "Action": [
                "ecs:DescribeTaskDefinition",
                "ecs:DeregisterTaskDefinition",
                "ecs:ListTaskDefinitions",
                "ecr:GetAuthorizationToken"
            ],
            "Effect": "Allow",
            "Resource": "*"
        },
        {
            "Action": "iam:PassRole",
            "Effect": "Allow",
            "Resource": "arn:aws:iam::111111111111:role/role-name"
        }
    ]
}
```

Replace the `111111111111` value with your AWS account number. The `iam:PassRole` action can be omitted if your task definition does not specify an ECS task role. If you do not use ECR, the `ecr:GetAuthorizationToken` action can be omitted.

Your ECR policy should limit access to the user or role used for ecs-deploy. Here is an example policy:

```
{
  "Version": "2008-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111111111111:user/user-name"
      },
      "Action": [
        "ecr:BatchCheckLayerAvailability",
        "ecr:BatchGetImage",
        "ecr:CompleteLayerUpload",
        "ecr:GetDownloadUrlForLayer",
        "ecr:InitiateLayerUpload",
        "ecr:PutImage",
        "ecr:UploadLayerPart"
      ]
    }
  ]
}
```

Troubleshooting
---------------

[](#troubleshooting)

- You must provide AWS credentials in one of the supported formats. If you do not, you'll see some error output from the AWS CLI, something like:

    ```
     You must specify a region. You can also configure your region by running "aws configure".

    ```

Testing
-------

[](#testing)

Automated tests are performed using [bats](https://github.com/sstephenson/bats). The goal of testing is to ensure that updates/changes do not break core functionality. Unfortunately not all of `ecs-deploy` is testable since portions interact with AWS APIs to perform actions. So for now any parsing/processing of data locally is tested.

Any new functionality and pull requests should come with tests as well (if possible).

Github Actions Support
----------------------

[](#github-actions-support)

Github Actions support is available. Add a code block similar to that below to your actions yaml file. Parameters are passed to the ecs-deploy tool under 'with' section. For each parameter, the parameter name followed by \_cmd must be called with the appropriate parameter option like '--aws-access-key' in addition to supplying the parameter aws\_access\_key with the appropriate value.

```
deploy_to_ecs:
  name: 'Deploy updated container image via blue/green deployment to ECS service.'
  runs-on: ubuntu-18.04
  steps:
  - uses: sil-org/ecs-deploy@master
    env:
      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      AWS_DEFAULT_REGION: 'us-east-1'
    with:
      aws_access_key_cmd: '--aws-access-key'
      aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
      aws_secret_key_cmd: '--aws-secret-key'
      aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      cluster_cmd: '--cluster'
      cluster: 'cluster-name'
      image_cmd: '--image'
      image: '{amazon_id}.dkr.ecr.us-east-1.amazonaws.com/cluster-name/image_name:latest'
      region_cmd: '--region'
      region: 'us-east-1'
      service_name_cmd: '--service-name'
      service_name: 'aws-service-name'
      timeout_cmd: '--timeout'
      timeout: '360'

```

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance87

Actively maintained with recent releases

Popularity47

Moderate usage in the ecosystem

Community38

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~77 days

Recently: every ~127 days

Total

51

Last Release

76d ago

Major Versions

1.0 → 2.02015-08-31

2.6.3 → 3.02017-05-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5e188393958c4505bb06d9e79ed99a47d1cd42551142f02ef364d8268449ef8?d=identicon)[fillup](/maintainers/fillup)

![](https://www.gravatar.com/avatar/836739aa4f60c754dc9a4a547ebd0c166e4b6e855d9f119df2be5aec92f3a375?d=identicon)[forevermatt](/maintainers/forevermatt)

![](https://www.gravatar.com/avatar/a0d56d7e6fc794910b03eff96448007ee05879ad38493f0b5f215c4fe61f4b30?d=identicon)[mtompset](/maintainers/mtompset)

![](https://www.gravatar.com/avatar/5256eacae3564eb6d3e954abc6552ed99a6d948d94d2b07cc1dc9dabb0bce108?d=identicon)[jason-jackson](/maintainers/jason-jackson)

---

Top Contributors

[![fillup](https://avatars.githubusercontent.com/u/556105?v=4)](https://github.com/fillup "fillup (135 commits)")[![briskt](https://avatars.githubusercontent.com/u/3172830?v=4)](https://github.com/briskt "briskt (46 commits)")[![forevermatt](https://avatars.githubusercontent.com/u/6233204?v=4)](https://github.com/forevermatt "forevermatt (42 commits)")[![jason-jackson](https://avatars.githubusercontent.com/u/35783387?v=4)](https://github.com/jason-jackson "jason-jackson (17 commits)")[![inakiabt](https://avatars.githubusercontent.com/u/606852?v=4)](https://github.com/inakiabt "inakiabt (10 commits)")[![HankieCodes](https://avatars.githubusercontent.com/u/3521186?v=4)](https://github.com/HankieCodes "HankieCodes (10 commits)")[![gregwebs](https://avatars.githubusercontent.com/u/1183?v=4)](https://github.com/gregwebs "gregwebs (10 commits)")[![kakakakakku](https://avatars.githubusercontent.com/u/1573290?v=4)](https://github.com/kakakakakku "kakakakakku (9 commits)")[![devon-sil](https://avatars.githubusercontent.com/u/122382412?v=4)](https://github.com/devon-sil "devon-sil (9 commits)")[![reidab](https://avatars.githubusercontent.com/u/13192?v=4)](https://github.com/reidab "reidab (9 commits)")[![Praveenraj-K](https://avatars.githubusercontent.com/u/181978672?v=4)](https://github.com/Praveenraj-K "Praveenraj-K (7 commits)")[![thomasbiddle](https://avatars.githubusercontent.com/u/1205663?v=4)](https://github.com/thomasbiddle "thomasbiddle (6 commits)")[![vpaul-dev](https://avatars.githubusercontent.com/u/67790656?v=4)](https://github.com/vpaul-dev "vpaul-dev (4 commits)")[![Kostanos](https://avatars.githubusercontent.com/u/1136702?v=4)](https://github.com/Kostanos "Kostanos (4 commits)")[![yu-orz](https://avatars.githubusercontent.com/u/1644258?v=4)](https://github.com/yu-orz "yu-orz (3 commits)")[![bobdoah](https://avatars.githubusercontent.com/u/1266467?v=4)](https://github.com/bobdoah "bobdoah (3 commits)")[![marcaurele](https://avatars.githubusercontent.com/u/1081566?v=4)](https://github.com/marcaurele "marcaurele (3 commits)")[![rafaelfelix](https://avatars.githubusercontent.com/u/137474?v=4)](https://github.com/rafaelfelix "rafaelfelix (3 commits)")[![marsewe](https://avatars.githubusercontent.com/u/28595676?v=4)](https://github.com/marsewe "marsewe (2 commits)")[![majdarbash](https://avatars.githubusercontent.com/u/8945766?v=4)](https://github.com/majdarbash "majdarbash (2 commits)")

---

Tags

aws-ecscontinuous-deploymentecsecs-deployawsec2dockerECSamazon web serviceselastic container service

### Embed Badge

![Health badge](/badges/silinternational-ecs-deploy/health.svg)

```
[![Health](https://phpackages.com/badges/silinternational-ecs-deploy/health.svg)](https://phpackages.com/packages/silinternational-ecs-deploy)
```

###  Alternatives

[ondram/ci-detector

Detect continuous integration environment and provide unified access to properties of current build

22249.4M33](/packages/ondram-ci-detector)[spatie/docker

Run a docker container in your PHPUnit tests

478120.2k12](/packages/spatie-docker)[ryoluo/sail-ssl

Laravel Sail plugin to enable SSL (HTTPS) connection with Nginx.

188672.6k2](/packages/ryoluo-sail-ssl)[aschmelyun/fleet

Run multiple Laravel Sail websites on your local environment

33269.5k](/packages/aschmelyun-fleet)[testcontainers/testcontainers

Testcontainers implementation in PHP

199184.7k17](/packages/testcontainers-testcontainers)[techpivot/aws-code-deploy

AWS Code Deploy Bash Runner

124126.9k](/packages/techpivot-aws-code-deploy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
