3
votes

Here is my code for sending SMS to a particular number with AWS sms service.

var AWS = require('aws-sdk');

        AWS.config.update({
            accessKeyId: '{ID}',
            secretAccessKey: '{KEY}',
            region: 'us-east-2'
        });
        var sns = new AWS.SNS();

        var params = {
            Message: 'this is a test message',
            MessageStructure: 'text',
            PhoneNumber: '+XXXXXXXX'
        };

        sns.publish(params, function(err, data) {
            if (err) console.log(err, err.stack); // an error occurred
            else     console.log(data);           // successful response
        });

But i got the following error in console

'InvalidParameter: Invalid parameter: PhoneNumber Reason: +XXXXXX is not valid to publish

4
Did you use real phone number or +XXXXXX? If real, can you show the format? I mean something like +123456789012 - Molda
yes i am using real phone number here is the format +91XXXXX ,91 is the country code - Jabaa
You can test sending a message to the phone number by using the AWS Command-Line Interface (CLI). Try this: aws sns publish --phone-number +91XXXX --message "published" - John Rotenstein
But i need apis - Jabaa
@Jabaa we understand that, but to restate the obvious, the point is that this is a troubleshooting step: you can use this test the number this way to determine whether the problem is (a) the number or (b) your code. If the error is the same the problem is the number. If the error is different, or no errors occur, the problem is in your code. - Michael - sqlbot

4 Answers

10
votes

Please try with setting the region to "us-east-1". It worked for me before.

var sns = new AWS.SNS({ "region": "us-east-1" });
5
votes

It is a bit misleading to ask everyone to change the region to us-east-1.

All the supported region are listed in the following link: https://docs.aws.amazon.com/sns/latest/dg/sms_supported-countries.html

P.S. I am new user, I can't add comments or edit anyone posts to include the supported list.

2
votes

SNS currently supports SMS only in the form of E.164 formats, please make sure you are using the same format.

Check it out here: https://en.wikipedia.org/wiki/E.164

Additionally, you are using SNS sms service in us-east-2, which does not support SMS delivery as of yet. Checkout the SMS enabled regions: http://docs.aws.amazon.com/sns/latest/dg/sms_supported-countries.html

1
votes

change your region us-east-2 to us-east-1 it worked for me

var sns = new aws.SNS({
    "accessKeyId": functions.config().aws.key,
    "secretAccessKey": functions.config().aws.secret,
    "region": "us-east-1",
});