Skip to content

Latest commit

 

History

History
 
 

04-DeployFargate

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Deploying an application with AWS Fargate

aws fargate logo

Quick jump:

1. Tutorial overview

This tutorial will walk you through a web application deployment using AWS Fargate. This is the same application that we used for the ECS Cluster with EC2. This means that we won't need to create and build another Docker image. We will also use the same image and ECR respoitory.

After concluding this tutorial, you will have an application running in AWS Fargate.

2. Creating the Cluster

We will create a new cluster just for the Fargate tasks, however, a single ECS cluster supports both EC2 and Fargate tasks.

Let's create a new cluster to deploy our containers. In your AWS account Management Console, navigate to the ECS Console.

Click in Create cluster and in the following screen select the Networking only cluster template. Click in Next step:

cluster template

For the Cluster name use containers-workshop-fargate-cluster and click in Create:

cluster configuration

3. Creating the Task Definition

To create a Task Definition, at the left side of the ECS Console menu, click in Task Definitions. Click in Create new Task Definition. Select FARGATE as the Launch type compatibility and click in Next steps:

type compatibility

In the Task Definition Name type containers-workshop-fargate-task-def. For Task Role choose None.

task configuration

Under Task execution role choose ecsTaskEcecutionRole, if that role is not listed, choose Create new role.

Under Task memory (GB) select 0.5GB. For Task CPU (vCPU) select 0.25 vCPU.

Click in Add container:

task size

For Container name type the name containers-workshop-app. And add the same ECR URL using in the previous modules of this workshop in the Image field. Under Port mappings type 80 and leave tcp as the protocol. Click in Add:

task container

Click in Create.

4. Deploying the application

Now that we have our task definition, let's create a task itself to see our container running with no servers to manage.

Go back to the ECS Console and select the cluster that you created for this tutorial. Click on the Task tab and then click in Run new task

run task

In the Run Task screen, for Launch type select FARGATE. For Task Definition select the Task Definition that you created in the previous step. For Cluster select the cluster containers-workshop-fargate-cluster:

run task configuration

Under Cluster VPC, select the VPC containers-workshop-vpc and the both containers-workshop-public-subnets as your Subnets. Select ENABLED in the Auto-assign public IP option. After selecting everything, click in Run Task:

run task configuration VPC

5. Accessing the application

After running your task, go back to the ECS Console. Select the cluster and click on the Tasks tab. You'll see a task in the PENDING status.

pending task

A Fargate task can take around 30 seconds to a minute before changing its status to RUNNING. That's because, for each new task, an ENI is created in your VPC with an IP from the subnet you chose, and then, it's attached to the Fargate task.

running task

To test your app, you need to get the public IP associated with your task. In order to do so, in you Fargate Cluster, click in Tasks. You should see your task with the status running:

Fargate tasks screen

Click in your Task ID (the first field of the screen) and you will be redirected to the Task Details page. You will find the public IP under the Network section:

Fargate public ip

Copy and paste the IP address in your browser. The final URL should look like this: http://34.229.126.241

final Fargate

6. Conclusion

You have successfully deployed an application with AWS Fargate and Docker containers. This is how you deploy a serverless container app on AWS.

Now, take a moment to spend some time navigating in the AWS Fargate. Here is a list of a few thing that you can try:

  • Finding the container logs;
  • Deploying a new version of this application;
  • Adding an Application Load-Balancer to your task definition;
  • Deploying other containers using AWS Fargate (you can use the container you created on the previous tutorial).

back to menu         continue workshop