-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsns-subscriber.py
48 lines (36 loc) · 1.14 KB
/
sns-subscriber.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
import logging
import boto.sns
from flask import Flask
from flask import request
from flask import render_template
# Logic Steps:
l = logging.basicConfig(filename='sns-sub.log', level=logging.DEBUG)
logger = logging.getLogger(l)
topicarn = "Your ARN Here"
app = Flask(__name__)
@app.route('/')
def sns_subscribe():
return render_template('sns-subscribe-form.html')
@app.route('/', methods=['POST'])
def sns_subscribe_post():
text = request.form['text']
c = boto.sns.connect_to_region("us-east-1")
if '@' in text:
subscription = c.subscribe(topicarn, 'email', text)
# print subscription
response = 'Email subscription sent to: ' + \
str(text) + str(subscription)
# print response
logger.info(response)
return response
else:
subscription = c.subscribe(topicarn, 'sms', text)
# print subscription
response = 'Mobile SMS subscription sent to: ' + \
str(text) + str(subscription)
# print response
logger.info(response)
return response
if __name__ == '__main__':
app.run(host="0.0.0.0", debug=True)