I want to create an AWS Lambda trigger to process a stream from an Amazon DynamoDB global table.
A DynamoDB global table is a collection of replicas across Regions in a single account. Global tables use DynamoDB Streams to replicate data across different Regions. When you create a replica for a global table, a stream is created by default. Any changes to a replica are replicated to all the other replicas within the same global table within a second using DynamoDB Streams.
Note: Having a single consumer on any of the global table replicas in any one Region is enough to retrieve the modification records for all items.
You can configure an AWS Lambda trigger to process a stream from a global table replica by doing the following:
- Be sure that AWSLambdaDynamoDBExecutionRole has the necessary AWS Identity and Access Management (IAM) permissions.
Note: The AWSLambdaDynamoDBExecutionRole IAM policy doesn't have permissions for Lambda to communicate with other services, such as Amazon Simple Notification Service (Amazon SNS), by default. This means that you must add the required additional permissions based on the Lambda target.
- Create a Lambda function using the blueprint dynamodb-process-stream. You can modify the Lambda code according to your requirement to process the stream data.
- After creating the Lambda function successfully, open the DynamoDB console, and select the global table replica. In the Exports and streams tab, choose Create trigger. Then, select the Lambda function that you created in the previous step. Be sure to select Enable trigger so that the trigger is activated after it's created.
The Lambda function is now configured as a trigger for your global table replica. Any changes to the replica are captured by the stream, and the trigger is invoked.
DynamoDB Streams and AWS Lambda triggers