Last active
June 16, 2016 19:18
-
-
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
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
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