How to setup Spring Boot + Docker + Load balancer with AWS Fargate ( AWS Console )

Kobe
4 min readJul 18, 2020

--

How to setup Spring Boot + Docker + Load balancer with AWS Fargate

AWS Fargate is a serverless compute engine for containers that work with both Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS). Fargate makes it easy for you to focus on building your applications. Fargate removes the need to provision and manage servers, lets you specify and pay for resources per application, and improves security through application isolation by design.

Fargate allocates the right amount of computing, eliminating the need to choose instances and scale cluster capacity. You only pay for the resources required to run your containers, so there is no over-provisioning and paying for additional servers. Fargate runs each task or pod in its own kernel providing the tasks and pods their own isolated compute environment. This enables your application to have workload isolation and improved security by design. This is why customers such as Vanguard, Accenture, Foursquare, and Ancestry have chosen to run their mission-critical applications on Fargate.

So we can easily deploy service with AWS Fargate ( Load Balancer / Scale-Up/Down our resource )

  1. Setup Spring Boot with Rest Sample

Github: https://github.com/kobee-tech-stack/client-server-architecture

2. Setup a basic Dockerfile sample in the root folder.

Build and check our service.

docker build -t web-service .

docker run -d -p 8080:8080 -t web-service

3. Go to the AWS and add a new repository

Aws URL: xxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/

4. Upload the image to this repository

Open AWS CLI and execute the command below

aws ecr get-login-password — region ap-southeast-1

Result : eyJwYXlsb2FkIjo

docker login -u AWS -p eyJwYXlsb2FkIjo ${your_aws_url}

docker image tag web-service:latest ${your_aws_url}/web-service

Recheck the docker image `docker image ls`

5. Push your image to the AWS ECR repository.

docker push xxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/web-service

Recheck your ECR Repository

6. Add new task deploy our image use ECS/Fargate

We can now define your deployment on AWS ECS/Fargate. Let’s create your task by going to “create a new task definition” option on AWS ECS and then select the type FARGATE:

We will use image upload to ECR above and create a new container

7. Setup a Load Balancer for our service.

Setup Cluster for our service

Our Task as below:

Task definition

Create and Run Task

Check our service

Now we are the successful first step — Deploy Web Service and Load Balancer for Web-Service instance

We try to call the API to our service.

--

--

Kobe
Kobe

Written by Kobe

I’m working at KMS-Technology company. I love code (▀̿Ĺ̯▀̿ ̿) — Full Stack Software Engineer

Responses (1)