DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Building an ETL Pipeline With Airflow and ECS
  • Spring Boot With Kubernetes
  • External Task Client Implementation in Camunda With Spring Boot Application
  • Containerization and Helm Templatization Best Practices for Microservices in Kubernetes

Trending

  • Microsoft Azure Synapse Analytics: Scaling Hurdles and Limitations
  • Solid Testing Strategies for Salesforce Releases
  • The Role of Retrieval Augmented Generation (RAG) in Development of AI-Infused Enterprise Applications
  • Ensuring Configuration Consistency Across Global Data Centers
  1. DZone
  2. Coding
  3. Frameworks
  4. Deploying Spring Boot to ECS (Part 2)

Deploying Spring Boot to ECS (Part 2)

Want to learn more about how you can deploy your Spring Boot app with the ECS container? Check out this second installment to learn more!

By 
Joydip Kumar user avatar
Joydip Kumar
·
Updated Oct. 17, 18 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
40.8K Views

Join the DZone community and get the full member experience.

Join For Free

This post is a continuation from our previous post on deploying Spring Boot to ECS.  In our second installment, we will cover how to deploy a Spring Boot application in the ECS container. We will be using a simple task planner application that is available on GitHub.

A Docker file is already available inside this project. Make sure you have Git, Docker, and AWS CLI installed wherever you are running the following commands. Check out this link for a Git clone.

Navigate inside the task-planner folder and run the following command to create an image:

docker build -t {dockerId}/taskplanner-0.1.0 -f Dockerfile .

Run the following command to see the image created:

docker image ls

What Is ECR?

The Amazon Elastic Container Registry (ECR) is a fully-managed Docker container registry that makes it easy for developers to store, manage, and deploy Docker container images. Amazon ECR eliminates the need to operate your own container repositories. ECR is well integrated with ECS, and we will see that shortly.

Create a repository from the ECS console in AWS and give it a name called poc-repo.

1

After the repo is created, we need to push our images to this repo .Run using the following command:

aws ecr get-login – – region us-east-1

Next, you need to copy and paste the output. You will see that you are now logged into the ECR.

You will then need to tag the image with a name and push the image to the ECR repo that we created above.

docker tag poc-repo:latest xxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/poce-repo:latestdocker push xxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/poce-repo:latest

You should be able to see the image in the ECR console.

What Is ECS?

ECS is an AWS-managed service for deploying applications in containers. ECS manages instances using Fargate. Fargate is the latest technology trend in which the user does not need to bother managing the instances. Fargate enables you to focus on building and running applications, not the underlying infrastructure.

Amazon ECS lets you easily build all types of containerized applications, from long-running applications and microservices to batch jobs and machine learning applications. Amazon ECS launches your containers in your own Amazon VPC, allowing you to use your VPC security groups and network ACLs. We will see below how we will create an ECS cluster and deploy the Spring Boot application.

  1. Create a Cluster

1

1

  1. Create a New Task Definition

Select the Fargate option and start creating a new task.

Task Definition Name: fargate-new-A

Task Role: ecsTaskexecutionRole

Network Mode: awsvpc

Requires compatibilities: FARGATE

Task execution role: ecsTaskexecutionRole

Task memory: 4GB

Task CPU: 2vCPU

Add Container

Container name: task-planner

Image: xxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/poce-repo:latest

Memory Limits: Hard limit: 1024, Soft limit: 512(Hard and soft limits correspond to the `memory` and `memoryReservation` parameters, respectively, in task definitions. )

Port Mapping: 9000 (as my container port is 9000)

Volume Mounting: Volume mounting is important else every time all the m2 jars will be downloaded and there will be no persistence across the cluster. Create a storage volume named as dockervolume and map the container path like below:

1

  1. Creating an Application Load Balancer in the Public Subnet

1

Associate to the alb security group, which will be open to HTTP and HTTPS in 80 and 443 ports respectively with the source from anywhere.

Next, create a target group where theloadbalancer will route the request. Make sure to mark the target type to IP.

1

Allow all IP addresses from the VPC subnet that we created.

1

A target group also gets created called “ecs-target," which has no target registered, yet.

  1. Creating an ECS service

1

Task definition: fargate-new-A, which we created above with the latest revision.

Next, you will need to associate the cluster that we created above (ecs-fargate)

Give a service name and the required number of task to be running.

1

Associate the tasks in the private subnet in the VPC section and associate the security group to the private security group created in the previous article.

1

Also, enable the auto assign IP.

1

Associate the Loadbalancer we created and the corresponding target group

1Attach the auto-scaling policy where the required number of a task would be two and it will scale up to four tasks when the number of ALB request per target goes above 50. We will test this in the future section with Apache benchmark.

Create the Service.

1Now, come back to the load balancer target group and you can see below all the availability zone has a healthy status

1.png

The ECS cluster should have two running tasks and one service :

1

Test the loadbalancerDNS name and test the app:

1.png

That’s it – now, you have successfully deployed a Spring Boot "dockerized" application with the ECS Fargate cluster in a private subnet with an app Loadbalancerin the public subnet.

Now, let's see how we can use Apache Benchmark to increase load in this system and scale the application to a maximum of four tasks in the cluster.

Install Apache Benchmark in your machine and run the following command:

If it is Ubuntu, you can install it by running:  apt install apache2-utils.

ab -n 50000 -c 500 http://ecs-fargate-lb-734855749.us-east-1.elb.amazonaws.com/login

It tells to give 50000 requests in total at 500 requests concurrently.

Finally, you can see that two more instances will scale up automatically.

Happy coding!!

Entity component system Spring Framework Spring Boot Docker (software) Machine learning application Task (computing)

Published at DZone with permission of Joydip Kumar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Building an ETL Pipeline With Airflow and ECS
  • Spring Boot With Kubernetes
  • External Task Client Implementation in Camunda With Spring Boot Application
  • Containerization and Helm Templatization Best Practices for Microservices in Kubernetes

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!