user2013 user2013 - 1 month ago 24
Node.js Question

basic application of AWS SNS

I want to build a basic Hello, World! application using

AWS SNS
and
node.js
, I have written some very basic code and it's not working. My Code is given below:

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

// aws configuration
var awsConfig = {
'region': 'us-east-1'
};

if (process.env.AWS_ACCESS_KEY != undefined && process.env.AWS_ACCESS_KEY != null) {
awsConfig.accessKeyId = process.env.AWS_ACCESS_KEY;
}

if (process.env.AWS_SECRET_ACCESS_KEY != undefined && process.env.AWS_SECRET_ACCESS_KEY != null) {
awsConfig.secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
}

var sns = new AWS.SNS(awsConfig).client;

console.log("sns : ", sns); // here sns value is 'undefined'

sns.createTopic({ // "TypeError: Cannot read property 'createTopic' of undefined"
'Name': 'sent-email'
}, function (err, result) {

console.log("some msg expecting........");
if (err !== null) {
console.log(util.inspect(err));
return;
}

console.log(util.inspect(result));

});


Any help is appreciated, Thanks in advance.

Answer

SNS.client is undefined. Check the documentation. You should just be doing this:

var sns = new AWS.SNS(awsConfig);
Comments