DEV Community

Seun for AWS Community Builders

Posted on

9

Deploy NGINX Application on AWS ECS

AWS ECS on Fargate provides a seamless platform to deploy containerized applications with ease and efficiency. In this post, we'll walk through the process of deploying an NGINX application on AWS ECS using Fargate.

What is AWS ECS and Fargate?

AWS ECS (Elastic Container Service) is a highly scalable, high-performance container management service that supports Docker containers and allows you to run applications on a managed cluster of servers. Fargate, on the other hand, is a serverless compute engine for containers that work with ECS, removing the need to manage servers or clusters. Additionally, you can deploy ECS on an EC2 instance, however you would need to manually manage the servers or cluster.

Why are we deploying NGINX?
NGINX is a popular open-source web server known for its high performance, stability, and rich feature set. It's often used for load balancing, reverse proxying, and as a web server.

Prerequisites

  • An AWS account with permission to use ECS
  • AWS CLI installed
  • Basic understanding of Docker, NGINX, and AWS AWS ECS

Image description

Step 1: Create an ECS Cluster:

A cluster is a logical grouping of your ECS resources, you would need a cluster to deploy a container. in this post, we will be using the default vpc for the cluster

To create a cluster Through AWS CLI
aws ecs create-cluster --cluster-name nginx-application

To Create a cluster via AWS Console

Log in to your AWS Management Console, Navigate to the ECS service, and select “Clusters”.
Create a new cluster

Image description

Step 2: Register task definition:

A Task Definition in AWS ECS is a blueprint for running containers, specifying details like container images, CPU and memory allocation, environment variables, and networking settings.

To Create a task definition via AWS Console

  • Go to the Task Definitions page on the ECS console.
  • Create a new task definition and select “Fargate” as the launch type.
  • Configure the task with the required settings like task size (CPU and memory).
  • Add a container definition for your NGINX server. Here, you'll specify the image for NGINX (you can use the official NGINX image from Docker Hub).

Image description

Image description

Step 3: Configure and Launch the Service

A service in AWS ECS creates a task by instantiating a task definition, where a task represents a running container. The service is responsible for managing and maintaining the container's desired state and scalability.

To Create a Service via AWS Console

  • Return to your ECS cluster and select “Services”.
  • Create a new service and select the task definition you created.
  • Configure the service - set the number of desired tasks, and network and security settings.
  • Launch the service. AWS Fargate will start and manage the containers for you.

Image description

Image description

Image description

Image description

Image description

Step 4: Access the NGINX Application

  • Find the public IP of your running task (available in the task details in the ECS console).
  • Access NGINX by entering the public IP in your web browser. You should see the NGINX welcome page.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay