> ## Documentation Index
> Fetch the complete documentation index at: https://cloud-architect.ipoint-labs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Introduction to Amazon Elastic Container Service (ECS)

> Hands-on lab · 45m

Launch this lab in the IP Lab Portal, then follow the steps below in the AWS console.

<a className="ip-lab-portal-btn" href="https://labs.intellectualpoint.com/labs/introduction-to-amazon-elastic-container-service-ecs" target="_blank" rel="noreferrer">
  Open IP Lab Portal
</a>

## Overview

### Lab details

1. This lab walks you through the steps to launch and configure an HTTPD container on an ECS Cluster.
2. You will practice using Amazon Elastic Container Service Cluster by creating Task definitions and tasks.
3. Duration: **60 minutes**
4. AWS Region: **US East (N. Virginia) us-east-1**

### Architecture diagram

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/001.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=21c091d749927637516ae7cb274654ed" alt="" width="920" height="480" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/001.png" />

### Task details

1. Sign in to the AWS Management Console
2. Create a Key Pair for the EC2 instances, inside the ECS Cluster
3. Launching an ECS Cluster
4. Create Task definitions.
5. Create a Service and start HTTPD container in ECS
6. Test the HTTPD container in ECS Cluster
7. SSH into the underlying EC2 instance and run Docker commands
8. Validation of the lab

### Launching the lab environment

1. To launch the lab environment, click on the **Launch lab** button.
2. Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
3. Once the Lab is started, you will be provided with **IAM user name**, **Password**, **Access** **Key**, and **Secret** **Access** **Key**.

<Note>
  You can only start one lab at any given time
</Note>

## Lab guide

**Lab Steps**

#### Task 1: Sign in to AWS Management Console

1. Click on the **Open console** button, and you will get redirected to AWS Console in a new browser tab.
2. On the AWS sign-in page,

* Leave the Account ID as default. Never edit/remove the 12-digit Account ID present in the AWS Console. Otherwise, you cannot proceed with the lab.
* Now copy your **User Name** and **Password** in the Lab Console to the **IAM Username and Password** in AWS Console and click on the **Sign-in** button

3. Once Signed In to the AWS Management Console, make the default AWS Region as **US East (N. Virginia) us-east-1.**

#### Task 2: Create a Key Pair for the EC2 instances, inside the ECS Cluster

1. Make sure you are in the **N.Virginia** Region. Navigate to **EC2** Service by clicking on the **Services** menu in the top, then click on **EC2** Service in the **Compute** section.
2. In the left navigation pane (scroll down) within **Network & Security**, click on the **Key pairs**
3. To create a new key pair, click on the **Create key pair** button.
4. Fill in the details below:

   * Name: Enter ***WhizKeyPair***
   * Key pair type : **RSA**
   * File format: **pem (Linux & Mac Users)** or **ppk (Windows users)**
   * Leave other options as default.
   * Click on the **Create key pair** button.

     <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/002.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=9baffabb02c6b64a2a9bb7fc6aedf069" alt="" width="1222" height="489" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/002.png" />

#### Task 3: Launching an ECS Cluster

1. Make sure you are in the **N.Virginia** Region. Navigate to **Elastic Container Service** by clicking on the **Services** menu in the top, then click on **Elastic Container Service** in the **Containers** section.

2. On the left sidebar, click on the **Clusters** option present under the **Amazon ECS** section, then Click on the **Create cluster** button.

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/003.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=776d85215b2e6af06e416cd3d130d579" alt="" width="1222" height="246" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/003.png" />

3. In Cluster configuration :

* Cluster name: enter **whizcluster**

  <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/004.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=4f1437c8f2d25ec101f32965c196c94f" alt="" width="1222" height="223" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/004.png" />

