Skip to content

Latest commit

 

History

History
98 lines (73 loc) · 4.42 KB

README.md

File metadata and controls

98 lines (73 loc) · 4.42 KB

Deploying Spring Boot application on Amazon ECS/AWS Fargate with Application Load Balancer

This sample project deploys a Java 21 Spring Boot application on Amazon ECS using AWS Fargate with Application Load Balancer to route traffic between two ECS Tasks.

Requirements

Deployment Instructions

  1. From the command line, execute the below command to build the project.

       mvn clean package
  2. (Optional) Run the application on local box using the below command:

       mvn spring-boot:run
  3. Get the right settings in place:

     aws_account=YOUR AWS ACCOUNT
  4. Please ensure that docker is up and running before executing this step. From the command line, run the below command

       bash build.sh

    if you get this error (can happen w/ Apple M1-M3):

     ERROR: Multi-platform build is not supported for the docker driver.
     Switch to a different driver, or turn on the containerd image store, and try again.
     Learn more at https://docs.docker.com/go/build-multi-platform/
    

    please run first:

     docker buildx create --name multiarch --driver docker-container --use
  5. Run the below command to deploy the AWS resources for the pattern as specified in the template.yml file:

       sam deploy --guided

    or just...

       ./deploy.sh

    After the first run SAM will save your preferences in a .toml file by default with the name samconfig.toml

  6. During the prompts:

    • Enter a stack name
    • Enter the same as AWS Region that you provided while building the image.
    • ImageURI Enter the image URI obtained from the previous output (from build.sh).
    • Allow SAM CLI to create IAM roles with the required permissions.
    • Keep default values to the rest of the parameters.

    If you have run sam deploy --guided mode once and saved arguments to a configuration file (samconfig.toml), you can use sam deploy in future to use these defaults.

  7. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for next step as well as testing. (More about SAM config file here)

How it works

This sample project deploys a Java 21 Spring Boot application on Amazon ECS Fargate with Application Load Balancer to route traffic between two ECS Tasks. The application exposed REST APIs which can be accessed over HTTP.

Overview Architecture: Overview

ECS Architecture zoom in diagram below:

End to End Architecture

Here's a breakdown of the steps:

  1. Amazon Elastic Container Registry: The repository of the container image of the Spring Boot Application.

  2. Application Load Balancer: Receives the HTTP request which routes the traffic to one of the Amazon ECS Tasks.

  3. Amazon Elastic Container Service: Amazon ECS Cluster is configured with one service having 2 Tasks. The 2 Tasks runs the Spring Boot application as container. The container image is retrieved from the Amazon Elastic Container Registry.