Created
December 16, 2014 07:23
-
-
Save a-hisame/b9785dcb6e421ff5a59f to your computer and use it in GitHub Desktop.
SNSへの通知を行うプログラム
This file contains hidden or 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
#!/usr/bin/env python | |
# coding: utf-8 | |
import uuid | |
import datetime | |
import boto.sns | |
# ----------------------- | |
# 設定によって変更するところ | |
# ----------------------- | |
REGION = 'ap-northeast-1' | |
AWS_ACCESS_KEY = '' | |
AWS_SECRET_ACCESS_KEY = '' | |
TOPIC_NAME = '' | |
# ----------------------- | |
def notify(subject, message): | |
conn = boto.sns.connect_to_region(REGION, | |
aws_access_key_id=AWS_ACCESS_KEY, | |
aws_secret_access_key=AWS_SECRET_ACCESS_KEY) | |
conn.publish(topic=TOPIC_NAME, message=message, subject=subject) | |
def main(id): | |
# 実行時刻をSNSに通知する | |
# SNSは登録先全てにpush通知を送る | |
message = 'My Name is Sender at {}'.format( | |
datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S')) | |
notify(id, message) | |
def _args_parser(): | |
''' コマンドラインからの入力解析を行うパーサを作成して返します。 ''' | |
import argparse | |
parser = argparse.ArgumentParser(description=u'Example Sender') | |
parser.add_argument('--id', type=str, help=u'Message ID', required=True) | |
return parser | |
if __name__ == '__main__': | |
import sys | |
args = _args_parser().parse_args(sys.argv[1:]) | |
main(args.id) | |
print 'ID: "{}" is published!'.format(args.id) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment