我对SNS和Lambda相当陌生。我已经成功创建了一个SNS主题,并且能够发送文本消息。上传文件时,我确实设置了S3事件。但是,我想更改该消息的文本,因此从应该向SNS主题发送消息的蓝图创建了Lambda函数。
这是我正在使用的蓝图代码:
from __future__ import print_function
import json
import urllib
import boto3
print('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.')
繁星点点滴滴
相关分类