首先,你需要批准你的 Lambda IAM role 发布到您的权限 SNS topic 使用得当 IAM policy 。
Lambda IAM role
SNS topic
IAM policy
{ "Action" : [ "sns:Publish", "sns:Subscribe" ], "Effect" : "Allow", "Resource" : [ { "Ref" : "<your SNS topic ARN>" } ] }
然后你可以使用以下代码 SNS publish 到你的 SNS topic 从你的另一个 Lambda 要么 Node.js 码。
SNS publish
Lambda
Node.js
var message = {}; var sns = new AWS.SNS(); sns.publish({ TopicArn: "<your SNS topic ARN>", Message: JSON.stringify(message) }, function(err, data) { if(err) { console.error('error publishing to SNS'); context.fail(err); } else { console.info('message published to SNS'); context.succeed(null, data); } });