12-03-2017 10:22 PM
hi all, i m using script snap to generate presigned url for an object in s3 .
Failure: ReferenceError: “AmazonS3Client” is not defined, Reason: Script failed with the following error: ReferenceError: “AmazonS3Client” is not defined, Resolution: Fix the errors in the script file:
following is the script :
// Ensure compatibility with both JDK 7 and 8 JSR-223 Script Engines
try { load(“nashorn:mozilla_compat.js”); } catch(e) { }
//Import the interface required by the Script snap.
importPackage(com.snaplogic.scripting.language);
// Import the Java utility classes.
importPackage(java.util);
importPackage(java.io.IOException);
importPackage(java.net.URL);
importPackage(com.amazonaws.AmazonClientException);
importPackage(com.amazonaws.AmazonServiceException);
importPackage(com.amazonaws.HttpMethod);
importPackage(com.amazonaws.auth.BasicAWSCredentials);
importPackage(com.amazonaws.services.s3.AmazonS3);
importPackage(com.amazonaws.services.s3.AmazonS3Client);
importPackage(com.amazonaws.services.s3.model.GeneratePresignedUrlRequest);
/**
Create an object that implements the methods defined by the “ScriptHook”
interface. We’ll be passing this object to the constructor for the
ScriptHook interface.
/
var impl = {
/
/**
The “execute()” method is called once when the pipeline is started
and allowed to process its inputs or just send data to its outputs.
Exceptions are automatically caught and sent to the error view.
*/
execute : function () {
this.log.info(“Executing Transform Script”);
while (this.input.hasNext()) {
// Read the next document, wrap it in a map and write out the wrapper
var doc = this.input.next();
//var credentials = new BasicAWSCredentials(aws_id,secret_key);
var client = new AmazonS3Client( credentials );
var request = new GeneratePresignedUrlRequest( "snaplogic01-dev", "sample.pdf", HttpMethod.PUT);
request.setExpiration( new Date( System.currentTimeMillis() + (120 * 60 * 1000) ));
var wrapper = new java.util.HashMap();
wrapper.put("original", doc);
wrapper.put("url",client.generatePresignedUrl( request ).toString());
this.output.write(doc, wrapper);
this.log.info("Transform Script finished");
}
}
};
/**