Windows Service Alternative In AWS Cloud

Introduction

Project architect as .Net Core Web API for backend and React Js for frontend. Web API in turn interacting with the database. The hosting provider used is AWS Cloud. Web API & React Js hosted using the AWS Lambda web application service and AWS RDS service for SQL database.

Scenario to develop schedule service

We were having a requirement of sending the report as a PDF in an email attachment on a scheduled basis. In a previous system before migrating it to AWS Cloud, it was handled using the .Net Windows service with complete logic inside the service only.

Implemented approach

AWS Services utilized,

  1. AWS Lambda Function – C#.Net
  2. Cloud Watch Events – Trigger

How it is implemented

Moved the Business logic to Web API from the console windows service.

Logic to generate the report is moved to Web API route, each report has its own route which gives the desired result.

AWS Lambda function becomes a middle

AWS Lambda function is now responsible for two tasks.

  • Get the report from Web API based on the input parameter from the trigger
  • Send email to the respective subscription list

AWS Lambda function gets only one input as report name which must be generated and send it across. Lambda function contains switch statement and respective function for each report to get from Web API and one generic function which sends an email.

Cloud watch events is a trigger point to AWS Lambda function

Finally, Cloud watch events are the main stuff that triggers the AWS Lambda function based on the configured schedule. Here we used the Cron expression to schedule a job at a specific time.

Conclusion

  • Cloud watch events are grate AWS service by which we can do a scheduling job with multiple targets services (like AWS lambda function,...)
  • In this approach, the AWS lambda function is a mediator which will get trigger from the cloud watch events.
  • Web API is processing the request and sending back the report data in bytes form to the Lambda function, which will intern send the email to the subscribed users.

Below are the reference diagrams for the complete implementation.


Similar Articles