Skip to main content
Launch this lab in the IP Lab Portal, then follow the steps below in the AWS console. Open IP Lab Portal

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

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.
You can only start one lab at any given time

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
  1. 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.

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.
  3. In Cluster configuration :
  • Cluster name: enter whizcluster
  1. 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
      • 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
  2. In Networking Section :
    • VPC: Select Default VPC
    • Subnets: Leave it as default.
  3. 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
  4. Keep rest things as default and click on Create button
  5. ECS Cluster will be created
  6. It will take few minutes to provision the ECS Instance.

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.
  1. In Task definition configuration:
  • Task definition family: Enter ecs-demo
  1. 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
  2. Under Container - 1:
    • Name: Enter httpd
    • Image URL: Enter httpd:2.4
  3. Under Port mappings :
    • Container port : Enter 80
    • Protocol : Select TCP
    • App protocol : Select HTTP
  1. Keep rest things as default and click on the Create button
  2. 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.
  1. In Service details: Choose Task definition revision: select the latest revision.
  2. Service name: Enter httpd
  1. Cluster will get selected by default.
  2. In Compute configuration:
  • Choose Compute option as Launch type and select the Launch type as EC2
  • In Deployment configuration, Scheduling strategy: Select REPLICA.
  • Desired tasks : Enter 1
  1. 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.
  1. Keep other options as default, and click on the Create button.
  2. The service will be created, wait till the Deployments and tasks changes to 1/1 tasks running
  1. Now navigate to Infrastructure tab, and scroll down to the Container Instances
  2. Click on the EC2 Instance ID, and you will be redirected to the running EC2 instance.

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

  1. Please follow the steps in 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:
  4. Now run the updates using the following command:
  5. Check the Docker version by running the following command:
  6. Check all the docker processes running in the ECS Cluster
  • Default ECS agent and httpd container is running in the underlying EC2 instance
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.

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 :

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.