EventBridge allows you to build event-driven architectures, which are loosely coupled and distributed.
An AWS Event Bus is a design pattern that allows PubSub-style communication between components while the components remain loosely coupled. A component can send a message to an AWS Event Bus without knowing where the message is sent to and then uses rules to evaluate them, applies any configured input transformation, and routes them to the appropriate target.
An Event rule matches incoming events and routes them to targets for processing. A single rule can route to multiple targets, all of which are processed in parallel. Rules are based either on an event pattern or a schedule. An event pattern defines the event structure and the fields that a rule matches. Rules that are based on a schedule perform an action at regular intervals.
Architecture for sample project to show the AWS Event bridge
AWS Event bridge and lambda deployment to AWS through serverless deploy
The Serverless Framework, as an open-source tool, is a pivotal component within the realm of Infrastructure as Code (IAC). It empowers developers and engineers to define, manage, and deploy serverless infrastructure in a code-centric manner.
The Serverless Framework's integration with IAC principles fundamentally transforms the way serverless infrastructure is provisioned, managed, and deployed by providing a structured, code-based approach that ensures consistency, reliability, and scalability across the application's lifecycle.
What we have done through serverless framework?
This configuration file, written in YAML for the Serverless Framework, orchestrates the deployment of a serverless application on Amazon Web Services (AWS). It defines AWS-specific settings like runtime (Python 3.8), memory allocation, and the S3 bucket for deployment. It outlines a Lambda function called lambda_handler with a scheduled EventBridge trigger, specifying its handler, execution role, timeout, attached layers, and environment variables like API endpoints, database credentials, and connection details, all fetched from environment variables. This configuration streamlines the setup and deployment process, ensuring the seamless execution of the serverless application while abstracting infrastructure management complexities. We deploy the above architecture through serverless framework.
It will make an Event Rule for a default event bus which will trigger the Event rule for a target every 6 hours and also deploy the lambda function for further processing.
Event Rule - Cron Schedule
Event Rule Target - lambda function
You can monitor your event rule in monitoring like how many invocations are there or how may invocations are failed to trigger the lambda function
AWS Pricing for AWS Event Bridge and lambda function
AWS bills for every 1 million events published on the event bus in which payload should be not exceed 64 KB if size of payload increases it will consider it another event with that payload means each 64 KB chunk of a payload is billed as one event (for example, an event with a 256 KB payload is billed as 4 requests).
For scheduled Invocation it will cost you $1.00/million scheduled invocations per month, after 14 million free invocations per month.
If your application publishes 3 million events per month to the event bus for each payload of 64KB in size then it will cost you $3.00 bill monthly.
If your monthly scheduled invocation is 20 million then it will cost you only $6.00 because 14 million free invocations per month.
Monthly invocations: (20M – 14M Free Tier) * $1.00/M = $6.00