Created
May 29, 2017 09:22
-
-
Save mzaradzki/53ec0be5091729acd4c9ed5b60e1adc4 to your computer and use it in GitHub Desktop.
Lambda code to add a document to CloudSearch using javascript SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addToIndex = function (bucketName, docName, docContent, context) { | |
var csd = new AWS.CloudSearchDomain({ | |
endpoint: CS_NAME+'.'+SERVICES_REGION+'.cloudsearch.amazonaws.com', | |
apiVersion: '2013-01-01' | |
}); | |
// see documentation at : | |
// http://docs.aws.amazon.com/cloudsearch/latest/developerguide/preparing-data.html#creating-document-batches | |
var jbatch = [ {"type": "add", | |
"id": bucketName+':'+docName, | |
"fields": {"content": docContent, | |
"content_encoding": "ISO-8859-1", | |
"content_type": "text/plain", | |
"resourcename": docName }, } ]; | |
var params = { contentType: 'application/json', documents: JSON.stringify(jbatch) }; | |
csd.uploadDocuments(params, function(err, data) { | |
if (err) { | |
console.log('CloudSearchDomain ERROR'); | |
} | |
else { | |
console.log('CloudSearchDomain SUCCESS'); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment