Deploy a Spring boot application to AWS ECS

Hemant
4 min readJun 19, 2024

--

In this article we will explore steps to deploy a docker image of springboot application to AWS ECS and access it via ALB.

Architecture Diagram

Amazon Elastic Container Service (ECS) is a highly scalable, high-performance container orchestration service that supports Docker containers and allows you to easily run and scale containerized applications on AWS.

Prerequisites

  1. An AWS account
  2. Basic knowledge of AWS services
  3. An application which already have an docker image. I will use this goal tracker application which is written in spring boot and react.

Configuration Steps

Step 1: Set Up an ECS Cluster

The first step is to set up an ECS cluster. Cluster is Follow below steps to create a cluster.

Search “Elastic Container Service” from search box. ECS will appear as highlighted in below image. Click on it to open ECS window.

Click on Clusters from left pane it will open clusters window and then click on Create Cluster button.

Once you will click on create cluster button it will open window as per below screen.

Provide cluster name, namespace name (optional), infrastructure (Fargate or EC2 Instances). Scroll all the way to bottom and click on “create cluster”.

New cluster will be created in few minutes and will be available in clusters window as per below image.

Step 2: Create Task Definition

From left pane select “Task Definition” (highlighted in below image).

Add then click on “Create new task definition”

Add Task Definition family (any relevant name as per your application) :

Add Task Size and Container details

Name : any name for your container

Image URI : AWS ECR or docker image URI (For this Article I am using docker image at this location.)

Click on create task and new task will be created as shown below -

Step 3: Create Service

This is actual step where application containers will be started.

Move back to cluster window and click on cluster which was created in step1.

Click on “Create” to create new Service and enter details.

Select “Launch Type”

Application type : Service

Family: Select the task definition you created in Step 2.

Scroll down to networking —

Select VPC, subnets

security group: choose create new security group if you don’t have any and configure inbound for type HTTP.

Configure Application Load Balancer and Create.

Service will be created after few minutes with a task(container) as per task definition.

Now click on Service name and it will open service details

Now click on View Load Balancer

Copy DNS Name and put it in a browser to access application.

Conclusion

In this article we deployed an application based on springboot to AWS ECS. Deploying an application to Amazon ECS involves several steps, but once you understand the process, it becomes straightforward. With ECS, you can easily scale your applications and use other AWS services to enhance your applications

--

--

Hemant

Lead Software Engineer @JPMorgan & Chase. Writes about Java, AWS and System Design