Skip to content

Instantly share code, notes, and snippets.

@theiasapidecv
Created December 27, 2019 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theiasapidecv/acb160408ecbd71b5c8cc70a269295c8 to your computer and use it in GitHub Desktop.
Save theiasapidecv/acb160408ecbd71b5c8cc70a269295c8 to your computer and use it in GitHub Desktop.
from flask import Flask
from flask import request as req
app = Flask(__name__)
@app.route('/', methods = ['POST'])
def example():
try:
message = json.loads(req.data)
except:
pass
type = req.headers.get('X-Amz-Sns-Message-Type')
if type == 'SubscriptionConfirmation' and 'SubscribeURL' in message:
r = request.get(message['SubscribeURL'])
return 'OK', 200
elif type == 'Notification':
subject = message['Subject']
if subject == 'New Study':
print(json.loads(message['Message']))
return 'OK', 200
elif subject == 'New Interpretation':
print(json.loads(message['Message']))
return 'OK', 200
else:
return 'ERROR', 400
else:
return 'ERROR', 400
if __name__ == '__main__':
app.run(host = 'localhost')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment