2

I'm using AWS DMS to migrate data from several sources into Redshift. For each replication task, I want to trigger a Lambda function when the full load finishes. Currently, I'm creating a separate AWS::Events::Rule for each DMS task like this:

EventPattern: !Sub |
 {
 "detail-type": ["DMS Replication Task State Change"],
 "source": ["aws.dms"],
 "account": ["${AWS::AccountId}"],
 "region": ["${AWS::Region}"],
 "resources": ["${DBToRedshiftPart1FullLoad}"],
 "detail": {
 "type": ["REPLICATION_TASK"],
 "category": ["StateChange"],
 "eventType": ["REPLICATION_TASK_STOPPED"],
 "eventId": ["DMS-EVENT-0079"]
 }
 }

But this becomes unmanageable as I have many replication tasks. Is there a way to define a single EventBridge rule that matches multiple (or all) DMS tasks and triggers a Lambda function with the ARN of the task that stopped passed in the event? I know I can have something like:

"resources": ["${DBToRedshiftPart1FullLoad}", "${DBToRedshiftPart2FullLoad}"]

But I don't know how to pass the ARN of the DMS task which exactly triggered this event to the Lambda. I want a single EventBridge rule that matches all my DMS tasks and passes the task ARN (i.e., the one that stopped) to the Lambda so it knows which task triggered it.

Ideally, I'd like to avoid duplicating rules for each task in CloudFormation. Is it possible to dynamically pass the triggering resource ARN in the event input or extract it from the event structure inside the Lambda?

Any suggestions or examples would be appreciated.

John Rotenstein
273k28 gold badges457 silver badges543 bronze badges
asked May 7, 2025 at 8:59
1
  • Yes, it is possible to extract the data from the event. Anything you can filter on is by definition part of the event your lambda gets invoked with. Commented May 7, 2025 at 9:31

1 Answer 1

2

Looks like this one did the job

DmsFullLoadTaskStoppedEventRule:
 Type: AWS::Events::Rule
 Properties:
 Name: DMSFullLoadTaskStoppedRule
 State: ENABLED
 Description: "Trigger Lambda after specific DMS full load tasks stop"
 Targets:
 - Arn: !GetAtt SomeLambdaFunction.Arn
 Id: "LambdaTarget"
 InputTransformer:
 InputPathsMap:
 taskArn: "$.resources[0]"
 InputTemplate: |
 {
 "phase": "DMS_FULL_LOAD_ENDED",
 "task_arn": "<taskArn>"
 }
 EventPattern: !Sub |
 {
 "detail-type": ["DMS Replication Task State Change"],
 "source": ["aws.dms"],
 "account": ["${AWS::AccountId}"],
 "region": ["${AWS::Region}"],
 "resources": ["${SomeDmsTask1}", "${SomeDmsTask2}"],
 "detail": {
 "type": ["REPLICATION_TASK"],
 "category": ["StateChange"],
 "eventType": ["REPLICATION_TASK_STOPPED"],
 "eventId": ["DMS-EVENT-0079"]
 }
 }
answered May 7, 2025 at 10:13
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.