Playing with the new AWS Copilot CLI
Tags: aws, githubcopilot, docker
Published: 2020-10-06 22:19:44

---
title: Playing with the new AWS Copilot CLI
published: true
description: 
tags: aws, copilot, docker
cover_image: https://images.unsplash.com/photo-1490043312819-28207692b051?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjYzOTIxfQ&w=3600

---

AWS just launched a fresh CLI recently - copilot. AWS says this CLI is for containerised applications. So the target audience seems to be people using ECS and Fargate. I decided to try this new stuff.

##Installation

The installation for Mac is quite simple. You use homebrew like -

```bash
brew install aws/tap/copilot-cli
```

For windows and Linux refer - https://github.com/aws/copilot-cli/wiki/Installation#manually

### Prerequisites

1. `aws` cli. If you do not have that you might want to install and configure that. Steps [here](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) and [here](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
2. docker

### Initialisation

I am using a simple html file to deploy to in a container using a simple Dockerfile.

The first command you will have to run to initialise is 

`copilot init`

This asks you a few questions and sets up the following things for you in the AWS account. 

1. Virtual Private Cloud (VPC) on 2 Availability Zones (AZs), which includes
    1. Internet Gateway
    2. Public Subnet
    3. Private Subnet
    4. Route Table
2. ECS Cluster
3. Application Load Balancer (ALB)
4. Elastic Container Registry (ECR)

![After running copilot init, creation of infrastructure ongoing
](https://arpit.dev/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F18a4583d-8042-4afa-8992-c50a3f2beeb9%2FUntitled.png?table=block&id=d846c7c2-32ec-4592-9302-c61cd42c1749&width=2790&userId=&cache=v2)

After running copilot init, creation of infrastructure ongoing

### Deployment

Once this is complete, it will ask you  whether you want to deploy this service to a test environment. If you say yes, it will deploy the service in a test environment and provide a URL where you can access the service (if it is a Web Service that you configured).

This does everything you need to deploy and access the Service through a Web URI.

![Here it is deploying to a new 'test' environment. Notice how it created everything for you from VPC to ALB.👀](https://arpit.dev/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F07de3260-de2d-4270-8771-9a16f5154198%2FUntitled.png?table=block&id=ed923413-3402-4bc0-8dff-33e3b765b761&width=1930&userId=&cache=v2)



### Test your deployment

Finally when the deployment is complete, it will give you a URL that you can paste in your favourite browser and test.

![Terminal showing Deployed successfully and giving the URL](https://arpit.dev/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F7fb7e4ff-d39e-4f2d-bc0c-2156a57180d0%2FUntitled.png?table=block&id=8fd7a50e-3870-41b3-91d0-c2bf7279c043&width=4210&userId=&cache=v2)

![Browser displaying Success Page](https://arpit.dev/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F34819fa9-b164-45ce-a78a-b3aca3bfdda9%2FUntitled.png?table=block&id=eb028bc7-cfc4-45e4-9033-27dbf51df9d8&width=4380&userId=&cache=v2)

Voila!

### Other commands

The copilot CLI has three main command streams

1. app - You can use this to perform operations on applications that you have deployed.  
2. env - To perform operations on the environments where your apps are deployed
    1. `copilot env init` - Initialise the env
    2. `copilot env ls` - List all envs
    3. `copilot env show` - Show Details of the env
    4. `copilot env delete` - Delete the env
3. svc

All these have a common set of commands, which are self explanatory - 

1. `copilot {app / env / svc} init` - Initialize
2. `copilot {app / env / svc} ls` - List
3. `copilot {app / env / svc} show` - Gives a more detailed view of the services in the application, the Environments and the URIs. In case of service, it will also display Routes, Service Discovery and other Configuration. 
4. `copilot {app / env / svc} delete` - To delete the app / env / service

Apart from these, svc has some more commands for `package`, `deploy`, `status` and `logs`. 

### Use cases

I think copilot has a really wide range of command sets to cover a wide range of use cases. It can be easily used for CI/CD for most containerised apps. Just install in the pipeline of your choice and deploy from there. 

Anyone using ECS or Fargate could make their deployment processes easier by these commands. 

They also have plans to introduce provisioning of S3, Databases (SQL and NoSQL) from the command which would further widen the use cases to deploy not only services but also storage for your application using this command. 

Also, its open source. Check it out [here](https://github.com/aws/copilot-cli).