Package: ecstools
ecstoolsECS Tools cli aims to make deploying to ECS Fargate easier. It also provides an easy way to scale
and update environment variables.InstallpipinstallecstoolsNOTE: Python 2 is not supported as of version 0.1.7UsageConfig FileAs of v0.1.6 the cli supports an INI config file. The cli will read config files from~/.ecstoolsand$(pwd)/.ecstools. The latter one will override settings from the former one. Hence, we can have config files per project and a global config to failback to. The config file can be used to set command aliases and/or service groups for multi-service deployments. An example config:[alias]cls=cluster lstd=task-definition lsls=service lslsa=service ls -aenv=service envdeploy=service deploydesc=service descscale=service scaletop=service top# Example: Deploy service group to production clusterdp=service deploy production app1 -g[service-group]app1=app1 app1-worker1 app1-worker2ListingList clusters$ecsclusterlsList services# List services in a cluster$ecsservicels<cluster># List service in a cluster with task definition info$ecsservicels<cluster>-aList task definition families$ecstask-definitionlsList task definition revisions with CPU, memory, and container information.# List the last 3 task definition revisions$ecstask-definitionls<task-definition-family>
app1-task-def:3cpu:1024memory:2048-container10-container1:docker-tag3-container20-container2:latest
app1-task-def:2cpu:1024memory:2048-container10-creator:v1.2.3-container20-container2:latest
app1-task-def:1cpu:1024memory:2048-container10-container1:v0.0.1# List more revisions$ecstask-definitionls<task-definition-family>-n123DeployingThe deployments work by specifying cluster, service, and a docker tag.The cli is going to check the current active task definition associated with the service and get the container name. Then it will create a new task definition revision with the new docker tag and deploy it. If the docker tag passed to the cli is the same as in the current task definition, a new deployment will be forced with the current task definition and containers will be recycled. This covers cases where we are deploying tag 'latest' but the tag was reassigned to a new image.Deploying - Service with multiple containers (Experimental)As of v0.1.6 deploying a service with multiple containers is support in single-service deployment only. The cli doesn't yet support multi-service deployments with multiple containers.To deploy multiple containers we need to pass the container tags in the same order the containers are defined in the task definition. If we have containers defined as [container1, container2] the deployment command will be:ecsservicedeploycluster1app1container1-tagcontainer2-tagDeploying - Deploying Multiple ServicesAs of v0.1.6 the cli supports deploying multiple services at the same time. Once a service group has been configured in~/.ecstoolswe can trigger a group deployment by passing-g. See theConfig FileDeploying - Auto-update MonitorThe cli output auto-updates during a deployment. We get almost real-time information about all deployments for the service (there could be more that one). The output includes information about:the name of the containers and their docker tags.the number of containers in each deployment and their status.the number of containers in an ALB/NLB (if one is configured for the service) and their registration status.the last two events from the ECS service.Deploying - Scaling during deploymentThe cli will assume we are trying to deploy as many containers as there are in the current task definition for the service. If we pass the-cflag, we can scale in or out during the deployment.Deploying - Verbose ModeWe can turn verbose mode on with-vto get additional information before the deployment begins.Deploying - Post Deployment MonitoringOnce the cli triggers the deploy and gets to the auto-update screen we can cancel the command if we want with Ctrl-C. The deployment is going to continue. We can always go back to monitor it withecs service top <cluster> <service>Deploying - Examples# Example of deploying a single service$ecsservicedeploycluster1app1tag-new-123
Elapsed:00:00:04
InProgresscluster1app10/1LB:[healthy:1]Ctrl-Ctoquitthewatcher.Nodeploymentswillbeinterrupted.# Example of deploying a service group$grep-B1app1~/.ecstools[service-group]octo=octoocto-worker1octo-worker2

$ecsservicedeployoctoocto:awscp-5513185-g
...Deploying and scaling at the same time.# To scale during a deployment pass `-c N`$ecsservicedeploycluster1app1tag1-c123ScalingScaling works by specifying cluster, service, and the number of desired containers. The cli auto-updates so we can see how many containers there are and what their ECS and ALB/NLB status is.Once the cli triggers the scaling and gets to the auto-update screen we can cancel the command if we want with Ctrl-C. The scaling is going to continue. We can always go back to monitor it withecs service top <cluster> <service>$ecsservicescale<cluster><service>123Updating environment variablesUpdating environment variables works by specifying cluster, service, and pairs of KEY=VALUE.The cli will get the current task definition for the service and then compare its environment variables with the ones that were passed. The cli will print a git-style diff so we can review the changes. Then it will prompt if we want to register a new task definition and deploy it. Finally, the cli starts printing the default deployment auto-update output.Once the cli triggers the deploy and gets to the auto-update screen we can cancel the command if we want. The deployment is going to continue. We can always go back to monitor it withecs service top <cluster> <service># List environment variables$ecsserviceenv<cluster><service># Set/Update environment variables from a file$ecsserviceenvcluster1app1"$(<file.txt)"# Set/Update environment variables$ecsserviceenvcluster1app1TEST1=123TEST2=456Currenttaskdefinitionforcluster1app1:app1-task-def:123

Container:app1
+TEST1=123+TEST2=456Doyouwanttodeployyourchanges?# Deleting environment variables$ecsserviceenvcluster1app1TEST1=123TEST2=456-d
Currenttaskdefinitionforcluster1app1:app1-task-def:123

Container:app1
-TEST1=123-TEST2=456Doyouwanttodeployyourchanges?Updating environment variables for multiple service via service groups.$envstageapp1-gTEST=123456Currenttaskdefinitionforstageapp1:stage-app1:961)app12)nginx#? 1==>Container:app1
+TEST=123456Currenttaskdefinitionforstageapp1-worker1:stage-app1-worker1:34==>Container:app1
+TEST=123456Currenttaskdefinitionforstageapp1-worker2:stage-app1-worker2:38==>Container:app1
+TEST=123456Doyouwanttodeployyourchanges?MonitoringWe can either describe a service or "top" it. Both print information about the current task definition, the number of containers and their status in ECS and ALB/NLB. In addition, the describe command prints information about the subnets and security groups. On the other side, the top command auto-updates. The top command is useful if we want to monitor the progress of a deployment or a scaling event which we triggered by exited out of the deploy or scale commands.# Describe a service$ecsservicedesc<cluster><service># Live monitoring of a service$ecsservicetop<cluster><service># Live monitoring of a service group$ecsservicetop<cluster><service-group>-gAWS Profile and RegionWe can use different AWS profile by specifying-p <profile>and different region with passing-r <region>.