Putting all things together using AWS Task Definition
Tags: aws, ecs
Published: 2020-02-07 01:17:31

---
title: Putting all things together using AWS Task Definition
published: true
date: 2019-12-27 13:56:51 UTC
tags: AWS,ECS
canonical_url: 
---

> **This article is the continuation of [WordPress with Docker, AWS (ECS, Code Pipeline, Load Balancer, RDS, EFS) Complete Series](https://salzam.com/wordpress-docker-aws-ecs-codepipeline-load-balancer-rds-efs/). For better understating, please start from the beginning of the series.**

In the previous article, We have created the ECS Task Definition which has our Docker Image container along with environment variables and we also have mounted EFS volumes for plugins and cache.

In this article, our website will go live with Load Balancer and Autoscalling groups (having multiple WordPress instances on demand). This means that AWS can increase the number of WordPress instances on demand and it can scale it down too.

We will do the following in this article:

- Create ECS Cluster
- Create Service for WordPress Task Definition
- Configure Autoscalling

## Create ECS Cluster

Go to ECS from your AWS console service tab and select Clusters, Click on Create Cluster

![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28222803/001-8-1024x306.png)

### Step 1: Select Cluster template

Select **EC2 Linux + Networking**

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28222919/002-7-1024x833.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28222919/002-7.png)

### Step 2: Configure cluster

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28223041/003-8-1024x1024.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28223041/003-8.png)

I have used m5a.large instance size. You can choose whatever instance size is suitable for you.

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28223630/004-8-965x1024.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28223630/004-8.png)

Please select the instance Security Group we created earlier. This cluster will create an EC2 instance for us. We will place our WordPress Docker image on this instance.

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28224001/005-6-1024x766.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28224001/005-6.png)

Hit Create button and it will create the Cluster for you.

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28224533/007-2-1024x741.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28224533/007-2.png)

You should be able to see your cluster in the list.

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28224321/006-7-1024x495.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28224321/006-7.png)

### Add Service to your Cluster

Click on the cluster your have created and click on **Create**

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28224746/008-3-1024x849.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28224746/008-3.png)

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28230433/009-3-1024x684.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28230433/009-3.png)

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28230453/010-3-1024x812.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28230453/010-3.png)

### Adding Load Balancer

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28230540/011-4-1024x929.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28230540/011-4.png)

Select your wordpress Load Balancer created earlier.

![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28230604/012-2-1024x164.png)

Click on Add to load balancer button

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28230636/013-2-1024x685.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28230636/013-2.png)

Select the target group created for the Load Balancer.

![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28230802/014-2-1024x434.png)

Un-select the Enable service discovery integration

### Configure Autoscaling Group

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28230845/015-2-1024x313.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28230845/015-2.png)

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28231043/016-1-1024x381.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28231043/016-1.png)

You can change these variables as per your requirements. In our case, it will create two EC2 instances for us and place our WordPress website on each of them.

### Creating Scale UP and Scale Down policies.

Something has to trigger an alarm so AWS EC2 can add or reduce number of instances for us. I am using CPU Utilization in our example. There are many more options.

To keep it simple, we are saying that if the CPU Utilization is above 60% for 5 minutes, add another instance. If the CPU Utilization is below 50% for 5 minutes, reduce instances to just 1.

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28231201/017-1-1024x916.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28231201/017-1.png)

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28231644/018-2-1024x867.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28231644/018-2.png)

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28231537/019-1-1024x785.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28231537/019-1.png)

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28231620/020-1-1024x859.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28231620/020-1.png)

### Service and Task Tabs

Now if you go back to your Cluster, You should be able to see that the new service and task has been added.

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28232054/021-1-1024x364.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28232054/021-1.png)

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28232107/022-2-1024x402.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28232107/022-2.png)

## Sucess !!!!

if everything goes well which I hope it will, Copy and past your Load Balancer DNS URL in the browser and you should see your WordPress website setup screen.

![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28233035/WordPress-Setup-Screen.png)

If, for some reason, things don’t go well and you don’t see this page. Please check how to Trouble shoot the problem below.

## Troubleshooting 

If something has gone wrong, your task will fail again and again. in order to find out what is wrong, click on the task and it will take you to a screen like this:

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28232451/023-1024x565.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28232451/023.png)

If something went wrong inside your container, you can investigate it inside the Logs tab.

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28232615/024-1024x442.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/28232615/024.png)

Otherwise expand the web container under the Details tab of the task and you will see Exit code and reason why the task has failed.