5.4 Backend on ECS, ECR & RDS
Backend Service on ECS, ECR & RDS
In this section, you will focus on packaging and deploying the Spring Boot backend
from the backend/backend folder to Amazon ECR and Amazon ECS (Fargate),
then connecting it to an Amazon RDS database.
Backend Service Overview
The backend is a Spring Boot application that provides REST APIs for:
- Managing production orders and work orders.
- Defining production lines and capacities.
- Tracking production progress and delays.
- Exposing metrics for dashboards and AI analysis endpoints.
- Sending OTP emails and notifications via SES.
The project uses:
- Java 17
- Spring Boot
- Spring Security (role-based access)
- JPA/Hibernate with Flyway database migrations
ECS architecture diagrams


These diagrams summarize how the backend service runs on Fargate tasks inside private subnets, connects to RDS, and is fronted by an ALB.
Containerization & Amazon ECR
- Create an ECR repository (for example
ims-production) in the target AWS account/region. - Review the
Dockerfile under backend/backend/. - Build the JAR using Maven (
./mvnw -DskipTests clean package). - Log in to ECR using the AWS CLI (or let CodeBuild do it with
aws ecr get-login-password). - Build the Docker image and tag it with your ECR repository URI, for example:
638389534958.dkr.ecr.ap-southeast-1.amazonaws.com/ims-production:<git-sha>- and optionally
:latest.
- Push the image to Amazon ECR.
In the workshop, this process is automated using AWS CodeBuild with the
buildspec.yml file at the repository root:
- CodeBuild logs in to ECR.
- Builds the Spring Boot JAR and Docker image.
- Tags the image with the short Git commit SHA and
latest. - Pushes both tags to the ECR repository.
Deploying to ECS (Fargate)

- Create an ECS Cluster (Fargate type).
- Define a Task Definition:
- Container image pulled from the ECR repository above.
- CPU/Memory limits (e.g., 0.5 vCPU / 1–2 GB RAM).
- Container port (e.g., 8080).
- Environment variables (database URL, username, password, etc.) – ideally from Secrets Manager.
- Create an Application Load Balancer (ALB) and target group for the ECS service.
- Configure health checks (e.g.,
/actuator/health if enabled). - Create an ECS Service using the task definition and attach it to the ALB target group.
Connecting to Amazon RDS

- Provision a PostgreSQL database in Amazon RDS inside your VPC private subnets.
- Configure Security Groups so that only ECS tasks (and optionally bastion/administration hosts) can connect to RDS.
- Store database credentials in AWS Secrets Manager.
- Map secrets/environment variables into the ECS task definition:
SPRING_DATASOURCE_URLSPRING_DATASOURCE_USERNAMESPRING_DATASOURCE_PASSWORD
- Verify that Flyway migrations under
src/main/resources/db/migration/ run successfully when the app starts.
Traffic Flow & Logs
At runtime, requests follow this path:
Client → Route 53 → ALB → ECS Service (Spring Boot) → RDS
Logs from the container are sent to CloudWatch Logs (e.g., log group /ecs/ims-backend).
You can use these logs to troubleshoot errors and verify that the service is healthy after each deployment.