Using AWS Copilot: Beginner’s Guide to Container Deployment

Last Updated on

CraftyTechie is reader-supported. When you buy through links on our site, we may earn an affiliate commission.

AWS Copilot is a command-line interface tool that simplifies containerized application deployment on Amazon Elastic Container Service (ECS). It is a tool designed to make the deployment process more straightforward and faster, especially for new ECS users who want to move beyond the manual management of lower-level infrastructure. 

aws copilot

AWS Copilot enables developers to focus more on developing high-quality applications and less on worrying about the underlying infrastructure. By automating many of the complex infrastructure and deployment tasks, Copilot creates modern application deployments based on production-ready patterns that include best practices designed by ECS engineers and customers over the years. 

This article will discuss AWS Copilot’s features, use cases, fundamental concepts, and deployment process, and how it addresses pain points associated with manual deployment.

AWS Copilot | Deploy Application with One Command 

Run the following command to deploy your containerized application to AWS ECS using AWS Copilot.

$ git clone [REPOSITORY URL]&& \ 
cd [PROJECT DIRECTORY] &&                               \
copilot init --app demo                      \
  --name api                                 \
  --type 'Load Balanced Web Service'         \
  --dockerfile './Dockerfile'                \
  --port 80                                  \
  --deploy

New to AWS Copilot? Learn step by step deployment process in this article.

Article Highlights

  • AWS Copilot is a command-line tool designed to simplify the process of deploying and managing containerized applications on Amazon ECS.
  • Some of the features include simplified application creation, automated infrastructure provisioning, and seamless deployment workflows.
  • It is suitable for a variety of use cases, such as deploying microservices, web applications, and APIs.
  • It automates much of the manual work associated with deploying on ECS, including VPC and subnet creation, load balancer configuration, and deployment pipelines.
  • The deployment process involves defining the application, environment, and service, followed by building and deploying the container images.

Table of Contents

Deploying to Amazon Elastic Container Service (ECS)

Amazon Elastic Container Service (ECS) is a fully-managed service, it doesn’t work in isolation but works on top of computing infrastructure such as EC2 or Fargate. Therefore, deploying a containerized application requires extensive knowledge and expertise in more than just ECS.

Here’s a usual deployment process of a containerized application to ECS.  

  1. Create a containerized application and push it to a container registry, such as Amazon Elastic Container Registry (ECR).
  1. Manually create and configure the necessary infrastructure resources, such as EC2 instances, VPC, security groups, and load balancers.
  1. Manually create an ECS task definition that defines how to run the containerized application, including the container image, CPU and memory requirements, and networking configuration.
  1. Create an ECS service that defines how many tasks should be run, how they should be distributed across the EC2 instances, and how they should be monitored and auto-scaled.
  1. Deploy the ECS service to the ECS cluster, which starts the tasks on the EC2 instances.
  1. Monitor the ECS service for errors and manually troubleshoot any issues that arise.
  1. Update the ECS service when a new version of the application is available by creating a new task definition, updating the service to use the new task definition, and then deploying the application to the ECS cluster.

The process not only sounds intimidating but is actually a daunting chore, especially for someone with a lack of experience and expertise. 

AWS Copilot to the Rescue!

Amazon Copilot automates the manual deployment process for ECS users so that they can focus on their application and its lifecycle rather than worrying about infrastructure setup and configuration. It uses production-ready patterns, which include time-tested and best practices for modern deployment and based on that data, it helps automate the process.

All you need to do is run an init command and provide input to a few prompts and Copilot creates resources, builds a container and deploys it to the cloud. After all the hard work it does on your behalf,  it provides you URI of your deployed application. Learn more about deploying with Copilot.

Features | AWS Copilot

AWS Copilot provides many features that help developers streamline containerized application development and deployment. Some of the key features are:

  • Application and environment management: It provides a simple CLI interface to create, manage, and delete applications and environments. Users can create multiple environments for testing, staging, and production and manage them independently.
  • Service templates: It comes with pre-built service templates that allow developers to quickly set up containerized applications with all the necessary configuration and infrastructure settings.
  • Infrastructure management:It manages the underlying infrastructure for containerized applications, including networking, load balancing, and auto-scaling.
  • Continuous Integration/Continuous Deployment (CI/CD): It integrates seamlessly with popular CI/CD tools such as Jenkins, GitLab, and AWS CodePipeline.
  • Monitoring and logging: It returns health status, infrastructure details and logs with one command.

Pros and Cons

ProsCons
Simplifies containerized application development and deploymentLimited to AWS infrastructure
Provides pre-built service templates for common application typesIt may require some knowledge of AWS architecture and infrastructure
Integrates with popular CI/CD toolsCLI-based interface may not be as user-friendly as GUI-based tools
Monitoring and logging with one commandLimited customization options for infrastructure settings
Supports microservices and distributed applications

Use Cases

AWS Copilot is well-suited for a wide range of use cases, including:

  • Microservices: It is designed to simplify the deployment and management of microservices on Amazon ECS. It provides a streamlined workflow for deploying multiple services within a single ECS cluster, with automated load balancing and service discovery.
  • Web Applications: It can be used to deploy and manage web applications on Amazon ECS. It provides built-in support for HTTP routing and SSL termination, making it easy to set up a scalable and secure web application.
  • Containerized Workloads: It can be used to deploy and manage any containerized workload on Amazon ECS, including custom applications, third-party software, and open-source projects. It provides a flexible and customizable workflow that can be adapted to a wide range of use cases.
  • DevOps Pipelines: It can be integrated with CI/CD tools like AWS CodePipeline and GitHub Actions to create automated deployment pipelines for containerized applications. This makes it easy to deploy new versions of an application to production without manual intervention.
  • Multi-Environment Deployments: It can be used to deploy and manage applications across multiple environments, such as development, staging, and production. It provides a consistent workflow for deploying and managing applications in different environments, which can help reduce errors and improve efficiency.
  • Scalable Applications: It can help developers scale applications on Amazon ECS automatically. It provides built-in support for load balancing, auto-scaling, and service discovery, making it easy to create highly available and scalable applications.

Fundamental Concepts

Here are the fundamental concepts of AWS Copilot.

Application

An application is a collection of related services that work together to perform a specific function. Each application can have multiple environments and services.

Environment

An environment is a specific deployment of an application. It can be a development, staging, or production environment. Each environment has its own infrastructure, such as EC2 instances and load balancers, and is isolated from other environments.

Service

A service is a running code inside a container. Your application can have one or more services. A distributed application has one or more services while a monolith application can have only one service. These services together form components of an application.

Installation

AWS Copilot can be installed on a local machine using a package manager or by downloading the binary from the AWS Copilot GitHub repository

Prerequisites

Before installing AWS Copilot, you need to have the following installed on your machine:

You can install AWS Copilot using one of the following methods:

  • Homebrew (macOS): If you’re using macOS, you can install AWS Copilot using Homebrew by running the following command:
$ brew install aws/tap/copilot-cli
  • Linux (apt-get): If you’re using a Linux distribution that supports apt-get, you can install AWS Copilot by running the following commands:
$ sudo apt-get update
$ sudo apt-get install -y copilot
  • Manual installation: If you’re unable to use either of the above methods, you can download the AWS Copilot binary from the AWS Copilot GitHub repository and install it manually. Learn more about manual installation.

Deployment with AWS Copilot

#1 – Configure AWS credentials

Before using CLI it is important to set up a local AWS profile using your AWS access and secret keys. Learn how to generate those.

To configure CLI, run the following command:

$ aws configure

#2 – Clone your application

Clone your application from GitHub using the following command. Replace the [REPOSITORY URL] with the URL of your project’s repository.

$ git clone [REPOSITORY URL]

#3 – Set up your application

From your project directory, run the following command.
Note: For Windows users, make sure to run the command from the folder that contains copilot.exe.

$ copilot init


Provide a name for your application. We will name it demo.

$ What would you like to name your application? [? for help]

#4 Set up ECS service for your application

Copilot CLI prompts you to choose the type of architecture. We will choose Load Balanced Web Service. You can choose what describes your application best.

$ Which workload type best represents your architecture?  [Use arrows to move, type to filter, ? for more help]
    Request-Driven Web Service  (App Runner)
 >  Load Balanced Web Service   (Internet to ECS on Fargate)
    Backend Service             (ECS on Fargate)
    Worker Service              (Events to SQS to ECS on Fargate)
    Scheduled Job               (Scheduled event to State Machine to Fargate)

Provide a name for your service. We will name it api.

$ What do you want to name this Load Balanced Web Service? [? for help]

The following option lets you decide to provide a path to the Dockerfile of your application or an existing Docker image. We will provide it with a custom path.

$ Which Dockerfile would you like to use for api?  [Use arrows to move, type to filter, ? for more help]
  > Enter custom path for your Dockerfile
    Use an existing image instead

Provide a port. We will keep the default 80.

$ Which port do you want customer traffic sent to? [? for help] (80)

Following all these configurations, you will see the following logs which signify that your application resources are being created.

Ok great, we'll set up a Load Balanced Web Service named api in application demo listening on port 80.

After creating application resources, it will ask you whether to deploy a test application. You can always deploy it later. We will choose y to let it deploy.

$  Would you like to deploy a test environment? [? for help] (y/N)

Deployment takes a while. If everything goes well CLI will provide URI on your deployed application.

✔ Deployed api, you can access it at http://demo-Publi-19INQC23YVLHE-1242135530.us-east-1.elb.amazonaws.com

#5 Verify your application

You can access endpoints on your application to see if it works. We get the following output.

aws copilot

AWS Copilot has the following useful commands to view the status of your application:

  • List AWS Copilot applications
$ copilot app ls
  • Show application environments and services information
$ copilot app show
  • List of all the services in an application.
$ copilot svc ls
  • Show logs of a deployed service.
$ copilot svc logs
  • Shows service status.
$ copilot svc status
  • Run the following to learn other commands.
$ copilot --help

Delete your deployed application

Finally, if you want to delete your deployment try running the following command.

