How To Receive Messages Using AWS Pinpoint

Dilip Kola
Tensult Blogs
Published in
4 min readOct 9, 2019

This Blog has moved from Medium to blogs.tensult.com. All the latest content will be available there. Subscribe to our newsletter to stay updated.

Ref: https://bit.ly/2VpnLnz

Banking mobile apps in India are required to support verification of mobile number using SMS as per RBI guidelines. When the user downloads the app and opens it for the first time, the app will generate a unique verification token, which should be sent to a designated mobile number via SMS. Then the bank processes the received SMS and verifies the user mobile number and associates the app to the user’s bank account.

AWS Pinpoint provides a two-way SMS feature using which it can receive SMSs and pass the message to an API for further processing. Let us see this in more detail now.

Prerequisites

  • Long code: In order to receive SMS using Pinpoint, we need to request a long code using AWS support.

Note: Two-way SMS is not supported for all countries so please check here before you start. Also the Long code registration depends on the telecom providers so it can take upto 3–4 weeks.

Architecture

Steps

  1. Request Long code using AWS support case.
Create Sevice Limit increase request for Pinpoint SMS
Request for Long code

Provide necessary details to AWS so that they can register a dedicated long code for you.

2. Create a Lambda function to process messages from an SNS topic in the following format and send it to the verification API.

{
"Records": [
{
"EventSource": "aws:sns",
"EventVersion": "1.0",
"EventSubscriptionArn": "arn:aws:sns:ap-south-1:123456789012:pinpoint-test:12345678-abcd-abcd-abcd-12345678abcd",
"Sns": {
"Type": "Notification",
"MessageId": "12345678-abcd-abcd-abcd-12345678abcd",
"TopicArn": "arn:aws:sns:ap-south-1:557970867295:pinpoint-test",
"Subject": null,
"Message": "{\"originationNumber\":\"+911234567890\",\"destinationNumber\":\"+911234567891\",\"messageKeyword\":\"tensult\",\"messageBody\":\"Hello world from Tensult\",\"inboundMessageId\":\"12345678-abcd-abcd-abcd-12345678abcd\",\"previousPublishedMessageId\":\"null\"}",
"Timestamp": "2019-09-24T12:30:45.219Z",
"SignatureVersion": "1",
"Signature": "abcdefHT2hbeMOHZBlKSamOfHoW8zw8FUTabcdefFhHcBdZx40n5J/lTOT5WsvCjzuy4d3t2F2Pf4LOs9IGKvTuaRNNrtN/Y7q0qENPOGzZ6RfabcdefT0Dfe5UBz1fvu3a/rVMO0FNuQHLYRAkc/abcdef0DcXz4uyNVmVBQGZ4+z2rQaflkFQpZwJLa2z1cFXjKmhzOls5YQfR+abcdef8ofvEhWbFtSabcdeftM/dXjQrFqFwNFGZss5qPuTT1qKYZyaBzgLzN4Gqrf4y3OY6M7dbV/abcdef",
"SigningCertUrl": "https://sns.ap-south-1.amazonaws.com/SimpleNotificationService-6aad65c2f9911b05cd53ef.pem",
"UnsubscribeUrl": "https://sns.ap-south-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:ap-south-1:123456789012:pinpoint-12345678-abcd-abcd-abcd-12345678abcd",
"MessageAttributes": {}
}
}
]
}

3. Create an SNS topic and add the above Lambda function as a subscription.

4. Once long code is available, Create a Pinpoint Project and configure to receive SMSs.

Create a Pinpoint project

You will be able to see the register long code from Project’s Settings -> SMS and Voice

Registered Long code and settings

To enable the SMS channel for the PinPoint project, click on Edit.

To enable Two-way SMS, click on the Phone Number (Long code)

Keywords in Pinpoint are used for automatic responses and we need at least one to get started.

SMS Settings for the Long code

Enable two way SMS for the long code.

Enable two-way SMS and select SNS topic to forward the message

5. Test the long code by sending a sample SMS from your mobile phone.

Conclusion

You have learned how to use Amazon Pinpoint two-way SMS feature to receive SMSs and also how to use that for verifying the phone number for the banking use case. I hope you have learned something new today, cheers.

--

--

Dilip Kola
Tensult Blogs

Spirtual Seeker | Mentor | Learner | Ex-Amazon | Ex-AWS | IIT Kanpur