ITM 300 - Cloud Foundations

Module 10: Product 10 Lab - Containers

list

Quick Oil Change and Repair

Product Objective

In this lab, we will containerize our vehicle service application, enabling it to auto-scale and utilize a load balancer. By following these steps, you will learn how to configure Docker, create a container registry, and deploy containers using ECS and Fargate. This process will enhance the reliability and scalability of your application.

Add / Verify IAM Role

Install and Configure Docker to work with AWS

Install Docker

sudo dnf install -y docker

Add your AWS Credentials:

mkdir ~/.aws
cd ~/.aws
touch credentials

Example of AWS Token Box

Credentials

Please note that this file doesn't have an extension. It is just called credentials

aws configure

When you run this command it should read from the credentials file you just created. If the access key shows [None], you'll need to paste in the correct information from the ASW Details, otherwise you can accept the access key id and the secret access key by clicking enter twice. You'll need to enter us-east-1 for the default region name and json for the Default output format.

cd /var/www/html

We've created a basic Dockerfile for you. This file is called Dockerfile with no extension. Let's look at what is in the file:

cat Dockerfile

This will show you that we are using the latest version of nginx and that we'll copy all of the files from this folder into the /usr/share/nginx/html folder in the container. This will all happen when we create the container.

Start up docker:

sudo systemctl start docker

Add a docker group (this might fail, if it does just continue on to the next step)

sudo groupadd docker

Add your user to the docker group

sudo usermod -aG docker $USER

Log out

exit

Log back in by refreshing the page.

Make sure docker is listed in the groups the user is assigned

groups $USER

Verify your AWS CLI Authentication

aws sts get-caller-identity

You should get something like this in return:

{ "UserId": "AROAIEXAMPLEID", "Account": "123456789012", "Arn": "arn:aws:sts::123456789012:assumed-role/RoleName/RoleSessionName" }

We are going to switch to the root user to run the following commands

sudo su

Make sure we are in the correct folder

cd /var/www/html

Create the container registry

search Search for ECR which will bring up Elastic Container Registry. Open this in a new tab.

The commands should look something like this (don't use the commands below, COPY from the PUSH COMMANDS for your specific repository)

Docker Commands

You should receive a response that shows the docker container was pushed to the ECR.

Exit out of the root user

exit

Go back to the ECR tab and click Close

You should see 1 image with a tag of latest in the list.

Docker container uploaded to ecr

Image URI

You'll need the Image URI for this image later in the lab.

Create an ECS

Create a cluster

Cluster

Occassionally the learner lab will fail to build the cluster.

You can go to cloudformation and rerun the build.

If that fails, create a second cluster and call it VehicleCluster2 and use it instead.

Create a task definition

Under Container-1

Deploy the containers

You will see 1/1 Tasks running

Copy the DNS name for the load balancer and paste it into a new tab.

You will see your app running in a container on your load balancer. If we received enough traffic, the app would auto scale up to 3 containers for us.

Test the web app to make sure you can log in and see service requests.

Take a screenshot of your app running on the container with the load balancer address in the URL and submit your screenshot.

(OPTIONAL) Add SSL to your load balancer

From the Load Balancer page:

You can now go to your load balancer and add https in the front. You'll need to accept the security warning because it is still self-signed.

Once finished, you can destroy the following:

If you leave these running, especially the load balancer, you will use up your allocated funds quickly.

Summary:

Key Concepts:

Reflective Questions: