Boto3 Lambda - Existing custom IoT Rule as event source
We know and are able to set existing custom IoT Rule as a Trigger for AWS Lambda.
We are currently using boto3 to create lambda function.
After creating lambda function we tried to set an existing custom IoT Rule as trigger using create_event_source_mapping().
This is resulting in below error -
An error occurred (InvalidParameterValueException) when calling the CreateEventSourceMapping operation: Unrecognized event source, must be kinesis, dynamodb stream or sqs. Unsupported source arn : arn:aws:iot:xx-xx-1:xxxxxxxxxxxx:rule/ruleName
Please find the code for the same below -
import boto3 import botocore.exceptions function_name = sample_function trigger_arn = arn:aws:iot:xx-xx-1:xxxxxxxxxxxx:rule/ruleName client = boto3.client('lambda') client.create_event_source_mapping(EventSourceArn=trigger_arn,FunctionName=function_name)
Is this not supported or possible using boto3?
How to fix this?
Lambda event source mapping is used only for the event sources that Lambda needs to poll such as SQS, Kinesis, Kafka, etc. IoT Rules are different. In order to trigger a Lambda function from an IoT rule you need to use the create_topic_rule in the IoT client.
Hi Uri, Thank you for the response. Yes I checked that earlier and I knew that I can use create_topic_rule to create new rule and set an action to trigger lambda. But I don't think I could use create_topic_rule to set an action to trigger lambda for an already created rule. Could you please point out which API I should use for the same? (I am expecting that I just have to pass the ARN of the existing rule and ARN of the lambda)
Can't create a topic rule that includes a lambda actionasked 3 years ago
Cant trigger a rule for a job execution update (UpdateJobExecution)
AWS IoT Core Rule Action to Timestream DBasked 2 years ago
Boto3 Lambda - Existing custom IoT Rule as event sourceasked 4 months ago
How to pass SQS attributes when IOT rule is triggered?asked 2 years ago
How to get the enable / disable of the trigger set in lambda with boto3.asked 2 years ago
Cloudwatch Rule Failed Invocationasked 5 years ago
Get output of a Lambda function back to IoT Core MQTT brokerAccepted Answerasked 7 months ago
Trigger a lambda function based on thing type
boto3 1.9.212 not able to create channel ChannelClass not setting upasked 3 years ago