AWS Copilot

Learn via video courses
Topics Covered

Overview

AWS Copilot is an AWS command line service that helps manage infrastructure for running containerized applications. The entire infrastructural setup and container monitoring can be done using a single command. It was designed to help developers focus on optimizing the application rather than setting up the infrastructure to run the application or maintaining the servers.

What is AWS Copilot?

A huge amount of developer's time usually gets utilized in setting up the infrastructure to run an application. Even after setting up the infrastructure, it must be monitored to ensure everything is running well. This time can be saved with the help of AWS Copilot.

AWS Copilot automates the process of setting up infrastructure and monitoring it. The entire flow can be managed by running CLI commands.

aws copilot logo

  • It eases the process of building and operating with AWS services like AWS ECS, AWS AppRunner, and AWS Fargate to make containerized applications ready for the production environment.
  • A Dockerfile contains the configurational instruction used to deploy a production-ready application on AWS by running one single command.
  • The infrastructure can be scaled and monitored using the command line.
  • Entire CI/CD (Continous Integration/Continous Delivery) pipeline can be set up using some commands.
  • Resource monitoring and debugging are also managed through the command line interface.

How Does It Work?

AWS Copilot is a command line-based service that makes running and deploying containerized applications quicker and easier.

Let's understand the working of Copilot with the help of the diagram given below:

Working of Copilot

  • The things you want as a part of your infrastructure can be converted into YAML scripts. This script contains the configuration details like :
    • Number of servers needed
    • The image and applications to be run on top of each server
    • The RAM and CPU configurations
    • The network and connectivity configurations
  • AWS copilot provides commands which understand these scripts. The copilot commands utilize this script for the following purposes:
    • Deploying a well-architectured infrastructure setup.
    • Deploying CI/CD pipelines for production environments.
    • Monitoring and troubleshooting infrastructural issues.
  • The scripts deploy the containerized applications using other AWS services designed for containers like:
    • AWS Elastic Container Sevice
    • AWS App Runner
    • AWS Fargate

Features of AWS Copilot

Having understood AWS Copilot's working, let's look at some of its essential features.

  • Organise: It allows us to organize the entire microservices infrastructure into one application.
  • Flexibility: Copilot provides the flexibility to set up testing and production across multiple regions to serve the needs of the traffic.
  • CI/CD Pipelines: CI/CD pipelines can be set up across all the microservices infrastructure in an automated way with the help of commands.
  • Monitoring and Debugging: In addition to setup, infrastructural issues can be monitored and debugged with the help of the command line facility provided by Copilot.
  • AutoScaling: If the traffic increases, the number of running servers can be increased. If the traffic decreases, the number of servers running in the infrastructure can be decreased. In short, the autoscale feature can be incorporated with the help of a terminal.

AWS Copilot Concepts

We have three major components to discuss when it comes to AWS Copilot.

Application

  • An application is composed of elaborate code run on a system.
  • An application usually consists of small components, like frontend components, backend components, etc.
  • If your development team is small, and can work on all the components, then a single Copilot application is good enough to work with.
  • If you have multiple teams, each focusing on a single component of an application, then we can have multiple copilot applications. Each team has its own AWS copilot application.

Environment

  • An environment is created for each stage of the software development lifecycle.
  • In Development Environment, the applications are developed and optimized. We add new features to the application in this environment by working on its code.
  • In Testing Environment, the application is tested, if things are working properly, features are working as expected, etc.
  • We also have a Production environment where the application developed and tested is deployed to be used by customers/users.

Service

  • Service refers to the lengthy code processes running inside the containers.
  • An application can have single or multiple services running.
  • Monolithic architecture is designed to run single services only. Then we have microservices architecture, which combines multiple services to form the application.
  • Usually, companies follow the microservices architecture. Under this, the frontend website runs as one service, the backend database server as another, and some API services.

AWS Copilot Use Cases

Let's have a look at some of the everyday use cases of AWS Copilot.

Develop Containerized Applications

  • AWS Copilot is used to deploying containerized applications on AWS Cloud using AWS ECS and AWS Fargate.
  • The containers deployed using copilot are production ready and can be hosted by just running a single command.
  • Developers can shift their focus on optimizing application code and features.

