Skip to content

russomi-labs/amazon-eventbridge-producer-consumer-example

 
 

Repository files navigation

Amazon EventBridge - Producer/Consumer example

This example application creates two AWS Lambda functions - a producer and a consumer. The SAM template deploys these functions, together with an EventBridge rule that determines which events are routed to the consumer.

The example shows how an ATM application at a bank could generate events, and the rule only passes 'approved' transactions to an event consuming application.

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

For more blogs and examples, visit Serverless Land.

.
├── README.MD                   <-- This instructions file
├── atmProducer                 <-- Source code for a lambda function
│   └── handler.js              <-- Main Lambda handler
│   └── events.js               <-- Events
│   └── localTest.js            <-- Wrapper for local testing
│   └── package.json            <-- NodeJS dependencies and scripts
├── atmConsumer                 <-- Source code for a lambda function
│   └── handler.js              <-- Main Lambda handler
├── template.yaml               <-- SAM template

Requirements

Installation Instructions

  1. Create an AWS account if you do not already have one and login.

  2. Install Git and install the AWS Serverless Application Model CLI on your local machine.

  3. Create a new directory, navigate to that directory in a terminal and enter https://github.com/aws-samples/amazon-eventbridge-producer-consumer-example.

  4. From the command line, run:

cd ./amazon-eventbridge-producer-consumer-example
sam deploy --guided

# Example of invoking lambda locally
aws lambda invoke --function-name eventbridge-app-atmProducerFn-xdazsEiS1rKs response.json

# or via sam cli
sam local invoke atmProducerFn

Choose a stack name, select the desired AWS Region, and allow SAM to create roles with the required permissions. Once you have run guided mode once, you can use sam deploy in future to use these defaults.

How it works

  • Use the AWS CLI or AWS Lambda Console to invoke the Producer function. This places the events in events.js onto the default event bus in EventBridge.
  • The EventBridge rule specified in template.yaml filters the events based upon the criteria in the EventPattern section.
  • When the rule validates an event, it is routed to the Consumer function. This logs out the event, which you can see in CloudWatch Logs.

==============================================

Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%