Skip to content

How do I receive notifications when a DataSync task execution succeeds or fails?

4 minute read
1

I want to know when my AWS DataSync task execution succeeds or fails.

Resolution

Configure Amazon Simple Notification Service (Amazon SNS) and Amazon EventBridge to send you email notifications when a DataSync task execution status changes to SUCCESS or ERROR. 

Prerequisite: You must create a DataSync task.

Create an Amazon SNS topic and subscribe your email to the topic

Complete the following steps:

  1. Open the Amazon SNS console.
  2. In the navigation pane, choose Topics.
  3. Choose Create topic.
  4. For Name, enter a name for this topic.
  5. Choose Create topic.
  6. On the page of your topic, choose the Subscriptions tab.
  7. Choose Create subscription.
  8. On the Create subscription page, take the following actions:
    For Protocol, choose Email.
    For Endpoint, enter the email address where you want to receive notifications.
  9. Choose Create subscription.
  10. In the subscription confirmation message that you receive, choose the Confirm subscription link.

Create an EventBridge rule for DataSync and set the SNS topic as the target

Complete the following steps:

  1. Open the EventBridge console.

  2. In the navigation pane, choose Rules.

  3. Choose Create rule.

  4. Enter a Name and description for the rule.

  5. For Build event pattern, choose AWS events or EventBridge partner events under the Events section.

  6. Under Event pattern, choose Use Pattern form.

  7. For Event source, choose AWS services.

  8. For AWS service, choose DataSync.

  9. For Event type, choose DataSync Task Execution State Change.

  10. Under Event pattern, enter the following JSON to get notifications for all task executions that are in the SUCCESS or ERROR status:

    {  
      "source": [  
        "aws.datasync"  
      ],  
      "detail-type": [  
        "DataSync Task Execution State Change"  
      ],  
      "detail": {  
        "State": [  
          "SUCCESS",  
          "ERROR"  
        ]  
      }  
    }
  11. Under Select Targets, take the following actions:
    For Target, choose SNS topic.
    For Topic, select the topic that you created.

  12. Choose Create.

Start a DataSync task to test email notifications

To test email notifications for DataSync task execution statuses, first create a task, and then start the task.

After you start the task, you get an email notification about the status of the DataSync task execution. For a task execution that succeeds, you receive a SUCCESS notification message that's similar to the following:

{  
    "version": "0",  
    "id": "example0-c014-d9e9-d7ac-44f00d5d1200",  
    "detail-type": "DataSync Task Execution State Change",  
    "source": "aws.datasync",  
    "account": "111122223333",  
    "time": "2019-01-23T12:35:26Z",  
    "region": "us-west-2",  
    "resources": ["arn:aws:sync:us-west-2:911112222333:task/task-example23d67d5be5/execution/exec-example316440271f"],  
    "detail": {  
        "State": "SUCCESS"  
    }  
}

Receive notifications for only one DataSync task

To get notifications for only one DataSync task, use EventBridge comparison operators to search for partial matches of the task's ARN.

For example, specify the task's ARN as the value of the prefix parameter in the following JSON:

{  
  "detail-type": ["DataSync Task Execution State Change"],  
  "source": ["aws.datasync"],  
  "resources": [{  
    "prefix": "arn:aws:datasync:REGION:ACCOUNT-ID:task/TASK-ID/execution/exec-"  
  }],  
  "detail": {  
    "State": ["SUCCESS", "ERROR"]  
  }  
}

Receive notifications for multiple DataSync tasks

Use the prefix parameter

To get notifications for multiple tasks, you can include a prefix parameter for each task. For example, the following JSON activates notifications for two tasks:

{  
  "source": ["aws.datasync"],  
  "detail-type": ["DataSync Task Execution State Change"],  
  "resources": [{  
    "prefix": "arn:aws:datasync:REGION:ACCOUNT-ID:task/TASK1-ID/execution/exec-"  
  }, {  
    "prefix": "arn:aws:datasync:REGION:ACCOUNT-ID:task/TASK2-ID/execution/exec-"  
  }],  
  "detail": {  
    "State": ["SUCCESS", "ERROR"]  
  }  
}

Note: Replace REGION with your AWS Region and ACCOUNT-ID with your AWS account ID. Also, replace TASK1-ID and TASK2-ID with the IDs of your tasks.

Use the wildcard parameter

You can also use the wildcard parameter to get notifications for specific tasks. For example, the following JSON activates notifications for all tasks that have the specified ARN prefix before the * character:

{  
  "detail-type": ["DataSync Task Execution State Change"],  
  "source": ["aws.datasync"],  
  "resources": [{  
    "wildcard": "arn:aws:datasync:REGION:ACCOUNT-ID:task/TASK-ID/execution/exec-*"  
  }],  
  "detail": {  
    "State": ["SUCCESS", "ERROR"]  
  }  
}

Note: Replace REGION with your Region, ACCOUNT-ID with your account ID, and TASK-ID with your task's ID.

To get notifications only for couple of tasks, use the following JSON:

{  
  "detail-type": ["DataSync Task Execution State Change"],  
  "source": ["aws.datasync"],  
  "resources": [{  
    "wildcard": "*/TASK1-ID/execution/exec-*"  
  }, {  
    "wildcard": "*/TASK2-ID/execution/exec-*"  
  }],  
  "detail": {  
    "State": ["SUCCESS", "ERROR"]  
  }  
}

Note: Replace TASK1-ID and TASK2-ID with the IDs of your tasks.

Related information

Monitoring events by using Amazon EventBridge

Creating rules that react to events in Amazon EventBridge

AWS OFFICIALUpdated a year ago