Skip to content

Instantly share code, notes, and snippets.

@horike37
Last active June 16, 2016 19:18
Show Gist options
  • Save horike37/b6d0b89fca1f9b98590a to your computer and use it in GitHub Desktop.
Save horike37/b6d0b89fca1f9b98590a to your computer and use it in GitHub Desktop.
Amazon API Gateway + Lambda + CloudSearchで検索APIサービスを作ってみる ref: http://qiita.com/horike37/items/3e37ff6416f6cf2a7934
var aws = require('aws-sdk');
var cloudsearchdomain = new aws.CloudSearchDomain({
endpoint: '<CloudSearchのエンドポイント>'
});
exports.handler = function(event, context) {
var params = {
query:event.q
};
cloudsearchdomain.search(params, function(err, data) {
if (err) {
console.log("error " + err);
} else {
if (data.hits.found > 0) {
console.log(data.hits.hit[0]);
context.done(null, data.hits.hit[0]);
} else {
console.log('not found');
context.done(null, 'error');
}
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment