Integration: Salesforce with AWS Simple Cloud Storage (Amazon S3)

In this article I am going to discuss integration requirement where we integrate Salesforce with AWS S3. I would like to share the business requirement and the different integration design patterns we take to meet this kind of integration requirement.

As we know Amazon S3 or Amazon Simple Storage Service is offered by AWS for cloud-based storage solutions. It is being used for several use cases and I am going to discuss one use case that I have worked several times in recent times.

Business Scenario

As you know, Salesforce provides great support for File storage. After moving from attachment to content module, Salesforce is offering great capabilities for file management.

Though Salesforce File is a great feature, most of the client prefers to manage files outside of Salesforce in dedicated Content Management System. AWS S3 is becoming a preferred solution for file storage requirements.

This brings the need of designing an integration solution that sends (uploads) the Salesforce file to Amazon S3 once it is associated to an object record (Opportunity, Case, Account or anything) in Salesforce.

Well, when we decide to use AWS S3 as file repository, we have to be ready to design a solution that is scalable and can upload small as well as big files without running into APEX Heap Size limitation.

Integration Solutions

As we do for any new business requirement, we start exploring different options. I have listed few options here but there could be more in this list.

1. Middleware Solution

This is my preferred solution. If we have a middleware that can connect to Salesforce and pull the files and upload to AWS S3 then I believe this is the best solution.

This design pattern is widely used, and we also followed same several time. We have to do little or no additional development in Salesforce and middleware can use standard REST API to pull the file using Content Version and upload it to Amazon S3.

Middleware can have all the necessary logic to identify and filter the necessary content document from Salesforce. Alternatively, it can be event-based solution where Salesforce notify the change and middleware tool pulls the documents. We used this design pattern few times where we published a platform event and middleware solution reacts on our event and pulls the necessary document(s) and upload(s) to Amazon S3. In some cases it updates back S3 document URL back to Salesforce

2. HTTPRequest – APEX Based Solution

This is other option we used few times. We create an APEX class that uses HTTPRequest class and sends the file to HTTP location. This is similar to calling any other REST API endpoints.

This is simple and accepted solution if you are working with small file size. If you try to send larger file, it is going to report heap size exception.

You can find lot of sample code online and you can update the code as needed for your use case.

3. Event based solution: Platform Event, Event Relay, EventBridge & Lambda

Last few years Salesforce is making AWS integration more and more easy and configurable. This is other preferred integration design pattern if you are not planning to use any middleware. This is no-code integration design pattern

This approach requires lot of configurations in Salesforce and AWS and may require development of Lambda function at AWS. I am going to list down steps and each steps require you to go through Salesforce help or related article if you do not know how to configure that.

Once you have done all the configuration then your integration should work as mentioned below:-

  • A user uploads a new file to Salesforce object record
  • A trigger (after Insert) configured on Content Version Object publishes a Platform event with Content Version Id and File Name
  • Salesforce Event Relay configuration, relays this event message to AWS EventBridge
  • A rule configured in Salesforce EventBridge triggers a lambda function
  • Lambda function process the event message and extracts the details needed and calls Salesforce REST API to get document details
  • Lambda function uploads the Salesforce file (output from REST Object) to AWS S3 Bucket
Configuration Requirement

Following configuration we have to do to complete this integration. This cannot be one page article and requires lot of configurations at Salesforce like Connected App, Named Credentials, Platform Events, Event Relays, Triggers etc…

  • Create a Platform Event to publish the event when a new content document is created or updated. You can add Content Version Id along with File Name and any other details that you would be requiring to send to AWS
  • Create trigger on Content Version object that publishes a platform event when a new content document is created
  • Configure Event Relay to leverage AWS EventBridge and send event to AWS. Refer this Salesforce document: https://help.salesforce.com/s/articleView?id=sf.ev_relay_intro.htm&type=5
  • Create a Lambda function that is triggered when AWS EventBridge receives notification from Salesforce. Refer AWS Lambda Function documentation

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top