You are currently viewing How to create, deploy and manage an application in AWS ECS using Copilot?

How to create, deploy and manage an application in AWS ECS using Copilot?

How to create, deploy and manage an application in AWS ECS using Copilot?

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

Today we are going to discuss, how to deploy a container application in AWS ECS using AWS Copilot.

What is AWS Copilot?

The Copilot CLI is a tool for developers to build, release, and operate production-ready containerized applications on AWS App Runner, Amazon ECS, and AWS Fargate.

Copilot makes it super easy to set up and deploy your containers on AWS – but getting started is only the first step of the journey. What happens when you want to have one copy of your service running only for testing and another copy serving production traffic? What happens when you want to add another service? How do you manage deploying to all of these services? Copilot wants to help you with all of these things so let’s jump into some of Copilot’s core concepts to understand how they can help.

Applications:

An Application is a collection of services and environments. When you get started with Copilot, the first thing you’ll be asked to do is choose an application name. This can be a high level description of the product you’re trying to build. An example might be an application named “chat” which has two services “frontend” and “api”. These two services could then be deployed to a “test” and “production” environment.

Environments:

Rumor has it, there are people out there that can write perfect code on the first go without any bugs. While we tip our hats to those folks, we believe it’s important to be able to test new code on a non-customer facing version of your service before promoting to production. In Copilot we do this by using environments. Each environment can have its own version of a service running allowing you to create a “test” and “production” environment. You can deploy your service to the test environment, make sure everything looks good, then deploy to your production environment. Since each environment is independent, if you deploy a bug to your test environment, customers using a service deployed to your production environment will be fine.

Services:

A service is your code and all of the supporting infrastructure needed to get it up and running on AWS. When you first get started setting up a service, Copilot will ask you what type of service you want to create. The type of service determines the infrastructure that’ll be created to support your code. If you want your code to serve traffic from the internet, for example, Copilot can set up an Application Load Balancer and an Amazon ECS Service running on AWS Fargate.

Jobs:

Jobs are ephemeral Amazon ECS tasks that are triggered by an event. Once their work is done, the task terminates. Just like services, Copilot will ask you all the necessary information to quickly get going with a scheduled task on AWS. The manifest file can always be used to adjust the configuration and provide more advanced settings.

Pipelines:

Now that you’ve got an application with a few services deployed to a couple of environments, staying on top of those deployments can become tricky. Copilot can help by setting up a release pipeline that deploys your service whenever you push to your git repository. (At this time, Copilot supports GitHub, Bitbucket, and CodeCommit repositories.) When a push is detected, your pipeline will build your service, push the image to ECR, and deploy to your environments.

Credentials:

  1. Application credentials: Copilot uses the AWS credentials from the default credential provider chain to store and look up your application’s metadata: which services and environments belong to it. Alternatively, you can set the AWS_PROFILE environment variable to point to a different named profile. For example, we can have a [my-app] profile that can be used for your Copilot application instead of the [default] profile.
  2. Environment credentials: Copilot environments can be created in AWS accounts and regions separate from your application’s. While initializing an environment, Copilot will prompt you to enter temporary credentials or a named profile to create your environment.

Manifest:

The AWS Copilot CLI manifest describes a service’s or job’s architecture as infrastructure-as-code. It is a file generated from copilot init, copilot svc init, or copilot job init that gets converted to an AWS CloudFormation template. Unlike raw CloudFormation templates, the manifest allows you to focus on the most common settings for the architecture of your service or job, and not the individual resources. Manifest files are stored under copilot/<your service or job name>/manifest.yml.

How to create, deploy and manage an application in AWS ECS using Copilot?

Prerequisites:

Step 1: Clone AWS provided sample ECS application.

Step 2: Initialize and deploy your containerize application in AWS ECS using Copilot.

Copilot will prompt to supply some options, provide the value as show below –

  • Application name: myapp
  • Workload type: Load Balanced Web Service
  • Service name: api
  • Dockerfile: ./Dockerfile
  • Port: 80
  • Deploy: Yes

Here the full excerpt for your reference.

One the application is deployed; you can curl or browse the link to check if your application is working properly.

Step 3: Check if your application is successfully deployed

Step 4: Get details on your application, environment and services using AWS Copilot command.

Next, we will a new version of the application using copilot.

Step 5: Deploy a new version of the application using AWS copilot.

Step 6: Check if new version of the application is successfully deployed

Step 7: Clean up.

Hope you have enjoyed this article, to get more details on AWS ECS, please follow below link.

https://docs.aws.amazon.com/ecs/index.html

To get more details in AWS Copilot, please refer below documentation

https://aws.github.io/copilot-cli/docs/overview/

Leave a Reply