DEV Community

Cover image for Playing with the new AWS Copilot CLI
Arpit
Arpit

Posted on

Playing with the new AWS Copilot CLI

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 -

brew install aws/tap/copilot-cli
Enter fullscreen mode Exit fullscreen mode

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 and here
  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<br>

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.👀

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

Browser displaying Success Page

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.

Top comments (0)