Created
February 1, 2018 20:23
-
-
Save manuthu/fa083350086871a0e6f26906a2d07649 to your computer and use it in GitHub Desktop.
How to receive a HTTP message from AWS SNS - https://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.html
This file contains 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
import logging | |
import json | |
from flask import Flask, current_app, jsonify | |
from flask import request | |
logging.basicConfig(level=logging.DEBUG) | |
app = Flask(__name__) | |
@app.route('/', methods=['POST', 'GET']) | |
def index(): | |
current_app.logger.info('Request Data %s', request.data) | |
json_data = json.loads(request.data) | |
c2b_alert = json.loads(json_data.get('Message')) | |
current_app.logger.info('c2b_alert Data %s', c2b_alert) | |
return jsonify(dict(success=True)) |
The POST HEADERS:
POST / HTTP/1.1
x-amz-sns-message-type: Notification
x-amz-sns-message-id: 22b80b92-fdea-4c2c-8f9d-bdfb0c7bf324
x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic
x-amz-sns-subscription-arn: arn:aws:sns:us-west-2:123456789012:MyTopic:c9135db0-26c4-47ec-8998-413945fb5a96
Content-Length: 773
Content-Type: text/plain; charset=UTF-8
Host: example.com
Connection: Keep-Alive
User-Agent: Amazon Simple Notification Service Agent
THE PAYLOAD
{
"Type" : "Notification",
"MessageId" : "7136bb1e-7f42-596c-9f04-e9f31159294b",
"TopicArn" : "arn:aws:sns:eu-central-1:619031000055:<>",
"Subject" : "C2BAlerts",
"Message" : "{\"@xmlns:ns1\": \"http://cps.huawei.com/cpsinterface/c2bpayment\", \"TransType\": \"Pay Bill\", \"TransID\": \"MB13IOIDE1\", \"TransTime\": \"20180201223450\", \"TransAmount\": \"10.00\", \"BusinessShortCode\": \"291222\", \"BillRefNumber\": \"testmike\", \"OrgAccountBalance\": \"8810.00\", \"MSISDN\": \"254705000001\", \"KYCInfo\": [{\"KYCName\": \"[Personal Details][First Name]\", \"KYCValue\": \"NAME\"}, {\"KYCName\": \"[Personal Details][Middle Name]\", \"KYCValue\": \"TEST\"}, {\"KYCName\": \"[Personal Details][Last Name]\", \"KYCValue\": \"TEST\"}]}",
"Timestamp" : "2018-02-01T19:34:51.738Z",
"SignatureVersion" : "1",
"Signature" : "E9FSoL7HM+yRkALKx4CJ61C9IiMEPX6GgCtCGqSKdVRBLt2HipouGr7Zs9kIHKCdth/jY1AtXEVi0g0i0/pityh204yHO+/tVrsmJCnJA38tO899cvucQbOVk/N5NcFsBIhprp/zXxgzgd2bUsnrIq8H8t4gwvLKRk3Ejx5yh7Q+MA3PW/YqkuPkFpFwp1h564NyatTn1MVPTmJ75bkP9ZbW3MLkIGFp5CGc7EZCp/veNwQRJkoc5nqqUXX9wVhZ1psIvrHvbmyJ1vwJsOid+2/o2eSI4YlcnyBW1QvBC5jTR4HsDaf3IO1ZF94FcnSxBpRD2pUrLFCFp3sRZ7b3ow==",
"SigningCertURL" : "https://sns.eu-central-1.amazonaws.com/SimpleNotificationService-433026a4050d206028891664da859041.pem",
"UnsubscribeURL" : "https://sns.eu-central-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-central-1:619031000055:mpesa-c2b-alerts-integ:7068cb0a-1ca0-440c-bf18-72d7647f0481"
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A sample response: