How mahesh100/micronaut-with-aws-lambda works
Project Type and Purpose
• This is a serverless microservice/demo application built on Micronaut (Java), intended to run as AWS Lambda functions.
• It demonstrates handling HTTP requests (GreetingHandler, RedisController), processing DynamoDB Streams events (DynamoDBStreamhandler), and encapsulates business logic in a service class (MyService).
File‐Structure Analysis
• src/main/java/com/example/demo/Application.java — Micronaut entry point, bootstraps the Lambda environment or embedded HTTP server.
• Handlers/controllers:
• GreetingHandler.java — HTTP Lambda endpoint (e.g., GET /greet).
• RedisController.java — HTTP endpoint interacting with Redis (ElastiCache).
• DynamoDBStreamhandler.java — AWS Lambda event handler for DynamoDB Streams.
• MyService.java — Shared business logic, invoked by controllers/handlers.
• application.yml — Configuration for AWS credentials, DynamoDB table names, Redis URL, logging levels.
• build.gradle + Shadow plugin — Bundles the application into a fat JAR for deployment.
Key Components
a. API Gateway (or HTTP Trigger)
• Triggers GreetingHandler and RedisController Lambdas on HTTP calls.
b. AWS Lambda Functions
• GreetingHandler
• RedisController
• DynamoDBStreamhandler (triggered by DynamoDB Streams).
c. Business Layer
• MyService (shared component invoked by all handlers).
d. External Systems
• DynamoDB (source table + Streams)
• Redis (ElastiCache cluster or Redis instance)
• Any outbound HTTP services called by MyService (if applicable).
e. Build & Deployment
• Gradle/Shadow: builds a single executable JAR.
• CI/CD (optional): pipeline pushing JAR to AWS Lambda.
Relationships & Data Flows
• HTTP Request → API Gateway → Lambda (GreetingHandler or RedisController) → MyService → DynamoDB or Redis → Response back to caller.
• DynamoDB Table Update → DynamoDB Streams → DynamoDBStreamhandler → MyService → downstream processing or external HTTP call.
• MyService may also call external REST APIs using Micronaut HTTP client (if implemented).
Architectural Patterns & Principles
• Serverless functions for event-driven and HTTP workloads.
• Single‐jar microservice via Shadow plugin.
• Dependency injection via Micronaut’s IoC container.
• Configuration externalized in application.yml.
• Separation of concerns:
• Handlers/controllers handle transport (HTTP, Streams)
• MyService contains domain logic
• Clear labels: component names, ports/endpoints (e.g., /greet, /redis).