• Subhasish Sahu

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

Updated: May 30, 2020



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




Integrate Docker into your IDE


( For Installing Docker ToolBox ,please refer my previous blog : https://www.thesubhasishsahu.com/post/how-to-deploy-springboot-application-in-aws-ec2-instance-using-docker )





Connect to docker service




From Terminal, run : mvn clean install


Then "Build Image on Docker"



or


You can Build image as below :




Build successful :


Push Image




You can see the same image got uploaded to Docker Hub



Now the files are available in Docker Terminal also


Before Pushing


After Pushing



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








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



Get the IAM Access Key and Create New Access Key




Configure it with command : aws configure


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


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


Push image to AWS ECR

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


Troubleshooting :


If you get below error


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






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








Set Permission



The Permission will look something like this



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


To Create Security Group :






ECR requires two interface endpoints:

  • com.amazonaws.region.ecr.api

  • com.amazonaws.region.ecr.dkr








Endpoint successfully create and running


Goto Account Settings






Create a Cluster


GoTo ECS











View Cluster




Create Task:









Go Back to ECR and copy the URI


Paste it at the image* textbox







Give Permission to ecsTaskExecutionRole to read image from ECR





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






Create a Service










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


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







100 views0 comments

Recent Posts

See All