問題描述
是否有人對 AWS Java SDK 1.4.2(及更高版本)中的 DynamoDB 的新命名空間 (com.amazonaws.services.dynamodbv2
) 和接口進行了更改?根據 1.4.2 發行說明,本地二級指數的發布顯然需要進行重大更改.
Has anyone made the change to the new namespaces (com.amazonaws.services.dynamodbv2
) and interfaces for DynamoDB in the AWS Java SDK 1.4.2 (and later)? The release of Local Secondary Indices apparently necessitated breaking changes as per the 1.4.2 release notes.
有沒有人找到一份指南,詳細說明了哪些更改以及遷移現有代碼需要做什么?我正在嘗試決定何時最好對現有代碼庫進行此更改.
Has anyone found a guide detailing what changed and what needs to happen to migrate existing code? I am trying to decide when is best to make this change for an existing code base.
推薦答案
DynamoDB 的新 dynamodbv2 命名空間引入了以下不兼容的更改(因為它們不是簡單的添加,需要更改代碼才能切換到新的命名空間):
The new dynamodbv2 namespace of DynamoDB introduces the following incompatible changes (in that they are not simply additive, and require code changes to switch to the new namespace):
- HashKeyElement 和 RangeKeyElement 被替換為 Map
.這包括名為 ExclusiveStartKey、LastEvaluatedKey 和 Key 的結構.此更改對代碼的主要影響是,現在為了調用 GetItem,您的代碼需要知道主鍵的屬性名稱,而不僅僅是主鍵值. - Query 現在使用 Map
類型的 KeyCondition 來指定完整的查詢,而不是使用單獨的 HashKeyValue 和 RangeKeyCondition 字段. - CreateTable 輸入將屬性類型定義與主鍵定義分開(并且創建/更新/刪除/描述響應與此匹配)
- 響應中的已消耗容量現在是一個結構,而不是單個數字,并且必須在請求中提出.在批處理操作中,它以單獨的 ConsumedCapacity 結構返回,而不是與結果一起返回.
- HashKeyElement and RangeKeyElement are replaced with a Map<String, AttributeValue>. This includes the structures named ExclusiveStartKey, LastEvaluatedKey, and Key. The main impact on the code with this change is that now in order to call GetItem, for example, your code needs to know the attribute names of the primary keys, and not just the primary key values.
- Query now uses a KeyCondition of type Map<String, Condition> to specify the full query, instead of having separate HashKeyValue and RangeKeyCondition fields.
- CreateTable input separates the attribute type definitions from the primary key definitions (and create/update/delete/describe responses match this)
- Consumed Capacity in responses is now a structure instead of a single number, and must be asked for in the request. In Batch operations, this is returned in a separate ConsumedCapacity structure, instead of alongside the results.
如果需要,可以逐步將您的代碼遷移到新的 Java API.如果您計劃在代碼中添加查詢本地二級索引或使用本地二級索引創建表的功能,您將需要為該部分代碼使用新的 API.
It is possible to migrate your code to the new Java API incrementally, if desired. If you plan to add functionality to your code that queries Local Secondary Indexes, or creates tables with local secondary indexes, you will need to use the new API for that part of your code.
如果您使用新 API 創建具有本地二級索引的表,您仍然可以使用 dynamodb 命名空間中的現有代碼對該表執行所有現有操作.例如,帶有 dynamodb 命名空間客戶端的 PutItem 將適用于使用 dynamodbv2 客戶端創建的表,反之亦然.
If you create a table with Local Secondary Indexes with the new API, you can still use your existing code in the dynamodb namespace to perform all of the existing operations on that table. As an example, PutItem with the dynamodb namespace client will work against tables created using the dynamodbv2 client, as well as the other way around.
這篇關于AWS Java SDK 中 DynamoDB v2 的遷移詳細信息?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!