I'm currently using peerlibrary:aws-sdk to interface with a few Amazon services. I'm now looking to send SMS messages to phone numbers using this same SDK wrapper.
What I'm trying to figure out are the API call sequences involved. This is the link to the SDK, but I have yet to find a comprehensive guide.
I know how to make these API calls, what I'm finding is you must call a few to get it right. Also, I only want to send SMS to Phones, not emails.
I've tested via the AWS console. I can create a Topic, and Subscribe to that Topic with the SMS Protocol. I can send SMS messages to a Phone number this way. But the API calls to Subscribe a Phone number to the existing Topic I created, and then so Publish to that Topic are a little confusing.
Has anyone sent messages via SNS and peerlibrary:aws-sdk's SDK wrapper and what are the API calls to make this happen?
So far as I can make out via the API docs, I need to do the following AFTER I've manually created a Topic in AWS SNS:
1) Subscribe a Phone Number to a Topic (must have ARN# for Topic):
sns.subscribe(params, function(err, data) {...});
1a) User must accept Subscription from their Phone.
2) Publish a SMS Message:
sns.publish(params, function(err, data) {...});
3) The User can unsubscribe anytime from their Phone.
But is this it?
I already have code that sets the Keys, do I need to do this for me to call the sub/pub APIs?
AWS.config.update({
accessKeyId: Meteor.settings.awsAccessKeyId,
secretAccessKey: Meteor.settings.awsSecretKey
});
UPDATE 1:
I got the following code set up
broadcaseSms: function () {
AWS.config.update({
accessKeyId: Meteor.settings.awsAccessKeyId,
secretAccessKey: Meteor.settings.awsSecretKey,
region: "us-east-1"
});
var sns = new AWS.SNS();
var params = {
Message: 'test 5', /* required */
MessageAttributes: {
someKey: {
DataType: String//, /* required */
// BinaryValue: new Buffer('...') || 'STRING_VALUE',
// StringValue: 'STRING_VALUE'
},
/* anotherKey: ... */
},
// MessageStructure: 'STRING_VALUE',
// Subject: 'STRING_VALUE',
// TargetArn: 'STRING_VALUE',
TopicArn: 'arn:aws:sns:us-east-1:34523452345:test'
};
sns.publish(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
But get an exception:
'InvalidParameterType: Expected params.MessageAttributes[\'someKey\'].DataType to be a string\n
I get the impression attribute, 'someKey' is wrong, and should an actual key...
UPDATE 2:
I got it working like this
AWS.config.update({
accessKeyId: Meteor.settings.awsAccessKeyId,
secretAccessKey: Meteor.settings.awsSecretKey,
region: "us-east-1"
});
var sns = new AWS.SNS({params: {TopicArn: 'arn:aws:sns:us-east-1:2353452345:test'}});
sns.publish({Message: 'THE MESSAGE TO PUBLISH'}, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});