Technical Articles
OpenConnectors-Amazon S3 Integration made simple with SAP CPI & SAP CP-OCN
Introduction:
In below blog would like to share how we can integrate Amazon S3 and SuccessFactors using SAP CPI & SAP Cloud Platform Open Connectors service.
Scenario:
Lets create simple scenario to pull user dump from SuccessFactors to create file in Amazon S3 Bucket.
Configuration in AWS [ Bucket and Folder Creation ]
Step 1:
Login to your AWS account and Navigate to S3 service.
Step 2:
Create a bucket shown like below following mentioned steps.
Step 3:
Create a folder like below
Configuration in AWS[ IAM service Configuration ]:
Now lets create an user and credentials required to connect AWS S3 bucket from SAP OCN.
Step 1:
Click on Services and navigate to IAM Service.
Step 2:
Navigate to Users and Click on Add User.
If already group is available you can select or else select Create Group.
Now we are all set with AWS Configuration and make sure to copy below credentials which is required for SAP OCN Configuration.
SAP Open Connector Configuration:
Login to SAP Cloud Platform and launch Open Connectors service.Search for Amazon S3 and click on authenticate.
Fill all the required details like below ( API Key,Secret,folder name and Region Endpoint ) and click on Create Instance.
Now you are successfully connected to S3 with below message and click on API Docs.
Click on Post files operation by selecting file that needs to uploaded and folder path inside S3 Bucket.
Navigate to response to copy the credentials and endpoint url to be used in SAP CPI .
SAP CPI Configuration:
Lets create an iflow to pull the data from SuccessFactors and connect to OpenConnectors endpoint url.
Step 1:
Configure Timer Event to initiate the IFlow deployment.
Step 2:
Add Request Reply step with SuccessFactors OData V2 protocol.And configure your channel like below .You can refer below link to make sure it works.
https://blogs.sap.com/2018/04/10/sap-cloud-platform-integration-odata-v2-query-wizard/
Step 3:
Add Content Modifier and set property to set filename with folder which later can be used in receiver adapter channel.
Step 4:
Add a script to log the payload.Refer below blog for payload logging .
https://blogs.sap.com/2016/04/19/hci-logging-using-groovy-scripts/
Step 5:
Add XML to CSV converter to generate CSV file.
Step 6:
Add a script to log the payload.Refer below blog for payload logging .
https://blogs.sap.com/2016/04/19/hci-logging-using-groovy-scripts/
Step 7:
Add Script to set authorization header and set multipart data.Make sure to replace below Auth header with value copied from SAP OCN configuration.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.io.*;
def Message setHeader(Message message, String id) {
message.setHeader("authorization", "YOUR AUTH HEADER GOES HERE");
message.setHeader("content-type","multipart/form-data; boundary=--------------------------" + id);
return message;
}
def ByteArrayOutputStream getMultiPartBody(payload, filename, id) {
String charset = "US-ASCII";
def LINEFEED = "\r\n";
def output = new ByteArrayOutputStream();
output.write(("----------------------------"+ id).getBytes(charset));
output.write(LINEFEED.getBytes(charset));
output.write(("Content-Disposition: form-data; name=\""+"file"+"\"; filename=\""+filename+"\"").getBytes(charset));
output.write(LINEFEED.getBytes(charset));
output.write("Content-Type: text/csv".getBytes(charset));
output.write(LINEFEED.getBytes(charset));
output.write(LINEFEED.getBytes(charset));
output.write( payload.getBytes(charset));
output.write(LINEFEED.getBytes(charset));
output.write(("----------------------------"+ id + "--").getBytes(charset));
output.write(LINEFEED.getBytes(charset));
return output;
}
def Message processData(Message message) {
String charset = "US-ASCII";
def id = "937427310133901149517591";
def map = message.getProperties();
def filename = "sriprasadtest_1.csv"
def ByteArrayOutputStream output = getMultiPartBody(message.getBody(String.class),filename,id);
message = setHeader(message, id);
message.setBody(output.toByteArray());
return message;
}
Step 8:
Add HTTP adapter with below mentioned parameters.
Now you are all good to go with deployment.!
Result:
Once you deploy file will be created in Amazon S3 folder.Now time to check for the result!
Reference:
[ 1 ] – Open Connector Blog series
Hope this helps and Happy Learning!
Regards,
Sriprasad Shivaram Bhat
Thanks for taking time and putting up this well informed blog. Good work Sriprasad.
Bhargav
Hi Sri,
Thanks for another very informative write-up. Keep blogging!
Regards,
Karthik
Thanks for sharing the blog especially in AWS space.
Hi Sriprasad,
Can we use the AWS S3 Open connector to be connected with SAP IBP Data services on Cloud? We have the flat files with some data that are present on AWS S3 storage and we want to consume the data directly in SAP IBP DS cloud.
Please advise?
Thaanks,
Vipin
Hello Sriprasad,
Request to please share some inputs on how to integrate to Amazon S3 Bucket using SAP PO ? Scenario is ECC (Pick .csv File from Al11) <---> SAP PO <-----> Post the file in Amazon S3 Bucket.
//Thanks
Tapas Tarun
HI tapas tarun
Did you complete the integration? If yes, can you share some reference? Or can you guide me how you proceeded I've the same scenario.
Thanks!
Dear Arsh,
Unfortunately, the requirement was put on hold due to costing issue. I guess with CPI and Open Connectors we can achieve this scenario as there are SAP Adaptors available to connect to Amazon S3 as mentioned by various Integration Leads.
https://blogs.sap.com/2019/06/24/advantco-adapter-amazon-s3-integration-made-simple-with-sap-cpi-sap-cp-ocn/
With PI/PO i am still searching on how to achieve this.
//Thanks
Tapas Tarun
Quick question. What is the significance of id below? That id value is being passed to 2 methods.
Nice blog.
Thanks,
Jay
Thanks for a very helpful andd informative blog , i was able to make it work !
Can you show a sample of auth header ? currently i used the three element as in the sample request from open connector page : User,Organization and Element but thats just for one instance how can we automate the instance creation?
Though you mentioned using the file contents we downloaded from AWS IAM but that seemed to be not working , can you help ?