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
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 )
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.