How do I automate the AWS DMS error log deletion process to avoid the storage-full state on my replication instance?

4 minute read

I want to automate the AWS Database Migration Service (AWS DMS) error log deletion process to delete more frequently.

Short description

If your AWS DMS error logs take a lot of space in your DMS replication instance, then the replication instance might go into the storage-full state. To resolve this issue, delete the DMS task error logs for your DMS tasks.

To delete the error log for your AWS DMS task, use one of the following methods:

  • AWS DMS console
  • AWS Command Line Interface (AWS CLI)
  • API 
  • Lambda scheduler

Note: There are several reasons that can cause the storage-full state to occur. For more information, see Why is my AWS DMS replication DB instance in the storage-full status?


Note: If you receive errors when you run AWS CLI commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.

Use the AWS DMS console

To manually delete your DMS task error logs, see How do I turn on, access, or delete CloudWatch logs for AWS DMS?

Use the AWS CLI

To use the AWS CLI to modify your task settings and delete your DMS task logs, run the modify-replication-task command:

aws dms modify-replication-task --replication-task-arn <DMS task ARN> --replication-task-settings '{"Logging": { "DeleteTaskLogs": true}}'

This command changes the "DeleteTaskLogs": true parameter to modify the task. After you add the task setting with this parameter, all logs for the task are deleted from the replication instance. After the logs are deleted, the task settings remove the "DeleteTaskLogs": true parameter. After you run this command, confirm that the logs are deleted from the replication instance.

To periodically delete the logs, use the "DeleteTaskLogs": true parameter to modify the task setting. You can use cron job to schedule modify-replication-task to run periodically.

Use the API

To automatically delete AWS DMS task logs, create a script to run every day, or at the frequency that you want. The following example uses AWS Lambda and Python code to automate the task error log deletion for the provided task ARN.

Set up the Lambda function

To set up the Lambda function, complete the following steps:

1.    Open the Lambda console, and then choose the AWS Region that contains your DMS resources.

2.    On the Functions panel, choose Create function.

3.    Enter a Function name.

4.    For Runtime, choose python 3.8.

5.    For Change default execution role, choose Create a new role with basic Lambda permissions. Note the AWS Identity and Access Management (IAM) role name that Lambda creates.

6.    Choose Create function.

7.    Open the AWS IAM console, and then open the IAM role that the Lambda function created.

8.    To create an IAM policy, use the following JSON. Replace the example task ARN with your task ARN:

{    "Version": "2012-10-17",
    "Statement": [
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
            "Resource": "arn:aws:dms:us-east-1:1234567890:task:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

9.    Attach the policy to the role that the Lambda function created.

10.    Open the Lambda console, and then choose the Lambda function that you created.

11.    For Function code, enter the following code, and then choose Deploy:

import boto3import json
client = boto3.client('dms')
def lambda_handler(event, context):
    # specific task ARN
    taskarn = 'arn:aws:dms:us-east-1:1234567890:task:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
    # modify the DMS task
    response = client.modify_replication_task(
        ReplicationTaskSettings='{"Logging": { "DeleteTaskLogs": true}}'

12.    Choose Test, and then enter Event name with the default template.

13.    Choose Create, and then choose Test again.

The DMS task status changes to Modifying. At the same time, the DMS task error logs under the replication instance are deleted.

Use the Lambda scheduler

To use the Lambda scheduler to automate DMS task error logs, complete the following steps:

  1. Open the Lambda console, and then choose the Lambda function that you created.
  2. For Designer, choose Add trigger.
  3. From the dropdown list, choose EventBridge (Cloudwatch Events).
  4. For Rule, choose Create a new rule.
  5. Enter Rule name and Rule description.
  6. For Schedule expression, enter the rate expression. For more information, see Schedule expressions using rate or cron.
  7. Choose Add.

Note: You can change and optimize this code. You can also use cron job or the Lambda scheduler to schedule this script to periodically run.

AWS OFFICIALUpdated 6 months ago