Getting started with Amazon ECS using Amazon Copilot
Get started with Amazon ECS using Amazon Copilot by deploying an Amazon ECS application.
Prerequisites
Before you begin, make sure that you meet the following prerequisites:
-
Set up an Amazon account. For more information see Set up to use Amazon ECS.
-
Install the Amazon Copilot CLI. Releases currently support Linux and macOS systems. For more information, see Installing the Amazon Copilot CLI.
-
Install and configure the Amazon CLI. For more information, see Amazon Command Line Interface.
-
Run
aws configure
to set up a default profile that the Amazon Copilot CLI will use to manage your application and services. -
Install and run Docker. For more information, see Get started with Docker
.
Deploy your application using one command
Make sure that you have the Amazon command line tool installed and have already run
aws configure
before you start.
Deploy the application using the following command.
git clone https://github.com/aws-samples/amazon-ecs-cli-sample-app.git demo-app && \ cd demo-app && \ copilot init --app
demo
\ --nameapi
\ --type'Load Balanced Web Service'
\ --dockerfile'./Dockerfile'
\ --port80
\ --deploy
Deploy your application step by step
Step 1: Configure your credentials
Run aws configure
to set up a default profile that the Amazon Copilot CLI uses
to manage your application and services.
aws configure
Step 2: Clone the demo app
Clone a simple Flask application and Dockerfile.
git clone https://github.com/aws-samples/amazon-ecs-cli-sample-app.git demo-app
Step 3: Set up your application
-
From within the demo-app directory, run the
init
command.For Windows users, run the
init
command from the folder that contains the downloadedcopilot.exe
file.copilot init
Amazon Copilot walks you through the setup of your first application and service with a series of terminal prompts, starting with next step. If you have already used Amazon Copilot to deploy applications, you're prompted to choose one from a list of application names.
-
Name your application.
What would you like to name your application? [? for help]
Enter
.demo
Step 4: Set up an ECS Service in your "demo" Application
-
You're prompted to choose a service type. You're building a simple Flask application that serves a small API.
Which service type best represents your service's architecture? [Use arrows to move, type to filter, ? for more help] > Load Balanced Web Service Backend Service Scheduled Job
Choose
Load Balanced Web Service
-
Provide a name for your service.
What do you want to name this Load Balanced Web Service? [? for help]
Enter
for your service name.api
-
Select a Dockerfile.
Which Dockerfile would you like to use for api? [Use arrows to move, type to filter, ? for more help] > ./Dockerfile Use an existing image instead
Choose
.Dockerfile
For Windows users, enter the path to the Dockerfile in the
demo-app folder
(*`...\demo-app\Dockerfile`*\.). -
Define port.
Which port do you want customer traffic sent to? [? for help] (80)
Enter
or accept default.80
-
You will see a log showing the application resources being created.
Creating the infrastructure to manage services under application demo.
-
After the application resources are created, deploy a test environment.
Would you like to deploy a test environment? [? for help] (y/N)
Enter
.y
Proposing infrastructure changes for the test environment.
-
You will see a log displaying the status of your application deployment.
Note: It's best to run this command in the root of your Git repository. Welcome to the Copilot CLI! We're going to walk you through some questions to help you get set up with an application on ECS. An application is a collection of containerized services that operate together. Use existing application:
No
Application name:demo
Workload type:Load Balanced Web Service
Service name:api
Dockerfile:./Dockerfile
no EXPOSE statements in Dockerfile ./Dockerfile Port:80
Ok great, we'll set up aLoad Balanced Web Service
namedapi
in applicationdemo
listening on port80
. ✔ Created the infrastructure to manage services under applicationdemo
. ✔ Wrote the manifest for serviceapi
at copilot/api
/manifest.yml Your manifest contains configurations like your container size and port (:80). ✔ Created ECR repositories for serviceapi
. All right, you're all set for local development. Deploy: Yes ✔ Created the infrastructure for the test environment. - Virtual private cloud on 2 availability zones to hold your services [Complete] - Virtual private cloud on 2 availability zones to hold your services [Complete] - Internet gateway to connect the network to the internet [Complete] - Public subnets for internet facing services [Complete] - Private subnets for services that can't be reached from the internet [Complete] - Routing tables for services to talk with each other [Complete] - ECS Cluster to hold your services [Complete] ✔ Linked accountaws_account_id
and regionregion
to applicationdemo
. ✔ Created environment test in regionregion
under applicationdemo
. Environment test is already on the latest version v1.0.0, skip upgrade. [+] Building 0.8s (7/7) FINISHED => [internal] load .dockerignore 0.1s => => transferring context: 2B 0.0s => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 37B 0.0s => [internal] load metadata for docker.io/library/nginx:latest 0.7s => [internal] load build context 0.0s => => transferring context: 32B 0.0s => [1/2] FROM docker.io/library/nginx@sha256:aeade65e99e5d5e7ce162833636f692354c227ff438556e5f3ed0335b7cc2f1b 0.0s => CACHED [2/2] COPY index.html /usr/share/nginx/html 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:3ee02fd4c0f67d7bd808ed7fc73263880649834cbb05d5ca62380f539f4884c4 0.0s => => naming toaws_account_id
.dkr.ecr.region
.amazonaws.com/demo
/api
:cee7709 0.0s WARNING! Your password will be stored unencrypted in /home/user/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded The push refers to repository [aws_account_id
.dkr.ecr.region
.amazonaws.com/demo
/api
] 592a5c0c47f1: Pushed 6c7de695ede3: Pushed 2f4accd375d9: Pushed ffc9b21953f4: Pushed cee7709: digest: sha_digest ✔ Deployed api, you can access it at http://demo-Publi-1OQ8VMS2VC2WG-561733989.region
.elb.amazonaws.com.
Step 5: Verify your application is running
View the status of your application by using the following commands.
List all of your Amazon Copilot applications.
copilot app ls
Show information about the environments and services in your application.
copilot app show
Show information about your environments.
copilot env ls
Show information about the service, including endpoints, capacity and related resources.
copilot svc show
List of all the services in an application.
copilot svc ls
Show logs of a deployed service.
copilot svc logs
Show service status.
copilot svc status
List available commands and options.
copilot --help
copilot init --help
Step 6. Learn to create a CI/CD Pipeline
Instructions can be found in the ECS Workshop
Step 7: Clean up
Run the following command to delete and clean up all resources.
copilot app delete