Reputation: 3351
I'm writing a program that sends SMS using the AWS SNS service. I am new to this topic. So I've tried one of the codes available online.
and the code is as below.
var AWS = require('aws-sdk');
AWS.config.region = 'your aws region';
AWS.config.update({
accessKeyId: "your access id",
secretAccessKey: "your secret access key",
});
var sns = new AWS.SNS();
var params = {
Message: "your message",
MessageStructure: 'string',
PhoneNumber: 'phone_number_without_+',
Subject: 'your subject'
};
sns.publish(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Here I've filled the entire data from my AWS console like Region
, accessKey
and secretAccessKey
, my mobile number
, Subject
and message
. post filling this when I try to run this, I get the below response.
{ ResponseMetadata: { RequestId: '30d54840-1aa8-5ad4-8de7-19cad1ed033f' },
MessageId: '7cc1d99e-b835-5015-b84e-88147370a9fe' }
but there is no sms delivered to my mobile.
I thought that the service is not available in my country and then tried sending the message from SMS console shown below. I received a text message on my mobile.
Here I'm not using any topic
and I need to send message individually, there is no bulk message to be sent.
Please guide me on where am I going wrong and how can I fix this.
Thanks
Update
Thanks for the quick test balent.
This thing is working, the saddest part is that the message is delivered after 9 hrs. I'm in India and our code starts something like this +91XXXXXXXXXX
and I did the same. But when tried through the console(SMS screenshot), the message was instant, can someone please shower some light on how this can be fixed. i.e. the sms to be sent instantly.
Upvotes: 4
Views: 2559
Reputation: 88
Thank you for your question and updated answer, to reduce time of delivery in India, setting the attribute DefaultSMSType to "Transactional" delivered it immediately.
sns.setSMSAttributes(
{
attributes : {
DefaultSMSType : "Transactional"
}
},
function(error){
if(error){
console.log(error);
}
}
);
Explanation- there are two types one is promotional which is default, and not time critical and one is transactional, time critical used for otp. There is a price difference I suppose in using either of the options. Upon reading your answer I tried the way you did and the sms were delayed, so I used the api given here to change to transactional and it gave instant messages.
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#publish-property
Upvotes: 5