Jabaa
Jabaa

Reputation: 1763

Send SMS with Amazon SNS in node js : Invalid parameter: PhoneNumber Reason: +XXXX is not valid to publish

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

Upvotes: 3

Views: 5821

Answers (4)

CY Lim
CY Lim

Reputation: 126

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.

Upvotes: 5

saigopi.me
saigopi.me

Reputation: 14938

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",
});

Upvotes: 1

user5398398
user5398398

Reputation: 121

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

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

Upvotes: 11

Avneesh
Avneesh

Reputation: 355

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

Upvotes: 2

Related Questions