AWS AppFlow <> Salesforce - automating multi tenant setup

Viewed 77

I'm brain storming the architecture for a new SaaS that will require processing events from one Salesforce instance per customer. I'll be using AWS AppFlow with Lambdas to process the events.

The basic flow is that the user will sign up via a web app for the SaaS, upon which I will need to create the AppFlow for this specific user. The user will need to sign in to Salesforce for OAuth during the sign up process, which should give me the Access Token for the user.

What I'm confused by is how to make this process dynamic/automated - should I be calling AWS APIs (eg CreateFlow, CreateConnectorProfile)? I've only ever worked with static resource YML files before for AWS resources, since it was a one time setup, not multi-tenant. Obviously having to manually push code each time a user signs up would be a hassle.

Would passing in the Access Token be enough (from the point of view of AuthN/Z) to call the create APIs?

1 Answers

Nope, a lot simpler than that if I'm reading your idea correctly. I've personally enjoyed Salesforce Platform Events for this.

https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-saas-salesforce.html

To summarize:

  1. You create a "listener" in Eventbridge/AppFlow for Salesforce-sourced events.
  2. Funnel those requests to Eventbridge eventbus. Overflow may go to s3
  3. The eventbus is then tied to a lambda where you can make your decisions.

In the platform event, you'd define a few fields like the access token, name, org id, etc. You can define a simple Apex file which publishes the platform event once its created. I generally have a Salesforce flow call an invocable to this Apex class to perform last second cleanup and publishing.

https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_publish_apex.htm

List<Low_Ink__e> inkEvents = new List<Low_Ink__e>();
inkEvents.add(new Low_Ink__e(Printer_Model__c='XZO-5', Serial_Number__c='12345', 
              Ink_Percentage__c=0.2));
inkEvents.add(new Low_Ink__e(Printer_Model__c='MN-123', Serial_Number__c='10013', 
              Ink_Percentage__c=0.15));


// Call method to publish events
List<Database.SaveResult> results = EventBus.publish(inkEvents);

// Inspect publishing result for each event
for (Database.SaveResult sr : results) {
    if (sr.isSuccess()) {
        System.debug('Successfully published event.');
    } else {
        for(Database.Error err : sr.getErrors()) {
            System.debug('Error returned: ' +
                        err.getStatusCode() +
                        ' - ' +
                        err.getMessage());
        }
    }       
}

When the lambda fires, it receives a single record with all the data you're looking for. Easy to move to any storage piece like DynamoDB, S3, etc. Or just use it instantly.

Related