截断DynamoDb或通过数据管道重写数据(Truncate DynamoDb or rewrite data via Data Pipeline)

系统教程 行业动态 更新时间:2024-06-14 17:03:52
截断DynamoDb或通过数据管道重写数据(Truncate DynamoDb or rewrite data via Data Pipeline)

可以通过数据管道转储DynamoDb,也可以在DynamoDb中导入数据。 导入进展顺利,但数据一直附加到DynamoDb中已存在的数据。

现在我找到了扫描DynamoDb并逐个或批量删除项目的工作示例。 但无论如何,对于大量数据而言,它并不是一个好的变体。

也可以删除表并创建它。 但随着这种变化,索引将会丢失。

因此,最好的方法是通过Data Pipeline导入覆盖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.

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.

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?

最满意答案

DynamoDB中没有Truncate Table功能, 仔细考虑删除表并再次创建

原因 :DynamoDB根据您使用的ReadCapacityUnits和WriteCapacityUnits向您收费。 如果使用BatchWriteItem函数删除所有项目,它将使用WriteCapacityUnits 。 因此,要保存这些WriteCapacityUnits以删除项目,最好是截断表并重新创建它。

删除和创建DynamoDB表的步骤如下:

通过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 } }

摘要删除表并再次创建它将是最佳解决方案。

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

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.

Steps to Delete & Create DynamoDB Tables as follows :

Delete Table via AWS CLI :

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

Delete Table via AmazonDynamoDB API :

Sample Request

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" }

Creating DynamoDB Table via 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.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.

更多推荐

本文发布于:2023-04-24 12:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/b0024ce89363ba6944b660c5f2e0b69c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   重写   管道   DynamoDb   Truncate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!