Brian
Brian

Reputation: 13571

How to send a message to SNS topic through the test event of an AWS lambda function?

I have an AWS lambda function that triggers an SNS topic on failure.

enter image description here

I'm wondering why the SNS topic is not triggered why I run "Test" in the AWS console.

enter image description here

As you can see in the above picture, the python lambda function raises an error at line 4.

I've subscribed to the SNS topic with my e-mail address. And I have clicked the "Confirm subscription" link. So there should be no problem receiving messages from the SNS topic.

I've also confirmed that the role of my AWS lambda function has "AmazonSNSFullAccess" permission.

Why can't I trigger SNS topic through the "Test" in AWS lambda function?

Upvotes: 0

Views: 1061

Answers (1)

Brian
Brian

Reputation: 13571

Thanks to pyzor's information, I use the following python script to asynchronously trigger my AWS lambda function so that it can send messages to SNS topic.

import boto3

client = boto3.client('lambda')
response = client.invoke(
    FunctionName='my-function',
    InvocationType='Event'
)
print(f"response: {response}")

Upvotes: 1

Related Questions