Skip to content

A starter project for Spring Boot microservices to deploy on ECS

License

Notifications You must be signed in to change notification settings

3pillarlabs/spring-boot-ecs-starter

Repository files navigation

spring-boot-ecs-starter

A starter project to deploy Spring Boot microservices in Amazon ECS Cluster

This starter kit includes the following artifacts:

springbootservice1: This is a Java Spring Boot sample microservice

springbootservice2: This is another sample Java Spring Boot microservice

ECS-CF-springboot-ALB-single-service: Use this YML template file to launch CloadFormation stack for a single service (springbootservice1)

ECS-CF-springboot-ALB-multiple-services: This YML template launches CloadFormation stack for a multiple services (springbootservice1 & springbootservice2)

ResourcesToBeCreated-single-service: This diagram shows the resources that will be created by ECS-CF-springboot-ALB-single-service CloudFormation stack

ResourcesToBeCreated-multiple-services: This diagram shows the resources that will be created by ECS-CF-springboot-ALB-multiple-services CloudFormation stack

Steps to build the microservice and launch the ECS Cluster

1. Build your applciation jar: "gradle clean build" from root directory of the applications springbootservice1 & springbootservice2

2. Build springbootservice1 Docker image : "docker build -t springbootservice1 ." from root directory

2. Build springbootservice2 Docker image : "docker build -t springbootservice2 ." from root directory

3. Host the Docker image: Host this docker image to Docker hub or ECR

4. Launch ECS Cluster from CloudFormation: Use ECS-CF-springboot-ALB-single-service to launch the cluster with springbootservice1 only and if you want to launch both the services then use ECS-CF-springboot-ALB-multiple-services You can either save the YML files to an s3 bucket and refer during launching the CF stack or copy its content and paste in designer.

These template use image(s) hosted on AWS ECR, you can use your own image hosted on ECR or Docker hub. To do so, search for "image" in the template and replace it with your image.

When you will launch the CloudFormation stack, provide some values when asked like Cluster name, no of minum & maximum number of instances in ECS Cluster, VPC, Subnets....

5. Test the service(s): Wait untill Stack status is shown as Complete

Check in Load Balancers list under EC2 Service, you will see a newly created ALB with name ECSALB. Copy the NDS (A Record) of the ALB and test the service(s) as mentioned below and replace {ECSALB} with ALB DNS:

{ECSALB}/service1 You will see message "Welcome to the 3Pilar Global springboot service sample"

{ECSALB}/service1/hello You will see message "Hello, how are you today..."

{ECSALB}/service2 You will see message "Welcome to the 3Pilar Global springboot service2 sample"

{ECSALB}/service2/hello You will see message "Hello from service2..."

When you call your multiple services using single ALB as mentioned in above, it is called path based routing when the ALB determines that which Target Group wikk service a request like /service1 or /service2

Please check other resources created by CloudFormation.

6. Delete the stack Once done, go and check the box again CloudFormation Stack and from Actions choose Delete Stack, this will delete all the resources created by the Stack.

About

A starter project for Spring Boot microservices to deploy on ECS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages