I write a tornado service as the Amazon SNS endpoint.
class TestHandler(tornado.web.RequestHandler):
def get(self):
logging.info('get')
self.sns()
self.write(self.request.body.decode('utf-8'))
def post(self):
logging.info('post')
self.sns()
self.write(self.request.body.decode('utf-8'))
def sns(self):
headers = self.request.headers
logging.info('HEADER: {}'.format(headers))
arn = headers.get('x-amz-sns-subscription-arn')
obj = json.loads(self.request.body)
if headers.get('x-amz-sns-message-type') == 'SubscriptionConfirmation':
logging.info('REQUEST: {}'.format(self.request))
subscribe_url = obj[u'SubscribeURL']
logging.info('URL:{}'.format(subscribe_url))
return '<Arn %r>' % arn
elif headers.get('x-amz-sns-message-type') == 'UnsubscribeConfirmation':
logging.info('Unsubscription')
elif headers.get('x-amz-sns-message-type') == 'Notification':
logging.info('Unsubscription')
return '', 200
But when I subscribe the endpoint to SNS, I didn't get any HTTP POST request. No logs was printed. So I tried to do curl
instead, and the logs shows it fine. I'm more convinced that SNS didn't send the request rather than my endpoint didn't receive it. I have no idea how to proceed. Please help. Thanks.