AWS Node.js SDKをご覧ください。すべてのAWSサービスエンドポイントにアクセスできます。
var sns = new AWS.SNS();
// subscribe
sns.subscribe({topic: "topic", Protocol: "https"}, function (err, data) {
if (err) {
console.log(err); // an error occurred
} else {
console.log(data); // successful response - the body should be in the data
}
});
// publish example
sns.publish({topic: "topic", message: "my message"}, function (err, data) {
if (err) {
console.log(err); // an error occurred
} else {
console.log(data); // successful response - the body should be in the data
}
});
EDIT:問題は、標準のボディパーサーは、SNS、コンテンツタイプとして送信するものであるプレーン/テキストを処理していないということです。生の体を抽出するコードです。あなたの体のパーサ前にそれを置きます:あなたはその後、使用することができます
app.use(function(req, res, next) {
var d= '';
req.setEncoding('utf8');
req.on('d', function(chunk) {
d+= chunk;
});
req.on('end', function() {
req.rawBody = d;
next();
});
});
:
JSON.stringify(req.rawBody));
あなたのルート内のJavaScriptオブジェクトを作成し、適切なSNSポストに動作します。
また、text/plainを処理するように本体パーザーを変更することもできますが、ミドルウェアを変更することはできません。上記のコードを使用してください。
コンテキストとして:この(合理的で素朴な)アプローチが失敗する理由は、SNS HTTPセットです。 "Content-Type:text/plain; charset = UTF-8" 参照:http://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.html (SNSではJSONが実際にはうまくいきません) – Jason