Deploying Spring Boot to AWS ECS with GitHub Actions

Published on 4/11/2025 â€ĸ Categories: github actions, spring boot, ecs, aws, devops

Deploying Spring Boot to AWS ECS with GitHub Actions

Architecture Overview

Spring Boot AWS ECSSpring Boot AWS ECS

Steps to Deploy

1. Dockerize the App

dockerfile
FROM openjdk:17
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]

2. Push to ECR (Elastic Container Registry)

bash
aws ecr get-login-password | docker login ...
docker build -t my-app .
docker tag my-app:latest <your-ecr-url>
docker push <your-ecr-url>

3. Define ECS Task

Use Fargate or EC2-based task with load balancer.

4. Automate with GitHub Actions

yaml
name: Deploy to ECS
on:
push:
branches: [ main ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.ECR_URI }}:latest

Done ✅

You now have a cloud-deployed Spring Boot app, auto-deployed on every push to main.