1.创建Lambda
在Lambda中,创建名为AWSSNSDemo的函数
'use strict'
console.log('loading function');
var aws = require('aws-sdk');
var docClient = new aws.DynamoDB.DocumentClient();
aws.config.region='ap-southeast-1';exports.handler = function(event,context,callback){console.log("AWS China Lambda and SNS Notification");const message = event.Records[0].Sns.Message;console.log("From SNS:",message);var params={Item:{date:Date.now(),message:message},TableName:'Lambda-Dynamo-Write-Read-China'};docClient.put(params,function(err,data){if(err){console.log("Fail to Write into AWS DynamoDB");callback(err,null);}else{console.log("Successfully write item into AWS DynamoDB");callback(null,data);}});
}
2.创建SNS
创建名为:SNSTopicTest的主题
3.创建Lambda触发器
4.在SNS发布消息
发布消息后,在DynamoDB中,如果检测到发布的消息数据,则说明集成成功。