- Newest
- Most votes
- Most comments
Yes, it's possible to create a single EventBridge rule that matches multiple or all AWS DMS tasks and triggers a Lambda function with the ARN of the specific task that stopped. Here's how you can achieve this:
- Create a more generic EventBridge rule that matches all DMS replication task state changes:
EventPattern: { "detail-type": ["DMS Replication Task State Change"], "source": ["aws.dms"], "detail": { "type": ["REPLICATION_TASK"], "category": ["StateChange"], "eventType": ["REPLICATION_TASK_STOPPED"], "eventId": ["DMS-EVENT-0079"] } }
This pattern will match any DMS replication task that stops after completing a full load, regardless of the specific task ARN.
- In your Lambda function, you can extract the specific task ARN from the event object. The event structure includes a 'resources' array that contains the ARN of the DMS task that triggered the event. You can access it like this in your Lambda function:
def lambda_handler(event, context): task_arn = event['resources'][0] # Your logic here using the task_arn
This approach allows you to have a single EventBridge rule that works for all your DMS tasks, and your Lambda function can determine which specific task triggered it by examining the event object.
By using this method, you avoid creating separate rules for each DMS task, making your CloudFormation template more manageable and scalable. The Lambda function will receive all the necessary information about the event, including the specific task that completed, allowing you to perform any required actions based on the task ARN.
Sources
Creating rules that react to events in Amazon EventBridge - Amazon EventBridge
Scenarios for EventBridge using AWS SDKs - Amazon EventBridge
Relevant content
- AWS OFFICIALUpdated 2 years ago