Node.js で、AWS の SNS にパブリッシュ(投稿)する方法です。
Arch Linux と Raspbian で動作を確認しました。
topic は変更して下さい。
#! /usr/bin/node
// ---------------------------------------------------------------
// sns_test.js
//
// Dec/08/2017
//
// ---------------------------------------------------------------
// exports.send_sns_handler = function(event, context) {
function send_sns_handler (event, context)
{
console.error ("*** end_sns_handler *** start ***")
var aws = require('aws-sdk')
var sns = new aws.SNS({
apiVersion: '2010-03-31',
region: 'ap-northeast-1'
})
sns.publish({
Message: event.body,
Subject: event.subject,
TopicArn: event.topic
}, function(err, data){
if ( err )
{
console.error ("*** end_sns_handler *** error ***")
context.fail('fail')
}
})
}
// ---------------------------------------------------------------
console.error ("*** 開始 ***")
const event = {
"topic": 'arn:aws:sns:ap-northeast-1:999999999999:test_sns',
"subject": "This is the subject of the message. Dec/08/2017",
"body": "This is the body of the message. Dec/08/2017 PM 13:29"
}
var context=""
send_sns_handler(event,context)
console.error ("*** 終了 ***")
// ---------------------------------------------------------------
python3 のサンプルはこちらです。
python で AWS の SNS にパブリッシュする