Skip to content

Instantly share code, notes, and snippets.

@mzaradzki
Created May 29, 2017 16:16
Show Gist options
  • Save mzaradzki/306f00e93e9f9e0bdff5a34ed5a5c1be to your computer and use it in GitHub Desktop.
Save mzaradzki/306f00e93e9f9e0bdff5a34ed5a5c1be to your computer and use it in GitHub Desktop.
AWS Lambda function to class Cloud Search API with javascript SDK
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