Search code examples
amazon-s3aws-lambdaamazon-dynamodbboto3

How to use DynamoDB export_table_to_point_in_time boto3?


I got error when trying to use IncrementalExport which fail the validation for "ExportType" and "IncrementalExportSpecification". I'm using the latest boto3 1.28.79. I follow the documentation here

client.export_table_to_point_in_time(
            TableArn=table_arn,
            S3Bucket=s3_bucket_name,
            ExportFormat='DYNAMODB_JSON',
            ExportType='INCREMENTAL_EXPORT',
            IncrementalExportSpecification={
                'ExportFromTime': datetime.today(),
                'ExportToTime': datetime.today() - timedelta(days=1),
                'ExportViewType': 'NEW_IMAGE'
            }
        )

Error:

{
  "errorMessage": "Parameter validation failed:\nUnknown parameter in input: \"ExportType\", must be one of: TableArn, ExportTime, ClientToken, S3Bucket, S3BucketOwner, S3Prefix, S3SseAlgorithm, S3SseKmsKeyId, ExportFormat\nUnknown parameter in input: \"IncrementalExportSpecification\", must be one of: TableArn, ExportTime, ClientToken, S3Bucket, S3BucketOwner, S3Prefix, S3SseAlgorithm, S3SseKmsKeyId, ExportFormat",
  "errorType": "ParamValidationError",
  "requestId": "e0edeed9-d68d-4f8c-ae4f-030e05248061",
  "stackTrace": [
    "  File \"/opt/python/lib/python3.9/site-packages/datadog_lambda/wrapper.py\", line 214, in __call__\n    self.response = self.func(event, context, **kwargs)\n",
    "  File \"/var/task/src/eda_transaction_export_handler.py\", line 15, in handle\n    def handle(events, context):\n",
    "  File \"/opt/python/lib/python3.9/site-packages/ddtrace/contrib/aws_lambda/patch.py\", line 120, in __call__\n    self.response = self.func(*args, **kwargs)\n",
    "  File \"/var/task/src/eda_transaction_export_handler.py\", line 16, in handle\n    client.export_table_to_point_in_time(\n",
    "  File \"/var/runtime/botocore/client.py\", line 530, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n",
    "  File \"/opt/python/lib/python3.9/site-packages/ddtrace/contrib/botocore/patch.py\", line 680, in patched_api_call\n    result = original_func(*args, **kwargs)\n",
    "  File \"/var/runtime/botocore/client.py\", line 919, in _make_api_call\n    request_dict = self._convert_to_request_dict(\n",
    "  File \"/var/runtime/botocore/client.py\", line 990, in _convert_to_request_dict\n    request_dict = self._serializer.serialize_to_request(\n",
    "  File \"/var/runtime/botocore/validate.py\", line 381, in serialize_to_request\n    raise ParamValidationError(report=report.generate_report())\n"
  ]
}

Solution

  • Using the latest version of boto3==1.28.79, botocore==1.31.79. I was able to export the data with no issue:

    import boto3
    from datetime import datetime
    from datetime import timedelta
    
    dynamodb = boto3.client('dynamodb')
    table_arn = 'arn:aws:dynamodb:eu-west-1:<account-id>:table/<my-table>'
    s3_bucket_name = 'my-bucket'
    from_time = datetime.today() - timedelta(days=1)
    to_time = datetime.today()
    try:
        dynamodb.export_table_to_point_in_time(
                    TableArn=table_arn,
                    S3Bucket=s3_bucket_name,
                    ExportFormat='DYNAMODB_JSON',
                    ExportType='INCREMENTAL_EXPORT',
                    IncrementalExportSpecification={
                        'ExportFromTime': from_time,
                        'ExportToTime': to_time,
                        'ExportViewType': 'NEW_IMAGE'
                    }
                )
    except Exception as e:
        print(e)
    

    enter image description here