AWS Java SDK 中 DynamoDB v2 的迁移详细信息?
是否有人对 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.
相关文章