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
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.
If you have any questions or any feedback please share with us.
#KeepSharing #KeepLearning
Can I know more about Put / data pull from salesforce in S3?
Let me know what you wanted to know?
Do you have any sample class that allows you to copy a text file from S3 to Salesforce.com files?
Hi Joseph,
I am working on it. I will post the same over here.
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.
Hi Harry,
You can give it a try but I have not implemented a private connect.
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!
You need to ask your business where they wanted to store the data and in which format as there is no concept of the table in AWS S3.
Hi , My requirement is upload large files Salesforce to aws using apis. Please help me on this.
What sort of help are you looking from me?
I am looking gor aws s3 mulitipart api Integration with salefore for uploading files in s3 bucket. If you created any blog please share with me.
I did not create any blog for this.
Hi Amit,
I am still getting Code>AccessDenied , i have followed on the steps. Do you know reason for this.
I do not have any idea about this.
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
By Seeing the error, it seems that your credentials are incorrect.
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?
You can use AWS JavaScript SDK for the same.
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. “
Looking at the error it seems the error is related to your AWS key or AWS Secret not related with Managed Package.
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=
This is really strange are you able to make a get-call to see all the objects and/or buckets?
Question on this, it seems something is missing in the S3 configuration itself. The anonymous block receives a 403 (forbidden). Any recommendations?
403 in AWS is access denied, you might need to check some permissions related to your account. Here is the Link
[…] https://pantherschools.com/integrate-salesforce-with-amazon-s3/ saved with Instapaper […]
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
Yes. You can reach out to me via my linkedin – https://www.linkedin.com/in/simplyamit/
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