Salesforce Connect Demo: Virtualizing DynamoDB

Kam Patel
8 min readMay 16, 2022

--

Virtualizing Amazon DynamoDB table within a Salesforce org enables the users of Salesforce applications to seamlessly access and handle data stored in AWS DynamoDB database, without leaving the Salesforce native environment. We’re going to walk through a demo of how you can put this feature to work for you in your orgs.

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. Salesforce connect for Amazon DynamoDB is in GA.

AppExchange partners looking for help with this topic can request an ISV Platform Expert consultation and have a deep, technically-focused conversation with me.

The Scenario

In this blog post, we’ll walk through a demo using a fictitious e-bike company as the star. The B2B company sells high-tech bikes directly to third-party vendors. The company needs the ability to store and process order-related records off-platform in the Amazon DynamoDB database.

Here’s a snapshot of the solution we’ll go through:

  • The Sales Agent selects an account and creates an Order (using no code Lightning flow).
  • “Orders” and related “Order processing” are two external Objects stored in the DynamoDB database table (this table uses a single table design pattern). Here is what the sObject relationship looks like in Salesforce…

Account (indirect lookup relation) Order External Object (external lookup relation) Order Processing External Object

  • On the insert of Order record in the DynamoDB table, it tiggers an AWS workflow (step function). The workflow in turn creates Order Processing step records in the DynamoDB table, and then publishes “Order Status Update” event on Amazon Eventbridge, which then finally sends the Platform event to Salesforce org via AWS API destination.

Data Flow outlined:

Lightning Flow DynamoDB “Order” AWS Workflow Insert “Order processing “ records Publish Order status update on Eventbridge Eventbridge rule Event bridge API destination Salesforce platform event Flow Slack

  • Using Lightning flow OOB slack actions (Summer ’22 beta), Order status event notifications are sent from Salesforce org to Slack.
The architecture and a data flow.

Pre-requisites to Know

1. Use an existing AWS instance, or sign up for one here.

2. Sign up for a Salesforce Summer ’22 preview org here.

AWS Setup

Now, let’s get AWS in a good place. This setup should take around 10 minutes.

Pre-requisite:

On your local machine, if you do not have npm or AWS CDK…

  • Install npm by running the command “npm install -g npm”
  • Install AWS CLI by running command “npm install -g aws-cdk”

From command line:

  • Run “AWS configure”
  • Run the command “cdk bootstrap aws://YOUR-AWS-ACCOUNT-NUMBER/us-east-1”, replacing YOUR-AWS-ACCOUNT-NUMBER with your AWS account number.

Step 1: Install the Stack

  • In the AWS console, change the region to us-east-1 (This is located in the top second right menu item).
  • Go to AWS Services → CloudFormation → Stacks
  • Click “Create stack” with the option “With new resources (standard)”, select all defaults thereafter and use.
  • For us-east-1 region use this S3 URL.
  • Name the stack “ebikedemo”, accept all other defaults, and create the stack.

Note: If you get an error installing the stack, do this: before reinstalling the stack, delete the existing stack, delete DynamoDB table, and delete ebikesOrderStatusEventLogGroup.

Wait until the Stack creation is complete. This may take 5–10 minutes.

Step 2: Get AWS Access Keys

Under your account name, go to Security Credentials and create a new Access keys. Note: This is just for the demo. 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 and test steps one to three. This should take around 15 minutes.

Pre-requisite: Salesforce Summer’22 org.

Step 1

Install ebike-aws demo app.

Step 2: Update Named Credentials

Update “AWS Access Key ID” and “AWS Secret Access Key”, using the Access keys from AWS Step 2.

Step 3: Add “Order create” Flow to Account Record Page

Go to “ebike Order” page. On the Account Record page, under the gear icon, click “Edit Page”

  • Add “ebikes New Order” flow to the page as shown in the gray annotation.
  • Make sure to click the “Pass record ID into this variable” checkbox as shown in the green annotation.

Step 4: Add E-bikes Orders to the Accounts Page Layout

Test (Step 1, 2, 3)

  • Go to “ebike Order” page, select an account record.
  • Using “ebikes New Order” flow, creates few orders. It should show related orders and you can drill down further to see Order processing steps for each order.

From Amazon Eventbridge, send ‘Order Status Update’ Platform event (Step 4)

Once the order processing is done by AWS workflow, now we can work on notifying the Salesforce e-bike app using the Platform event?

AWS has an existing feature whereby events published in Event bridge can be routed to Salesforce. Please follow this tutorial or follow these steps. Note: Following steps can be part of Cloudformation template, but I want to show this how to configure it manually!

Configure Target 1

First log the Order Status Update Event to Cloudwatch log (so we can see what it looks like).

  • Go to Eventbridge → Rules
  • Give any name to the Log group and complete the wizard with default values.

Time to Test

  • Now go to the Salesforce org, select an account, and create an order.
  • In the Cloudwatch log (that you created in Target 1), you will see the event payload (published by the Step function) under the “detail” node as shown.
  • In the next step, we will route only that payload to the Salesforce platform event

Setup Target 2

Let’s publish the event to Salesforce via API destinations.

Pre-requisite: Create a connected app in the Salesforce org with these values:

  • Selected OAuth Scopes: Manage user data via APIs (api)
  • Callback URL: https://localhost:8001/callback (can be any URL)
  • Assign the connected app to your user-profile

Create a new API destination

API destination endpoint: Replace “domain” with your domain name…. (e.g. Mine is forcecom282-dev-ed) https://domain.my.salesforce.com/services/data/v54.0/sobjects/ebikesaws__OrderStatusUpdate__e

Update Client ID and Secret with your connected app values. Make sure the password is a secret body field, and also append the user’s security token to the password.

Now click Create. Note: That will validate your Salesforce org credentials so if you get an error, fix the values and try again.

Edit existing Eventbridge Rule to Add Newly Created API destination as Another Target

  • Go to Step 3, and click “Add another target”
  • Select the existing API destination that was created in the prior step.
  • Under “Additional Settings”, select “Part of the matched event” and enter the value “$.detail” (remember we want only payload to be sent to Salesforce platform event), complete the wizard and update the rule.

Time to Test

Now in the Salesforce org, when you create a new order from the e-bikes app, you should receive an email because there is a Lightning Flow waiting for an Order status update event.

Slack Notification (Step 5)

Instead of sending an email, wouldn’t it be cool if we send a notification to the Sales Agent via Slack? You can do it without writing a single line of code! Thanks to Lightning flow and brand new Customer 360-degree hub (beta).

Pre-requisite:

  • Enable Slack in Salesforce org.
  • Sign up for a free Slack workspace (if you don’t have an existing Slack workspace).
  • Connect Slack hub to Salesforce org

Go here and click “ADD THE SALESFORCE DIGITAL HQ FOR SLACK APP”.

Add Slack Action to Existing Lightning Flow Template

  • Open “ebikes Order Status EventHandler” flow
  • Deactivate the flow
  • Add a new activity “Send Slack Message”

Test the Updated Order Status Flow

  • Open “ebikes Test Order Status Update Event”
  • Debug, add any order id

You should see a Slack message sent to the Slack channel.

  • Save the “ebikes Order Status EventHandler” flow as a new workflow and activate.

Now when Amazon EventBridge sends an Order status platform event, you should get Slack notifications.

Clean-up

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

Summary

Now at the e-bike company, the Sales agents are able to place an order which are stored and processed in AWS. We connected the Salesforce org to the Amazon DynamoDB table and even pushed the notification events to the Slack — all without writing any code!

--

--

Kam Patel

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.