$ copilot app delete

Deploy your Application with One Command

We have already seen a step-by-step deployment process. Copilot can do the entire process with one command. Just make sure you have your AWS profile configured with aws configure. Run the following command to deploy your application.

$ git clone [REPOSITORY URL]&& \ 
cd [PROJECT DIRECTORY] &&                               \
copilot init --app demo                      \
  --name api                                 \
  --type 'Load Balanced Web Service'         \
  --dockerfile './Dockerfile'                \
  --port 80                                  \
  --deploy

Frequently Asked Questions

What is the cost of using AWS Copilot?

AWS Copilot is a free and open-source command-line interface (CLI) tool provided by AWS. There are no additional charges for using AWS Copilot itself. However, the underlying AWS services used by AWS Copilot, such as Amazon ECS and AWS Fargate, may incur charges based on their usage.

What types of applications can be deployed with AWS Copilot?

AWS Copilot supports deploying containerized applications to Amazon Elastic Container Service (ECS) or AWS Fargate. The applications can be written in any programming language or framework, as long as they can be packaged as a Docker container. 

AWS Copilot simplifies the process of deploying, releasing, and operating containerized applications by providing a higher-level abstraction over the underlying infrastructure. This makes it easier to manage complex containerized applications and focus on developing business logic rather than worrying about infrastructure details.

What deployment workflows does AWS Copilot support?

  1. Local development: Developers can use AWS Copilot to test and debug their applications on their local machines before deploying them to a production environment.
  1. Manual deployment: AWS Copilot can generate CloudFormation templates that automate the creation of ECS or Fargate resources. Developers can use these templates to deploy their applications to a production environment.
  1. Continuous deployment: AWS Copilot integrates with popular CI/CD tools like AWS CodePipeline, Jenkins, and GitLab to automate the deployment of new versions of an application as soon as they are committed to a code repository.
  1. Blue/green deployment: AWS Copilot can be used to deploy new versions of an application to a separate environment, test it, and then swap it with the existing environment to minimize downtime.
  1. Rolling deployment: AWS Copilot can perform a rolling deployment by updating a subset of the containers in an ECS service or Fargate task at a time while keeping the rest of the containers running. This helps ensure that the application stays available during the deployment process.

How is AWS Copilot different from other deployment tools?

AWS Copilot is a modern and streamlined deployment tool that is designed to simplify the deployment and management of containerized applications on Amazon ECS and AWS Fargate. Here are some ways in which AWS Copilot differs from other deployment tools:

  1. Integrated Infrastructure Management: Unlike other deployment tools, AWS Copilot automates the creation and management of the underlying infrastructure resources required to deploy and run containerized applications, such as VPCs, subnets, load balancers, and security groups. This eliminates the need for users to manually manage infrastructure resources, reducing complexity and increasing efficiency.
  1. Simple CLI interface: AWS Copilot provides a simple and intuitive command-line interface (CLI) that enables users to easily create, deploy, and manage their containerized applications on Amazon ECS and AWS Fargate, without the need for extensive knowledge of these services.
  1. Modern Application Deployment: AWS Copilot provides a set of best practices for deploying modern, scalable, and fault-tolerant containerized applications that are designed for production environments. This includes support for multiple environments, deployment pipelines, and application health checks.
  1. Open-Source and Community-Driven: AWS Copilot is open-source and community-driven, meaning that users can contribute to the development of the tool and benefit from the contributions of others. This also means that AWS Copilot is constantly evolving and improving based on user feedback and the latest industry best practices.
  1. Built for AWS: AWS Copilot is specifically designed to work seamlessly with other AWS services, such as Amazon ECS and AWS Fargate, providing a native and integrated deployment experience that is optimized for the AWS cloud.

Conclusion

AWS Copilot is a command line tool that simplifies the process of deploying and managing containerized applications on Amazon ECS. It automates many of the manual tasks associated with deploying on ECS, such as VPC and subnet creation, load balancer configuration, and deployment pipelines. AWS Copilot supports a variety of application types, including microservices, web applications, and APIs, and it can be easily installed and used with any standard code repository.

The deployment process involves defining the application, environment, and service, followed by building and deploying the container images. AWS Copilot offers a streamlined and efficient process for containerized application deployment, compared to manual deployment on ECS or other deployment tools.

We have demonstrated how to deploy a containerized PHP application using AWS Copilot. The deployment process is entirely automated and requires nothing more than providing a few inputs. AWS Copilot does the whole weight lifting so that developers can focus on their application and its lifecycle.

Hope this article has been helpful. Stay tuned for more at FuelingPHP.

Building Web Applications in AWS

This article is part of our series to make AWS easy. We love AWS, but let’s be honest. It isn’t effortless. It’s way too complicated. We’ve created this learning path to help level you up and onboard your PHP app quickly.

Did you find this article helpful?

Join the best weekly newsletter where I deliver content on building better web applications. I curate the best tips, strategies, news & resources to help you develop highly-scalable and results-driven applications.

Build Better Web Apps

I hope you're enjoying this article.

Get the best content on building better web apps delivered to you.