Day Break
Day Break

Reputation: 108

How do I configure a Lambda Trigger on SQS FIFO Queue in boto3?

I want to configure a Lambda trigger after creating or creating an SQS FIFO Queue with boto3.

I looked in the SQS boto3 document, but I couldn't find it. Can anyone help me?

Upvotes: 1

Views: 2314

Answers (1)

jarmod
jarmod

Reputation: 78563

Using boto3, you can add an event source mapping to the Lambda function, as follows:

import boto3

client = boto3.client('lambda', region_name='us-east-1')

response = client.create_event_source_mapping(
    EventSourceArn='arn:aws:sqs:us-east-1:999999999999:myfifo',
    FunctionName='my-lambda-function',
    Enabled=True,
    BatchSize=10
)

Change the SQS queue ARN and the Lambda function name to match yours.

Note that my example indicates BatchSize=10. This is important because it means that SQS may batch together multiple messages and send them to Lambda in a single invocation. Ordinarily this would only happen if a number of messages were sent to SQS at about the same time. Your Lambda function in this case would receive an array of event data. You can change this as needed.

Upvotes: 4

Related Questions