4. In Infrastructure Section :

   * Select **Fargate and Self-managed instances**.

     * Auto Scaling group (ASG): Select **Create new Auto Scaling Group**
     * Provisioning model: select **On-demand**

       * Container instance AMI : Select **Amazon Linux 2023**

       <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/005.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=439f0738c45cb787ce4e5b3d72798c13" alt="" width="1222" height="618" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/005.png" />
     * EC2 instance type : Select **t2.micro**
     * EC2 instance role: Choose the existing IAM role **EC2ECSClusterRoleProfile\_**

       Desired capacity :

       * Minimum : Enter **1**
       * Maximum :  Enter **2**
     * SSH Key pair: Select **WhizKeyPair**

       <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/006.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=b2967e947e4b3db6b9f54a3247c54b0e" alt="" width="1880" height="896" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/006.png" />

5. In Networking Section :

   * VPC: Select **Default VPC**
   * Subnets: Leave it as default.

6. Security group :

   * Select **create new security group**

     * Security group name : Enter **MySG**
     * Security group description : Enter **MySG**
   * Inbound rules for security groups:

     * Type : Select **SSH**
     * Source : Select **Anywhere**

       <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/007.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=9596872c4b6c68801695f61be44dae5c" alt="" width="1373" height="651" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/007.png" />

7. Keep rest things as default and click on **Create** button

8. ECS Cluster will be created

9. It will take few minutes to provision the ECS Instance.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/008.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=f25d6323f1fe1f84f4c610ea54669018" alt="" width="1222" height="259" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/008.png" />

#### Task 4: Create Task Definitions

In this task, we are going to create a task definition for the cluster. A task definition provides a blueprint for creating tasks, which are the basic unit of work in ECS. Each task definition can define one or more containers that are run together on the same underlying EC2 instances or Fargate tasks.

1. On the left sidebar, click on the **Task Definitions** option present under the **Amazon ECS** section.
2. Click on the **Create new task definition** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/009.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=ae8696434c85003a08755add3509214f" alt="" width="1222" height="276" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/009.png" />

3. In Task definition configuration:

* Task definition family: Enter ***ecs-demo***

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/010.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=df3e166248aa697647be80fc192dbc2e" alt="" width="1222" height="198" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/010.png" />

4. For Infrastructure requirements :

   * Launch Type : select **Amazon EC2 Instances**
   * Task size :

     * CPU : Enter **.25 vCPU**
     * Memory : Enter **.5 GB**

       * In Task Role: **Choose none**
       * In task execution role: **Choose none**

         <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/011.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=df22de7423a3d4f6700fd0adb2598e3a" alt="" width="1592" height="1304" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/011.png" />

5. Under Container - 1:

   * Name: Enter ***httpd***
   * Image URL: Enter ***httpd:2.4***

6. Under Port mappings :

   * Container port : Enter **80**
   * Protocol : Select **TCP**
   * App protocol : Select **HTTP**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/012.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=3255aa020297b0c006e61bbd0f938320" alt="" width="1222" height="537" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/012.png" />

7. Keep rest things as default and click on the **Create** button

8. Task Definition **ecs-demo** is now created.

#### Task 5: Create a service and start HTTPD container in ECS

In this task, we are going to create a service and start the HTTPD container. In AWS ECS (Elastic Container Service), a service is a long-running task that ensures that a specified number of instances of a task definition are running and maintained in an ECS cluster. Services allow you to define the desired state of your tasks and automatically handle task placement, scaling, and recovery.

1. On the left sidebar, click on the **Task definitions** option present under the **Amazon ECS** section.
2. Select **ecs-demo** and click on **Deploy** and click **Create service** button.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/013.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=99973fa3606f76cc1677f70b6ab4973e" alt="" width="1222" height="204" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/013.png" />

3. In Service details: Choose Task definition revision: select the latest revision.

4. Service name: Enter **httpd**

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/014.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=c05c498b73b7bf2b249b77682a3ec0fb" alt="" width="1222" height="495" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/014.png" />

5. Cluster will get selected by default.

