Skip to content

Webhook for SNS SMS Deliveries

0

Hi AWS Community, I am new to AWS. I want to build a webhook which will be invoked on the SMS deliveries. This webhook will take the status of the SMS delivered and will into my AWS RDS database. I have deployed a lambda function which will act as webhook.

I want to know how my webhook will be invoked on SMS deliveries by SNS? I researched about it and got to know that I need to create a SNS topic but how will I configure the SNS to push messages to the topic after delivering the SMS?

2 Answers
0

Hi,

You can achieve what you want via CloudWatch.

This page explains how SNS SMS delivery can be logged in CW with messages: https://docs.aws.amazon.com/sns/latest/dg/sms_stats_cloudwatch.html

You get then such a message for each SMS:

{
    "notification": {
        "messageId": "34d9b400-c6dd-5444-820d-fbeb0f1f54cf",
        "timestamp": "2016-06-28 00:40:34.558"
    },
    "delivery": {
        "phoneCarrier": "My Phone Carrier",
        "mnc": 270,
        "numberOfMessageParts": 1,
        "destination": "+1nnn5550100",
        "priceInUSD": 0.00645,
        "smsType": "Transactional",
        "mcc": 310,
        "providerResponse": "Message has been accepted by phone carrier",
        "dwellTimeMs": 599,
        "dwellTimeMsUntilDeviceAck": 1344
    },
    "status": "SUCCESS"
}

You scan either schedule your Lambda via cron every few minutes and scan the CW log stream to report such messages in your RDS instance or be completely even-driven via CloudWatch Event rules (see https://medium.com/@oshara.16/trigger-aws-services-using-cloudwatch-part-1-trigger-a-lambda-function-9fd763ee7755) and have your Lambda triggered on each such message.

Best,

Didier

EXPERT
answered a year ago
  • Setting up with CW is costly. Is there any cheaper way to do it?

0

To set up a webhook that will be invoked on SMS deliveries by Amazon SNS and update your AWS RDS database, you'll need to follow these steps:

  1. Create an Amazon SNS topic: This topic will receive notifications about SMS delivery status.

  2. Subscribe your Lambda function to the SNS topic: Your Lambda function, which acts as the webhook, should be subscribed to the SNS topic you created. This way, it will be invoked whenever a message is published to the topic.

  3. Configure SNS to send delivery status notifications: You need to enable delivery status logging for your SNS topic. This is done by setting specific topic attributes.

Here's how to configure SNS to push messages to the topic after delivering the SMS:

  1. Enable delivery status logging for your SNS topic by setting the following attributes:

    • SMSSuccessFeedbackRoleArn: Set this to the ARN of an IAM role that allows SNS to write successful delivery logs to CloudWatch Logs.
    • SMSFailureFeedbackRoleArn: Set this to the ARN of an IAM role that allows SNS to write failed delivery logs to CloudWatch Logs.
    • SMSSuccessFeedbackSampleRate: Set this to a value between 0-100 to specify the percentage of successful SMS deliveries to log.
  2. When you send an SMS through SNS, include the MessageAttributes parameter with AWS.SNS.SMS.SMSType set to "Transactional" and AWS.SNS.SMS.MessageAttributes.DeliveryStatus set to "true".

  3. SNS will then publish delivery status messages to the specified topic, which will trigger your Lambda function.

  4. In your Lambda function, you can process the delivery status information and update your RDS database accordingly.

Remember to ensure that your Lambda function has the necessary permissions to write to your RDS database and that it's configured to run in the same VPC as your RDS instance if required.

This setup will allow you to receive SMS delivery status notifications via your webhook (Lambda function) and update your RDS database based on the delivery status.
Sources
Configuring delivery status logging using the AWS SDKs - Amazon Simple Notification Service
Using AWS Lambda with Amazon RDS - AWS Lambda
Invoking Lambda functions with Amazon SNS notifications - AWS Lambda

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.