0

How do I use Boto3 and Python to subscribe an AWS Lambda function to an AWS DynamoDB Stream?

Subscribing a Lambda function to a DynamoDB stream is straight-forward enough. However, it's not clear how to do this with code.

I need do it in code because I have to do it about 60 times.

Owen Brown
  • 179
  • 9

1 Answers1

2

You can use create_event_source_mapping from boto3

response = client.create_event_source_mapping(
    EventSourceArn=<your stream arn>
    FunctionName='name of function',
    Enabled=True|False,
    BatchSize=123,
    StartingPosition='TRIM_HORIZON'|'LATEST'|'AT_TIMESTAMP',
    StartingPositionTimestamp=datetime(2015, 1, 1)
)

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lambda.html#Lambda.Client.create_event_source_mapping

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.Lambda.Tutorial.html#Streams.Lambda.Tutorial.SNSTopic

sayboras
  • 4,897
  • 2
  • 22
  • 40