Announcement

Collapse
No announcement yet.

AWS S3 Get Javascript Reader

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • AWS S3 Get Javascript Reader

    Hey guys, here is some quick code to retreive a file from an S3 bucket and inside of your Javascript reader. If you have any improvements feel free to share

    Code:
    // Set the AWS account Access Key, AWS account Secret Key
    var awsCreds = new Packages.com.amazonaws.auth.BasicAWSCredentials(accessKey, secretKey);
    
    // Set the s3client
    var s3client = new Packages.com.amazonaws.services.s3.AmazonS3Client(awsCreds);
    
    // Create s3Object
    var s3Object = s3client.getObject(bucketName, keyName);
    
    var s3ObjectInputStream = s3Object.getObjectContent();
    
    var bReader = new BufferedReader(new InputStreamReader(s3ObjectInputStream));
    var line;
    var lines = bReader.lines().filter({
    	test: function (x) {
    		return x.length != 0
    	}
    }).toArray();
    
    for (var i = 0; i < lines.length; i++) {
    	logger.info('Text Line: ' + lines[i]);
    	messages.add(new RawMessage(lines[i]));
    }
    s3ObjectInputStream.close();
    return messages;

  • #2
    Great!! Thanks!

    Comment

    Working...
    X