I am trying to update dynamodb and send SNS notification from Lambda function using the following code. Even though function execute successfully SNS notification does not happen. SNS log does not show any entry either. SNS from console to the same ARN works. Checked to update dynamodb that does not work either. Required IAM role policies for Dynamodb and SNS publish are created. Any pointers or way to debug will help.
'use strict';
console.log('Loading function');
var AWS = require("aws-sdk");
var sns = new AWS.SNS();
AWS.config.update({
region: "us-east-1"
});
var docClient = new AWS.DynamoDB.DocumentClient();
exports.handler = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
console.log('Received event: ', JSON.stringify(event, null, 2));
console.log('Received context: ', JSON.stringify(context, null, 2));
// console.log('Cognito id: ', context.identity.cognitoIdentityId);
+console.log("Start .................." + new Date().toString());+
console.log("Notifying....:");
sns.publish({
TargetArn: "arn:aws:sns:us-east-1:796915632304:endpoint/GCM/JaybMe/b65794ea-d30d-38a8-8450-e0ff3b877bfc",
Message: "Simple notification message "
}, function(err, data) {
if(err) {
console.error('error publishing to SNS');
context.callbackWaitsForEmptyEventLoop = false;
callback(err);
//context.fail(err);
} else {
console.info('Message published to SNS');
context.callbackWaitsForEmptyEventLoop = false;
callback(null, "SUCCESS");
}
});
console.log('Finished function');
context.callbackWaitsForEmptyEventLoop = false;
callback(null, "SUCCESS");
}
Tested with run time 4.3 and 6.10 but same behaviour
thanks Sajeev