Build a Stable and Secure Foundation

  • With the help of AWS Copilot, we can deploy containers across multiple regions and availability zones.
  • The containers can be hosted in multiple regions and environments (testing, production, development, etc.).
  • The container servers are isolated from each other, which increases security. Moreover, being hosted on AWS, the security is taken care of using AWS services.

Easy Scaling

  • With the increase in user traffic, the number of containers needs to be increased to serve the increasing demand across different regions.
  • With the decrease in user traffic, the number of containers needs to be decreased to save cost and resources.
  • The increase and decrease of servers are taken care of by AWS Copilot. We can integrate the autoscale feature with our infrastructure by specifying it in the configuration file.

Monitor and Troubleshoot

  • Monitoring containers in the production environment is a major issue, as it involves a lot of manual work.
  • AWS Copilot eases infrastructure monitoring by automating the process.
  • The monitoring and troubleshooting process can be automated by running a few commands via the copilot command line service.

Getting Started with AWS Copilot

We know a lot more about the AWS Copilot now. It's time to do some hands-on demos using it. In this demo, we are going to deploy a simple web app.

Create IAM User

We know that we have to work on AWS CLI, so first, let's create a user in the AWS account to get the access key and secret key configured in AWS CLI. It involves the following steps:

  • Login to the AWS console and search IAM in the search bar. Click on IAM. selecting iam in aws console
  • Go to the Users section and click on Add users. adding user
  • Fill in the User name and select the AWS credential type to Access the key. Click on Next: Permissions filling user name aws credential type
  • On the next page, click on Attach existing policies directly and choose Administrator access. Click on Next: Tags. choosing administrator access
  • As the Tags are optional, leave it as default and click on Next: Review. Review the entered details and click on Create user. review entire details
  • The user is created successfully. Copy the Access key ID and Secret access key. access key id and secret access key

This access key and secret key are used to confirm the AWS CLI.

Setup AWS Command Line Interface

Let's download the AWS CLI in the system. Follow these steps:

  • Open the command prompt and run the given command. msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi It will start the installation process of AWS CLI. Click Next for few times and accept the licenses. installing aws cli
  • Click on Install. After a few minutes, click on Finish. installing aws cli2
  • Open the File Explorer where this AWS CLI is installed and copy the path. location of aws cli installed
  • Open the Environment variable and click on Edit. editing environment variable
  • Click on New and paste the copied path of AWS CLI. Click on OK. paste copied path of aws cli
  • Go to the command prompt and run aws --version to check the AWS CLI version. Run the command aws configure to configure the AWS CLI with the AWS account. Use the copied access key ID and secret access key for the IAM user we created earlier. Set a default region. and press Enter. checking aws cli version
  • Now, as we create a sample app, we have to clone the code in the local system. Run the following command to get the code in the local system.

It will create a folder demo_app in which it copies the code. Go to the demo_app directory and install the copilot windows executable file using the following command.

installing copilot windows

  • Now, we can run the copilot command in the command prompt. Run copilot --help in the command prompt. running copilot comand

We set up AWS copilot in our system. Now, we have to check whether docker is running on my system. In my case, docker is not installed, so let's install docker first. If Docker is already installed on your system, you can skip the steps to install Docker.

Steps to Install Docker

  • Enable virtualization from BIOS and go to this link it will download the docker desktop. Click on it to install it. installing docker desktop
  • Once it will install, it will ask to close and restart. Click on that the system will restart automatically. After restarting Docker Subscription Service Agreement appears on the screen. Click on Accept. docker subscription service agreement screen
  • Sometimes, it will ask to install WSL 2 kernel update. Click on the link. install wsl 2 kernel update
  • Download the latest package by clicking on the link. download latest linux kernel update package
  • Open the downloaded file and install the WSL package. Click on Finish. install wsl package
  • After installing the WSL 2 package, restart the system again. Open the Docker Desktop, and now it will show in running state, and it shows Get started with Docker in a few easy steps!. docker desktop running state

Build Sample App Using AWS Copilot

