Integrate Salesforce with Amazon S3 within 15 min

on

|

views

and

comments

Dear Trailblazers,

In this blog post, we will learn how we can integrate Salesforce with Amazon S3 within 15 minutes. Yes, you read it correctly we will be able to integrate it within 15 minutes. Let’s start

Named Credentials

Before we start let’s talk about named credentials as we are going to use named credentials for the authentication.

A named credential specifies the URL of a callout endpoint and its required authentication parameters in one definition. Salesforce manages all authentication for Apex callouts that specify a named credential as the callout endpoint so that your code doesn’t have to. You can also skip remote site settings, which are otherwise required for callouts to external sites, for the site defined in the named credential. To learn more Click Here

Step1 – Get AWS Access Key ID & AWS Secret Access Key

Login into Amazon S3 Console using This URL then Click on your name on the Top right and the Click on “My Security

Credentials

Then Click on Access Keys & Click on Generate Access Key to generate the Key & Secret File. Download the Key file or Copy and paste the Key and Secret file and we are going to use these in next step.

Step 2 Create Named Credentials in Salesforce

Login into Salesforce Application, navigate to Setup -> Named Credentials and then Click on New Named Credentials

Provide Label and it will populate the Name automatically. And for the URL, the value should be combination of

scheme (https://) + instance name ( s3 ) + region name ( us-east-1 ) +amazonaws.com/

#1 – scheme will always be https://

#3 – As we are connecting with Amazon S3, so instance name will be s3. If you wanted to connect with EC2 then instance name will be ec2 ( all in small )

#3 – region name, you need to provide the region name here. To get the region name go back to Amazon S3 Console and in the URL you will get something like ?region=us-east-1 . So you need to use value after ?region=, in the example value is us-east-1

#4 – For AWS S3 it will remain same as amazonaws.com/ ( Do not remove / from the URL ) and it will keep changing based on the instance that you are trying to connect.

Now the value for URL field will look like below ( Considering above scenario )

https://s3.us-east-1.amazonaws.com/

For Identity select Named Principal from Dropdown, Provde AWS Key value and Secret value from that file that you downloaded from the Step 1.

For AWS Region, provide the value of the region and for AWS Service provide s3. Verify from the below image

 

Step3 – Test the Setup

To test the setup and check if this is working on not. We will try to get the list of Buckets from our AWS S3 Instance.

Execute below code from Developer Console.

HttpRequest req = new HttpRequest();
req.setEndpoint('callout:AWS_S3');
req.setMethod('GET');
req.setHeader('Content-Type','application/xml');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());
System.debug(res.getStatusCode());
System.debug(res.getStatus());

You will see the result like below along with Status Code as 200

And Boom, you have connected Amazon AWS S3 with Salesforce.

https://www.youtube.com/watch?v=0d6HvUZLofc&feature=youtu.be

If you have any questions or any feedback please share with us.

#KeepSharing #KeepLearning

Resources

Amazon API

Amit Singh
Amit Singhhttps://www.pantherschools.com/
Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion
Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

How to start your AI Journey?

Table of Contents Introduction Are you tired of the same old world? Do you dream of painting landscapes with your code, composing symphonies with data, or...

The Secret Weapon: Prompt Engineering: 🪄

Table of Contents Introduction Crafting the perfect prompt is like whispering secret instructions to your AI muse. But there's no one-size-fits-all approach! Exploring different types of...

How to Singup for your own Production org?

Let's see how we can have our salesforce enterprise Salesforce Org for a 30-day Trial and use it as a Production environment. With the...

Recent articles

More like this

28 COMMENTS

  1. Besides setting up the Name Credentials, what about Private Connect? does it need to set up also to integrate Salesforce with S3? we are using s3 for community cloud.

  2. Hi Amit, My requirement is to replicate the Salesforce database into the AWS. So if I want to post the Account record to S3, what should I need to create in the s3. A table as similar as Account in SF? Can you share the high level idea that would be really helpful. Thanks!

  3. i am getting this error – The request signature we calculated does not match the signature you provided. Check your key and signing method. Any idea what could be the issue

  4. Hi,
    I want to send the documents more than 20mb in size to s3. I know we have asynchronous heap size limit as 12 mb as of now. but still I want to achieve this without using any app exchange app from the lightning component. any suggestions?

  5. Name credential not working in manage package give below error
    “The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details. “

  6. Hi Amit,

    I need to delete some files(Objects) inside the S3 bucket using apex code. I am getting the below error while trying to hit the S3 bucket API.
    AccessDenied
    There were headers present in the request which were not signed
    content-md5
    GE86Q0HJYWN2PN7MOxmuA2S7Ntb3BLx1H9GT+87hwGwKbnFbwa3wIkEMWAhy/HtBXsM97qxd7H2/N0tkIjQhPQ=

  7. Question on this, it seems something is missing in the S3 configuration itself. The anonymous block receives a 403 (forbidden). Any recommendations?

  8. Do you do consulting? I have this job.
    We need something where our vendor automatically drops files with their software as they are created live in an s3 bucket in the format of [SalesforceTaskID]-[CallSID].wav
    but we need it in the format below. The salesforce task id in the .wav file could be used to do a call or whatever protocol to salesforce to get all the information from that particular TaskID because all of that information resides in Salesforce.
    10030_20210127-145204_367_SMS: 8333080761Call: 83330807618333080761_SMS: 7205306585Call: 72053065857205306585_IN_joe-agent.mp3
    It would need to update the S3 file name to this format except it can stay in .wav format.

    Recommended file name format in the excel file if interested

  9. Just for others having the access denied followed by “The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method”
    I had the same issue, but it resolved when I checked all three header options, not just the first one as pictured above. I assume it must depend on the AWS set up? I have zero control over that, so was happy this resolved it, hope it does the same for some others having the same issue
    Generate Authorization Header
    Allow Merge Fields in HTTP Header
    Allow Merge Fields in HTTP Body

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5/5

Stuck in coding limbo?

Our courses unlock your tech potential