Tech Blog‎ > ‎Geek corner‎ > ‎

Add Amazon S3 Data storage to your rules

posted Sep 12, 2016, 9:02 AM by Unknown user   [ updated Sep 12, 2016, 2:27 PM by Laura Carrubba ]

There are times when you need to read a file - an Excel spreadsheet, a comma separated file (CSV) , or an employee resume to/from Live API Creator. API server is a Java-based engine and you have full access to the java.io.File interface. This works fine if you are running a single user system on your laptop. However, in a production system that has been scaled horizontally, you would need to mount and map some shared filesystem (for example, x:/foo/bar/myfile.txt) . Another approach is to add the Amazon s3 JAR files to your Live API Creator environment and call the S3 files from the cloud.

If you are running on Amazon, add the following files to your WAR file (java jar uf CALiveAPICreator-3.0.WAR .ebsextensions/JDcDrivers.config):

Sample JDBCDrivers.config for Amazon S3

  "/usr/share/tomcat8/lib/aws-java-sdk-core-1.11.9.jar":

     mode: "000755"

     owner: tomcat

     group: tomcat

     source: http://central.maven.org/maven2/com/amazonaws/aws-java-sdk-core/1.11.9/aws-java-sdk-core-1.11.9.jar

 

  "/usr/share/tomcat8/lib/aws-java-sdk-kms-1.11.9.jar":

     mode: "000755"

     owner: tomcat

     group: tomcat

     source: http://central.maven.org/maven2/com/amazonaws/aws-java-sdk-kms/1.11.9/aws-java-sdk-kms-1.11.9.jar

 

  "/usr/share/tomcat8/lib/aws-java-sdk-s3-1.11.9.jar":

     mode: "000755"

     owner: tomcat

     group: tomcat

     source: http://central.maven.org/maven2/com/amazonaws/aws-java-sdk-s3/1.11.9/aws-java-sdk-s3-1.11.9.jar

 

  "/usr/share/tomcat8/lib/joda-time-2.9.4.jar":

     mode: "000755"

     owner: tomcat

     group: tomcat

     source: http://central.maven.org/maven2/joda-time/joda-time/2.9.4/joda-time-2.9.4.jar


If you are using Live API Creator running on Amazon (AWS) using Elastic Beanstalk (EBS). For more information about the setup, see Install on Amazon Web Services Elastic Beanstalk. The key is to add the correct Amazon JAR files to the installation (.ebsextensions/JDBCDrivers.config) shown above. The second part is to create a Java Class and library (see amazon documentation samples ) that you will load as a user library (JAR) in Live API Creator. Using a rule or event, you can call the new Java wrapper function. The trick is to either pass in the accessKey and secretKey (replace their sample code with new BasicAWSCredentials(accessKey,secretAccessKey) ); The other trick is to make sure you have set the access rights for each file you plan to read to allow this user read privileges.


var ReadFileFromS3 = Java.type("com.mycompany.s3.ReadFileFromS3");

var myFile =new ReadFileFromS3(buckeName, key, accessKey, secretAccessKey);