我对SNS和Lambda相当陌生。我已经成功创建了一个SNS主题,并且能够发送文本消息。上传文件时,我确实设置了S3事件。但是,我想更改该消息的文本,因此从应该向SNS主题发送消息的蓝图创建了Lambda函数。这是设计器的屏幕截图这是我正在使用的蓝图代码:from __future__ import print_functionimport jsonimport urllibimport boto3print('Loading message function...') def send_to_sns(message, context): # This function receives JSON input with three fields: the ARN of an SNS topic, # a string with the subject of the message, and a string with the body of the message. # The message is then sent to the SNS topic. # # Example: # { # "topic": "arn:aws:sns:REGION:123456789012:MySNSTopic", # "subject": "This is the subject of the message.", # "message": "This is the body of the message." # } sns = boto3.client('sns') sns.publish( TopicArn=message['arn:aws:sns:MySNS_ARN'], Subject=message['File upload'], Message=message['Files uploaded successfully'] ) return ('Sent a message to an Amazon SNS topic.')
2 回答

繁星点点滴滴
TA贡献1803条经验 获得超3个赞
我发现一个有效的NodeJs示例:
console.log('Loading function');
var AWS = require('aws-sdk');
AWS.config.region = 'us-east-1';
exports.handler = function(event, context) {
console.log("\n\nLoading handler\n\n");
var sns = new AWS.SNS();
sns.publish({
Message: 'File(s) uploaded successfully',
TopicArn: 'arn:aws:sns:_my_ARN'
}, function(err, data) {
if (err) {
console.log(err.stack);
return;
}
console.log('push sent');
console.log(data);
context.done(null, 'Function Finished!');
});
};
添加回答
举报
0/150
提交
取消