6. In Compute configuration:

* Choose Compute option as **Launch type** and select the Launch type as **EC2**

  <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/015.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=0b5be0a071ae272669371ccc89febde2" alt="" width="1222" height="619" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/015.png" />
* In **Deployment configuration**, Scheduling strategy: Select **REPLICA.**
* Desired tasks : Enter **1**

  <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/016.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=9199d7a337850d3b6e2bec276e10b1f8" alt="" width="1021" height="322" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/016.png" />

7. In Networking section:

* VPC: select the **default vpc**
* Subnets: leave it as default
* Security Group: click on **Use an existing security group** and select **MySG**.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/017.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=415dcf41b67b211d91181ffef253969e" alt="" width="1222" height="666" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/017.png" />

8. Keep other options as default, and click on the **Create** button.

9. The service will be created, wait till the Deployments and tasks changes to 1/1 tasks running

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/018.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=28c989c5cadede1e84bce1d9a44ddf21" alt="" width="1222" height="291" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/018.png" />

10. Now navigate to Infrastructure tab, and scroll down to the Container Instances

11. Click on the EC2 Instance ID, and you will be redirected to the running EC2 instance.

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/019.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=408e5eba7c2494befdf0bed983faecae" alt="" width="1222" height="516" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/019.png" />

#### Task 6: SSH into the underlying EC2 instance and run Docker commands

1. Please follow the steps in [SSH into EC2 Instance](/aws-cp/support/ssh-into-ec2-instance)
2. Please note that the Ec2 instance connect will not work for the ECS instance, so please try other SSH methods.
3. Get the root access using the following command:

   ```
   sudo su
   ```
4. Now run the updates using the following command:

   ```
   sudo dnf update -y
   ```
5. Check the Docker version by running the following command:

   ```
   docker version
   ```
6. Check all the docker processes running in the ECS Cluster

   ```
   docker ps
   ```

<img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/020.png?fit=max&auto=format&n=S7TRbFaK099mvCQ6&q=85&s=839f5953edf9b064f1efb48cd3c23091" alt="" width="2862" height="314" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/020.png" />

* Default ECS agent and httpd container is running in the underlying EC2 instance

<Tip>
  **Do you know?**

  One unique fact about AWS ECS is its support for the FireLens container logging system. FireLens allows you to route logs from containers running on ECS to various AWS services, such as Amazon CloudWatch Logs, Amazon Kinesis Data Firehose, or even third-party log aggregators.
</Tip>

### Task 7: Validation Test

1. Once the lab steps are completed, please click on the **Check my work** button on the left side panel.
2. This will validate the resources in the AWS account and displays whether you have completed this lab successfully or not.
3. Sample output :

   <img src="https://mintcdn.com/ip-cloud-architect-pathway/S7TRbFaK099mvCQ6/images/labs/introduction-to-amazon-elastic-container-service-ecs/021.gif?s=d0f8ee99617113bb7b060905392e34c8" alt="" width="1001" height="647" data-path="images/labs/introduction-to-amazon-elastic-container-service-ecs/021.gif" />

#### Completion and conclusion

* You have successfully created and launched ECS Cluster
* You have successfully created an HTTPD Container

#### End lab

* Sign out of AWS Account
* You have successfully completed the lab
* Once you have completed the steps, click on **End lab** in the IP Lab Portal

## What gets checked

When you press **Check my work**, the platform verifies each of these:

* **Check ECS Cluster Exists** — Check ECS cluster is created or not
* **Create ECS Service** — Check whether ECS service created or not
* **Create ECS Task Definition** — Check whether ECS task definition created or not
* **Launch an EC2 Instance** — Check whether an EC2 Instance is launched or not.

## Related help

* [FAQs and Troubleshooting](/aws-cp/support/faqs-and-troubleshooting)
* [SSH into EC2 Instance](/aws-cp/support/ssh-into-ec2-instance)