Now, after installing and checking the docker is in a running state, let's move further and build the sample app using copilot. Follow these steps:

  • GO to the command prompt and run the command copilot init. It will ask for the name of the application. Type the application name and press Enter. running comand copilot init
  • Next, it will ask what workload architecture is needed to build the application. This is a sample application, so choose Load Balanced web Service and click Enter. selecting workload architecture
  • Set a name for the service. set name for service
  • It will ask for the Dockerfile to build this application. In this case, a pre-created Dockerfile is in the demo_app folder, so choose that file and press Enter. (Otherwise, you may choose a custom Dockerfile and provide the custom path.) selecting dockerfile
  • Next, it will ask for the port number on which the customer traffic will be sent. Keep it default as port 80 and press Enter. port number
  • Now, it will build the infrastructure to build this app. My Dockerfile contains configurations to create different services in the backend, so that it will take time. build infrastructure
  • After it builds and creates the necessary services, it will ask to deploy it to a test environment. Type y for yes to proceed further. deploy test environment
  • It will take a few minutes and finally shows that the service API is deployed successfully. Copy the link to access the service. deploying service api successfully
  • Open the copied link in a new tab we will see our sample app is running fine. running sample app
  • We can run various commands like copilot app ls to see the application's name, copilot svc ls to see the services, and copilot svc status to check the status of the services. check status of copilot svc
  • We successfully built and deployed the sample demo app using copilot. It uses various AWS services, so it will be a good practice to delete the applications and related services to avoid additional charges. Run the command copilot app delete in the command prompt. It will ask to confirm the delete type y. It will start deleting the application and the AWS services it creates earlier. After a few minutes, the application and related AWS services are deleted successfully. deleting aws service

We successfully learn how to use AWS Copilot to build and deploy a sample demo app.

Note :

Installing Docker, AWS-CLI and creating an IAM user is a one-time setup to help you get started. Launching a container using AWS Copilot is a small fraction of this setup.

Working Using Command Line Only

Let's see the steps to build an app with satisfied prerequisites.

  1. You can quickly start by installing aws copilot on your system by using the brew command as given below:

If you are unfamiliar with brew, you can directly install the latest releases of AWS Copilot from GitHub using the curl command.

  1. You can create a Dockerfile with content as minimal as the one below:
  1. After this, you can follow the same steps mentioned under the section Build Sample App Using AWS Copilot.

AWS Copilot Alternatives & Comparisons

Listed below are a few alternatives to AWS Copilot.

Kubernetes

kubernetes logo

  • Kubernetes is a monitoring tool used to manage Docker containers.
  • It is helpful when we want to work on a multi-cloud setup. Multi-cloud setup is one in which some of our servers are running on, say, AWS, and others are running on another cloud like Azure.
  • Copilot can deploy container servers across multiple regions in one go, whereas we need to have separate Kubernetes software for monitoring each region.

Docker Swarm

docker swarm logo

  • Docker Swarm shares some common features with copilot.
  • It converts the multi-container application into a single application file and can deploy the application using a single command, just like AWS Copilot.
  • Although the working of Docker Swarm is slightly similar to AWS Copilot, it works well only for a small set of containers. If the number of containers exceeds a certain limit, the monitoring becomes difficult via the Docker swarm.

Spring Cloud

spring cloud logo

  • Spring Cloud helps developers to add some patterns in distributed systems
  • Some of the popular features of Spring cloud include it takes care of load balancing, routing, circuit breakers, etc.
  • It maintains versioning of the configurations and distributes the workload as needed.

Rancher

rancher logo

  • Rancher is a container management tool that is open source and available on GitHub, providing a lot of flexibility.
  • It includes distributions of Kubernetes, Apache Mesos, and Docker Swarm.
  • It can be integrated with many services like Jenkins, AWS EC2, Docker, GitHub, etc.

Conclusion

  • AWS Copilot is a command-line service that helps deploy a production-ready infrastructure for running our applications.
  • The entire process of building, deploying, and monitoring the container-based applications can be done with the help of single command via the terminal window.
  • It combines with other AWS services like AWS ECS, AWS App Runner, AWS Fargate, etc., to deploy the infrastructure to the cloud.
  • AWS Copilot allows us to set up multiple environments like testing, development, production, etc., and across multiple regions in one go.
  • Infrastructure scaling is also made easier with the help of AWS Copilot. Security is also one of the strong benefits provided by the copilot.
  • Major competitors of Copilot are Kubernetes, Docker Swarm, Spring Cloud, Rancher, etc. AWS Copilot stands as a tough competition with multiple features and uses cases.