你打电话context.done()
后正在打电话publish()
.publish()函数是一个异步调用,您不会等待它完成.另外,我认为你的变量不pubResult
包含你期望的变量.
试试这个:
console.log('Loading function'); var aws = require('aws-sdk'); exports.handler = function(event, context) { var sns = new aws.SNS(); console.log('start of brians sns function') sns.publish({ Message: 'Test publish to SNS from Lambda', TopicArn: 'arn:aws:sns:us-east-1:xxxxxxxxxxxx:lambdatop' }, function(err, data) { if (err) { console.log(err.stack); // Notify Lambda that we are finished, but with errors context.done(err, 'Brians Function Finished with Errors!'); return; } console.log('push sent'); console.log(data); // Notify Lambda that we are finished context.done(null, 'Brians Function Finished!'); }); };