AWS Lambda function to class Cloud Search API with 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
exports.handler = (event, context, callback) => { | |
var csd = new AWS.CloudSearchDomain({ | |
endpoint: CS_NAME+'.'+SERVICES_REGION+'.cloudsearch.amazonaws.com', | |
apiVersion: '2013-01-01' | |
}); | |
var params = { | |
query: event.query, | |
sort: '_score desc', | |
size: event.size, // number of documents to return | |
start: event.start, // start index of document list to return (cf multi tab) | |
queryOptions: JSON.stringify({fields: ['content']}), | |
}; | |
// see documentation at : | |
// docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudSearchDomain.html#search-property | |
csd.search(params, function(err, data) { | |
if (err) { | |
callback('CloudSearch ERROR'); | |
context.done(); | |
} | |
else { | |
callback(null, data); // SUCCESS | |
context.done(); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment