Event Relay: Publish Events from Salesforce to Amazon EventBridge

Kam Patel
AppExchange and the Salesforce Ecosystem
7 min readJul 8, 2022

--

When building application integrations, there are two common approaches: request-response and event-driven architecture. In request-response architecture, the client sends a request (e.g. SOAP/REST API) and expects a response synchronously. In the event-driven architecture, the client generates an event and can immediately move on to its next task. Loosely coupled integrations enable less brittle and scalable architectures.

A new way to publish and subscribe to Salesforce Platform Events is coming: the Pub/Sub API, and you can learn more in this blog post. We can write a listener in AWS (or any external system) to subscribe to the Salesforce Platform Events and process them. With the new Event Relay beta, each custom platform event or change data capture event that is published to the Salesforce event bus is automatically forwarded to an event bus in Amazon EventBridge. That means if you are using AWS, you can subscribe to the Salesforce Platform Events without writing a custom listener app.

Let’s walk through the steps of configuring new Salesforce Event Relay and Amazon EventBridge. As a bonus, we will take that learning to the next level and update the demo app in “Salesforce Connect Demo: Virtualizing DynamoDB” using the same configuration with minor changes.

Disclaimer: Salesforce labapp and AWS stack in this blog post is provided as-is, use it as a general guidance. For AWS you are responsible for everything including all the expenses incurred and security aspects. Event Relay is still in beta.

Please contact your Salesforce account/success team if you are interested in joining the Event Relay beta or learning more. If you are an AppExchange partner looking for help with this topic, you can request an ISV Platform Expert consultation, join the Event Relay beta, and have a technically focused conversation with me.

The Scenario

A fictitious e-bike B2B company sells high-tech bikes directly to third-party vendors. Once the order has been created in Amazon DynamoDB, they want to publish a platform event to AWS to start the order processing workflow.

Basic configuration

Let’s get going. We will configure Event Relay and Amazon EventBridge which will enable the published Platform Events to (from Salesforce Lightning Flow) make their way to the Amazon Cloudwatch logs.

Note: We will be shuttling between the Salesforce and AWS configuration setup

AWS Setup

  • Get AWS Account ID & Access Keys.

Under your account name copy Account ID (blurred with the blue box).

Next click Security Credentials, and create new Access keys. Save these for the next steps.

Note: This is just for demo purposes. In practice, do not use AWS root user for API access. Instead, create an additional user with only required permissions.

Security Credentials
New Access keys

Salesforce Org Setup

Let’s configure your Salesforce org for Event Relay. This should take around 30 minutes.

In beta, Event Relay supported setup experience is via the Tooling API (documentation will be public in near future). Event Relay will GA with configuration via the Tooling API and that the setup UI will follow as a post-GA improvement. In the meantime, you can use either Tooling API or unsupported unlocked package (Thanks to

who built this cool utility) to perform the required configuration.

In this blog, we will use the unmanaged package.

Step 1: Install helper package

  • Install Event Relay helper (un-managed) package in your org, either using this (for sandbox org) or this (for dev org).
  • Open the “EventRelayUtil” app

Step 2: Create a Named Credentials

Relevant API: /services/data/v55.0/tooling/sobjects/NamedCredential/

Using the helper package UI: Name the NamedCredentials “EventRelayDemoNC”. Make sure to put your AWS account number (from prior step). For AWS region, make sure to enter “US-EAST-1”

Note: You can create NamedCredentials from Setup as well.

Step 3: Create channel

Relevant API: /services/data/v55.0/tooling/sobjects/PlatformEventChannel

Using the helper package UI: Name the channel “ebikesEventPublishChannel”

Step 4: Add channel member

Associate the channel to the Platform event that is part of the package you installed

Relevant API: /services/data/v55.0/tooling/sobjects/PlatformEventChannelMember

Using the helper package UI: Select the Event Channel “ebikesEventPublishChannel” and the Platform event “TestLoanProcessRequest__e” as shown

Step 5: Create Event Relay config

Relevant API: /services/data/v55.0/tooling/sobjects/EventRelayConfig/

Using the helper package UI: Create “New Event Relay Configuration” by associating the channel and Named Credentials.

Here is what it should look like. Note that the Status is not active yet. We will come back to this soon.

AWS Setup

After configuring the event relay in Salesforce, the Event Relay creates a partner event source in the Amazon EventBridge. We need to associate the partner event source with an event bus. This should take around 15 minutes.

  • Go to Amazon EventBridge. Click the Partner event sources and associate the newly created Partner Event Source with Event bus
  • Let's create a rule that will log incoming events to CloudWatch. Select event bus that you associated in the previous step

Click “Create rule” and select the values as shown below

Select target as “AWS service”, Cloudwatch log group, and name it anything

This is what it will look like.

Salesforce Org Setup

  • Activate the Event Relay configuration
  • Refresh the page and you status should be “Run”

Test the Event Relay

  • In Salesforce org, create a Lightning Flow that publishes the Event. Create a Screen based flow with an action that creates a platform event. Run this Flow in the debug mode
  • In AWS under CloudWatch logs you should see the above event logged

Leverage Event Relay in ebikes Demo (Optional)

In this previous blog post, we walked through a demo of how ebikes (a fictitious B2B company) leverages Amazon DynamoDB to store and process orders.

Pre-requisite: Complete the “Salesforce Connect Demo: Virtualizing DynamoDB” blog’s Step 1–3.

Instead of starting the AWS Workflow (Step Functions) via DynamoDB streams (think of it as a trigger), we will publish a Platform Event from Salesforce which will be pushed to the Amazon EventBridge and that will start the AWS workflow.

Here is what the data flow will be:

  • The Sales Agent selects an account and creates an Order (using no code Lightning Flow).
  • Before implementing Event Relay: Post insert of Order record in the DynamoDB table, a Lambda function gets triggered which publishes an event to kick off AWS workflow
  • After implementing Event Relay: As shown in Step 2 below, post insert of an Order record in the DynamoDB table, Lightning Flow publishes the “Order Processing Request” event which makes its way to the Amazon EventBridge via Event Relay to kick off the workflow. Yes — no code, just config!

Updated Data Flow Outlined:

High-level steps

  • Delete the DynamoDB stream that calls the Lambda function to trigger Step functions
  • Add a new target to the Rule you created above, that will start the Order processing step function

That’s it! Now when you create an order from the Lightning Flow, everything should work as planned.

Clean up

Always clean up the AWS resources once done so you don’t incur additional cost.

Summary

We implemented Event Relay to send Salesforce Platform Event to the Amazon EventBridge and process it, all without writing any code.

--

--

Kam Patel
AppExchange and the Salesforce Ecosystem

Hello! I work at Salesforce as a technical expert for ISV partners. I love going for long walks, socializing, public speaking and teaching kids in rural areas.