I am fairly new to SNS and Lambda. I have successfully created a SNS topic and I am able to send a text message. I did set up an S3 event when a file was uploaded. However, I would like to change the text of that message and therefore created a Lambda function from a blueprint that is supposed to send a message to the SNS topic.
Here is a screenshot of the Designer
This is the blueprint code I am using:
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.')
When testing the Lamda function, I receive the following error:
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
I am not sure I understand what is going wrong and would appreciate the help! Thank you!