How to send Salesforce Platform Events to Amazon EventBridge?

How to send Salesforce Platform Events to Amazon EventBridge?

Event Relay can be used to send Salesforce Platform Events to Amazon EventBridge.

1. Create a Platform Event in Salesforce.

2. Create a Connected App in Salesforce.

Callback URL should be https://{Your Domain}.my.salesforce.com/services/oauth2/callback

Example:

https://test-ec-dev-ed.develop.my.salesforce.com/services/oauth2/callback

3. Get the Access token.

Endpoint URL:

https://test-ec-dev-ed.develop.my.salesforce.com/services/oauth2/token

4. Use the Access Token from Step 3 and make a POST Request to create PlatformEventChannel.

Endpoint:

https://test-ec-dev-ed.develop.my.salesforce.com/services/data/v56.0/tooling/sobjects/PlatformEventChannel

Header:

Body: 

5. Make a POST Request to create PlatformEventChannelMember.

Endpoint:

https://test-ec-dev-ed.develop.my.salesforce.com/services/data/v56.0/tooling/sobjects/PlatformEventChannelMember

Header:

Body:

6. Create a Legacy Named credential with URL in the following format.

arn:aws:aws_region:aws_account_number

7. Make a POST Request to create EventRelayConfig.

Endpoint:

https://test-ec-dev-ed.develop.my.salesforce.com/services/data/v56.0/tooling/sobjects/EventRelayConfig

Header:

Body:

8. Use the following SOQL and execute in your Salesforce Developer Console.

SELECT Id, RemoteResource, Status, 
ErrorMessage, ErrorTime, ErrorIdentifier 
FROM EventRelayFeedback 
WHERE EventRelayConfigId ='7k23t0000008OI5AAM'

Note down the RemoteResource value.

9. Search the RemoteResource in Amazon EventBridge. Use the Associate with event bus button to associate the Salesforce Partner Event Source.

10. Start the Event Relay by setting the State to RUN. Do a PATCH Request.

Header:

Body:

11. Create a Rule in Amazon Eventbridge. Use the following Pattern.

{
  "source": [{
    "prefix": "aws.partner/salesforce.com"
  }],
  "detail-type": ["Employee__e"]
}

12. Use the following code to Publish a Platform Event.

List < Employee__e > listEvents = new List <Employee__e >();
listEvents.add( 
	new Employee__e( 
		Employee_Number__c = '12345',
		Notes__c = 'Testing'
	) 
);

List < Database.SaveResult > results = EventBus.publish( listEvents );

for ( Database.SaveResult sr : results ) {

    if ( sr.isSuccess() ) {
    
        System.debug( 'Event successfully published event.' );
        
    } else {
    
        for(Database.Error err : sr.getErrors()) {
        
            System.debug( 'Error code: ' + err.getStatusCode() );
            System.debug( 'Error message: ' +   err.getMessage() );
                        
        }
        
    }  
         
}

13. Check in Amazon CloudWatch log group.

Leave a Reply