可以通过数据管道转储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.
更多推荐
发布评论