Creating Amazon ECS resources using the AWS Copilot command line interface

To Nha Notes | July 18, 2024, 6:37 p.m.

The Copilot CLI is a tool for developers to build, release, and operate production-ready containerized applications on AWS App Runner and Amazon ECS on AWS Fargate. From getting started, pushing to staging, and releasing to production, Copilot can help manage the entire lifecycle of your application development.

Target technology stack  

  • AWS environment set up with a virtual private cloud (VPC), public and private subnets, and security groups

  • Amazon ECS cluster

  • Amazon ECS service and task definition

  • Amazon Elastic Container Registry (Amazon ECR)

  • Amazon DynamoDB

  • Application Load Balancer

  • AWS Fargate

  • Amazon Identity and Access Management (IAM)

  • Amazon CloudWatch

  • AWS CloudTrail

Target architecture 

When you deploy the sample application for this pattern, multiple tasks are created and deployed in separate Availability Zones. Each task stores data in Amazon DynamoDB. When you access the webpage for a task, you can view the data from all other tasks.

 

Architecture for deploying containers with AWS Copilot

Installing the AWS Copilot CLI

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/copilot-install.html

Deploying a sample Amazon ECS application using the AWS Copilot CLI

Deploy a sample web application that is cloned from a GitHub repository using the following command. For more information about AWS Copilot init and its flags, see the AWS Copilot documentation.

git clone https://github.com/aws-samples/aws-copilot-sample-service.git demo-app && \ 
cd demo-app &&                               \
AWS_PROFILE=<AWS_PROFILE> copilot init --app demo                      \
  --name api                                 \
  --type 'Load Balanced Web Service'         \
  --dockerfile './Dockerfile'                \
  --port 80                                  \
  --deploy

After the deployment is complete, the copilot CLI will return a URL that you can use to verify the deployment. You can also use the following commands to verify the app's status.

  • List all of your copilot applications.

AWS_PROFILE=<AWS_PROFILE> copilot app ls

  • Show information about the environments and services in your application.

AWS_PROFILE=<AWS_PROFILE> copilot app show

  • Show information about your environments.

AWS_PROFILE=<AWS_PROFILE> copilot env ls

  • Show information about the service, including endpoints, capacity and related resources.

AWS_PROFILE=<AWS_PROFILE> copilot svc show

  • List of all the services in an application.

AWS_PROFILE=<AWS_PROFILE> copilot svc ls

  • Show logs of a deployed service.

AWS_PROFILE=<AWS_PROFILE> copilot svc logs

  • Show service status.

AWS_PROFILE=<AWS_PROFILE> copilot svc status

  • When you're finished with this demo, run the following command to clean up associated resources and avoid incurring charges for unused resources.

AWS_PROFILE=<AWS_PROFILE> copilot app delete

 
References

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Copilot.html

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/copilot-deploy.html

https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/deploy-a-clustered-application-to-amazon-ecs-by-using-aws-copilot.html

https://aws.github.io/copilot-cli/docs/getting-started/first-app-tutorial/

https://aws.github.io/copilot-cli/docs/commands/init/

https://community.aws/content/2bx7S1uWyARNnlfcjlFRGWZSZrf/navigate-your-containerized-apps-to-success-with-aws-copilot?lang=en