python3 で、AWS の SNS にパブリッシュ(投稿)する方法です。
Arch Linux と Raspbian で動作を確認しました。
topic は変更して下さい。
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
# sns_test.py
#
# Dec/08/2017
#
# --------------------------------------------------------------------
import sys
import json
import urllib
import boto3
# --------------------------------------------------------------------
def send_to_sns(event, context):
sns = boto3.client('sns')
sns.publish(
TopicArn=event['topic'],
Subject=event['subject'],
Message=event['body']
)
return ('Sent a message to an Amazon SNS topic.')
#
# --------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
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:01"
}
context = ""
rvalue = send_to_sns(event, context)
print(rvalue)
#
sys.stderr.write("*** 終了 ***\n")
# --------------------------------------------------------------------
Node.js のサンプルはこちらです。
Node.js で AWS の SNS にパブリッシュする