我是一名有用的助手,可以进行文本翻译。
当测试Lambda函数时,我收到以下错误:
我不确定我理解出了什么问题,希望能得到帮助!谢谢!
我对SNS和Lambda还比较陌生。我已成功创建了一个SNS主题,并能够发送文本消息。我设置了一个S3事件,当上传文件时触发。但是,我想更改该消息的文本内容,因此从蓝图中创建了一个Lambda函数,该函数应该向SNS主题发送消息。
以下是设计师的截图
这是我正在使用的蓝图代码: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.')
当测试Lambda函数时,我收到以下错误:
Response:
{
"stackTrace": [
[
"/var/task/lambda_function.py",
25,
"send_to_sns",
"TopicArn=message['arn:aws:sns:MySNS_ARN'],"
]
],
"errorType": "KeyError",
"errorMessage": "'arn:aws:sns:MySNS_ARN'"
}
Request ID:
"7253aa4c-7635-11e8-b06b-838cbbafa9df"
Function Logs:
START RequestId: 7253aa4c-7635-11e8-b06b-838cbbafa9df Version: $LATEST
'arn:aws:sns:MySNS_ARN': KeyError
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 25, in send_to_sns
TopicArn=message['arn:aws:sns:MySNS_ARN'],
KeyError: 'arn:aws:sns:MySNS_ARN'
END RequestId: 7253aa4c-7635-11e8-b06b-838cbbafa9df
REPORT RequestId: 7253aa4c-7635-11e8-b06b-838cbbafa9df Duration: 550.00 ms Billed Duration: 600 ms Memory Size: 128 MB Max Memory Used: 30 MB
我不确定我理解出了什么问题,希望能得到帮助!谢谢!