top of page

How to Deploy SpringBoot Application on to (Serverless)AWS Fargate by pulling images from AWS ECR

  • Writer: Subhasish Sahu
    Subhasish Sahu
  • May 17, 2020
  • 2 min read

Updated: May 30, 2020


ree

Pre - Requisite :

  1. Java 1.8 ( or above)

  2. Intellij Idea IDE

  3. Docker

  4. AWS Account

  5. Docker HUB Account


Create a SpringBoot Application in Intellij IDE



ree

Integrate Docker into your IDE




ree


ree

Connect to docker service


ree

ree

ree

From Terminal, run : mvn clean install


ree

Then "Build Image on Docker"


ree

ree

or


You can Build image as below :



ree

Build successful :

ree

Push Image

ree

ree

ree

You can see the same image got uploaded to Docker Hub



ree

Now the files are available in Docker Terminal also


Before Pushing


ree

After Pushing


ree

Now we need to push those images to AWS ECR, before that we need to create repo in ECR



ree

ree

ree


ree

ree

Now using Docker ToolBox, we will push the image to ECR


First Step is to check if aws cli is available or not :

Command : aws --version


ree

Get the IAM Access Key and Create New Access Key



ree

Configure it with command : aws configure


ree

Connect Docker with AWS ECR


Run the command : aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <aws account id>.dkr.ecr.us-east-1.amazonaws.com


ree

Create a Tag for the image newly build


Command : docker tag springboot_awsfargate:latest <aws account id>.dkr.ecr.us-east-1.amazonaws.com/springboot_awsfargate:latest


ree

Push image to AWS ECR


ree

Troubleshooting :


If you get below error


ree

run docker-machine stop default and docker-machine start default


ree




Image pushed to the repository and then click on Permissions to set the permission


ree


ree


ree


Set Permission


ree

ree

The Permission will look something like this


ree

Before creating cluster and running a task, lets create a new Security Group and VPC endpoints


To Create Security Group :


ree

ree

ree

ree

ECR requires two interface endpoints:

  • com.amazonaws.region.ecr.api

  • com.amazonaws.region.ecr.dkr


ree

ree


ree

ree

ree

ree

Endpoint successfully create and running

ree

Goto Account Settings


ree

ree

ree


Create a Cluster


GoTo ECS


ree

ree

ree

ree

ree

ree

ree

ree


View Cluster



ree

Create Task:


ree

ree

ree

ree

ree


ree

Go Back to ECR and copy the URI


ree

Paste it at the image* textbox


ree

ree

ree

ree

ree

Give Permission to ecsTaskExecutionRole to read image from ECR


ree



After the creation of task , we need to run the task


ree

ree

ree

ree

ree

Create a Service


ree

ree

ree


ree

ree



When you click on the Task,in the next page you will see a Network section ,take the Public IP and hit it in a browser


ree

It means the code has been successfully deployed.Now put the rest of the resource path and you can the proper response from the springboot application



ree




Comments


bottom of page