Skip to content

Event-Driven Architecture using Lambda and EventBridge for a Spring Boot Native micro-service deployed in Fargate ECS.

License

Notifications You must be signed in to change notification settings

aosolorzano/city-tasks-spring-boot-aws-eda

Repository files navigation

EDA using Lambda and EventBridge with SAM-CLI, and a Native Spring Boot MS deployed on Fargate ECS as Event Source.

  • Author: Andres Solorzano.
  • Level: Advanced.
  • Technologies: Java 17, Spring Boot 3, Spring Native, Spring WebFlux, Spring OAuth2, Quartz, Flyway, Lombok, Testcontainers, LocalStack, AWS Copilot CLI, SAM-CLI, Amazon Cognito, Aurora PostgreSQL, DynamoDB, Application Load Balancer, EventBridge, Lambda, and Docker.

You can read the following articles from my Medium.com account to get more project details:

  1. Multi-Account environment on AWS using IAM Identity Center.
  2. OAuth2 in Spring Boot Native microservice.
  3. Deploying Spring Boot Native microservice using Cross-Account deployment.
  4. End-to-End Encryption using TLS ECDSA certificate and ACM with Copilot CLI.
  5. EDA using Amazon EventBridge, Lambda, and SAM-CLI, with Fargate ECS as Event Source.

Description.

This project uses Spring Boot to manage Quartz Jobs with the help of Spring Webflux and Spring Native. The Quartz library is configured for a clustered environment, so it needs Postgres to store and manage Jobs executions. When a Quartz Job is executed, the calling method retrieves the Device item associated with the Tasks and updates its state in DynamoDB. To perform all these activities, the users must have a valid access token (JWT) to access the endpoints. All test cases use TDD from the beginning of the development, and only Integration Tests are executed with the support of Testcontainers and LocalStack to try to cover real-world scenarios. This project also uses Docker Compose to deploy a local cluster with the required services for local testing.

Prerequisites.

  • Git.
  • AWS CLI (version 2.11.+).
  • AWS Copilot CLI (version 1.27.+).
  • AWS SAM CLI (version 1.90.+).
  • OpenJDK (version 17.0.+). You can use SDKMAN.
  • Apache Maven (version 3.9.+) You can use SDKMAN.
  • Spring Boot (version 3.1.1)
  • Docker and Docker Compose.

Project Structure.

The project is divided into the following directories:

  • src: Contains source code of the required project services.
  • copilot: Contains the Copilot configuration files.
  • template.yaml: Contains the SAM configuration.
  • docker-compose.yml: Contains the Docker Compose file to deploy the local cluster.
  • pom.xml: Contains the project's dependencies.
  • utils: Contains the scripts to deploy the application locally or in AWS.

Internal Documentation.

The internal project documentation is divided into the following directories:

Deployment Options.

You need to execute the following command from the project's root directory:

./run-scripts.sh

The script will ask you for the required AWS profiles to deploy the application locally or in AWS:

Then, the script shows a main menu with the following options:

Please go to 'Helper menu' to create the dependent resources before deploying the application:

Getting Device items from DynamoDB on LocalStack.

Execute the following command:

aws dynamodb scan                           \
  --table-name Devices                      \
  --endpoint-url http://localhost:4566