LoginSignup
1
4

More than 5 years have passed since last update.

python で AWS の SNS にパブリッシュする

Last updated at Posted at 2017-12-08

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 にパブリッシュする

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4