截断DynamoDb或通过数据管道重写数据 [英] Truncate DynamoDb or rewrite data via Data Pipeline

查看:94
本文介绍了截断DynamoDb或通过数据管道重写数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以通过数据管道转储DynamoDb,也可以在DynamoDb中导入数据。导入进展顺利,但是所有时间数据始终附加到DynamoDb中已经存在的数据中。

There is possibility to dump DynamoDb via Data Pipeline and also import data in DynamoDb. Import is going well, but all the time data appends to already exists data in DynamoDb.

目前,我发现了一些工作示例,这些示例扫描DynamoDb并逐个或逐个删除项目批量。但是无论如何对于大量数据来说,它都不是很好的选择。

For now I found work examples that scan DynamoDb and delete items one by one or via Batch. But at any rate for big amount of data it is not good variant.

此外,还可以删除表并创建它。

Also it is possible to delete table at all and create it. But with that variant indexes will be lost.

因此,最好的方法是通过Data Pipeline导入覆盖DynamoDb数据或以某种方式截断。有可能吗?

So, best way would be to override DynamoDb data via import by Data Pipeline or truncate somehow. Is it possible to do? And how is it possible if yes?

推荐答案

Tyncate Table功能在DynamoDB中不可用,因此请考虑删除桌子和桌子再次创建

Truncate Table functionality is not available in DynamoDB, So kindly consider deleting the table & creating again,

原因:DynamoDB基于 ReadCapacityUnits 向您收费&您使用的 WriteCapacityUnits 。如果使用 BatchWriteItem 函数删除所有项目,它将使用 WriteCapacityUnits 。因此,要保存这些 WriteCapacityUnits 以便删除项目,最好将表&

Reason : DynamoDB Charges you based on ReadCapacityUnits & WriteCapacityUnits which you have used. If you delete all items using BatchWriteItem function, it will use WriteCapacityUnits. So, to save these WriteCapacityUnits for deleting items, It will be better if you truncate the table & recreate it agian.

删除和删除步骤创建DynamoDB表,如下所示:

Steps to Delete & Create DynamoDB Tables as follows :


通过AWS CLI删除表

aws dynamodb delete-table --table-name *tableName*

通过AmazonDynamoDB API删除表

示例请求

POST / HTTP/1.1
Host: dynamodb.<region>.<domain>;
Accept-Encoding: identity
Content-Length: <PayloadSizeBytes>     
User-Agent: <UserAgentString>
Content-Type: application/x-amz-json-1.0
Authorization: AWS4-HMAC-SHA256 Credential=<Credential>, SignedHeaders=<Headers>, Signature=<Signature>
X-Amz-Date: <Date> 
X-Amz-Target: DynamoDB_20120810.DeleteTable 

{
    "TableName": "Reply"
}

通过AmazonDynamoDB API创建DynamoDB表

POST / HTTP/1.1
Host: dynamodb.<region>.<domain>;
Accept-Encoding: identity
Content-Length: <PayloadSizeBytes>     
User-Agent: <UserAgentString>
Content-Type: application/x-amz-json-1.0
Authorization: AWS4-HMAC-SHA256 Credential=<Credential>, SignedHeaders=<Headers>, Signature=<Signature>
X-Amz-Date: <Date> 
X-Amz-Target: DynamoDB_20120810.CreateTable 

{
    "AttributeDefinitions": [
        {
            "AttributeName": "ForumName",
            "AttributeType": "S"
        },
        {
            "AttributeName": "Subject",
            "AttributeType": "S"
        },
        {
            "AttributeName": "LastPostDateTime",
            "AttributeType": "S"
        }
    ],
    "TableName": "Thread",
    "KeySchema": [
        {
            "AttributeName": "ForumName",
            "KeyType": "HASH"
        },
        {
            "AttributeName": "Subject",
            "KeyType": "RANGE"
        }
    ],
    "LocalSecondaryIndexes": [
        {
            "IndexName": "LastPostIndex",
            "KeySchema": [
                {
                    "AttributeName": "ForumName",
                    "KeyType": "HASH"
                },
                {
                    "AttributeName": "LastPostDateTime",
                    "KeyType": "RANGE"
                }
            ],
            "Projection": {
                "ProjectionType": "KEYS_ONLY"
            }
        }
    ],
    "ProvisionedThroughput": {
        "ReadCapacityUnits": 5,
        "WriteCapacityUnits": 5
    }
}


摘要删除表格&再次创建是最好的解决方案。

Summary : Delete the table & Create it again would be the best solution.

这篇关于截断DynamoDb或通过数据管道重写数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