Dynamodb 简明教程
DynamoDB - Basic Concepts
在使用 DynamoDB 之前,你必须让自己熟悉它的基本组件和生态系统。在 DynamoDB 生态系统中,你可以使用表、属性和条目。表包含一组条目,条目包含一组属性。属性是无需进一步分解的数据的基本元素,即字段。
Before using DynamoDB, you must familiarize yourself with its basic components and ecosystem. In the DynamoDB ecosystem, you work with tables, attributes, and items. A table holds sets of items, and items hold sets of attributes. An attribute is a fundamental element of data requiring no further decomposition, i.e., a field.
Primary Key
主键用作表条目的唯一标识符,辅助索引提供查询灵活性。DynamoDB 流通过修改表数据记录事件。
The Primary Keys serve as the means of unique identification for table items, and secondary indexes provide query flexibility. DynamoDB streams record events by modifying the table data.
表创建不仅需要设置名称,还需要设置主键;它标识表条目。没有两条条目共享同一个键。DynamoDB 使用两种类型的主键 −
The Table Creation requires not only setting a name, but also the primary key; which identifies table items. No two items share a key. DynamoDB uses two types of primary keys −
-
Partition Key − This simple primary key consists of a single attribute referred to as the “partition key.” Internally, DynamoDB uses the key value as input for a hash function to determine storage.
-
Partition Key and Sort Key − This key, known as the “Composite Primary Key”, consists of two attributes. The partition key and The sort key. DynamoDB applies the first attribute to a hash function, and stores items with the same partition key together; with their order determined by the sort key. Items can share partition keys, but not sort keys.
主键属性仅允许标量(单个)值;和字符串、数字或二进制数据类型。非键属性没有这些约束。
The Primary Key attributes only allow scalar (single) values; and string, number, or binary data types. The non-key attributes do not have these constraints.
Secondary Indexes
这些索引允许你使用备用键查询表数据。尽管 DynamoDB 并不强制使用它们,但它们会优化查询。
These indexes allow you to query table data with an alternate key. Though DynamoDB does not force their use, they optimize querying.
DynamoDB 使用两种类型的二级索引 −
DynamoDB uses two types of secondary indexes −
-
Global Secondary Index − This index possesses partition and sort keys, which can differ from table keys.
-
Local Secondary Index − This index possesses a partition key identical to the table, however, its sort key differs.
API
DynamoDB 提供的 API 操作包括控制平面、数据平面(例如创建、读取、更新和删除)和流的操作。在控制平面操作中,你可以使用以下工具创建和管理表 −
The API operations offered by DynamoDB include those of the control plane, data plane (e.g., creation, reading, updating, and deleting), and streams. In control plane operations, you create and manage tables with the following tools −
-
CreateTable
-
DescribeTable
-
ListTables
-
UpdateTable
-
DeleteTable
在数据平面中,你可以使用以下工具执行 CRUD 操作 −
In the data plane, you perform CRUD operations with the following tools −
Create |
Read |
Update |
Delete |
PutItem BatchWriteItem |
GetItem BatchGetItem Query Scan |
UpdateItem |
DeleteItem BatchWriteItem |
流操作控制表流。你可以查看以下流工具 −
The stream operations control table streams. You can review the following stream tools −
-
ListStreams
-
DescribeStream
-
GetShardIterator
-
GetRecords
Provisioned Throughput
在表创建中,你可以指定预置吞吐量,它为读取和写入预留了资源。你可以使用容量单位来衡量和设置吞吐量。
In table creation, you specify provisioned throughput, which reserves resources for reads and writes. You use capacity units to measure and set throughput.
当应用程序超出设置的吞吐量时,请求会失败。DynamoDB GUI 控制台允许监控已设置和已使用的吞吐量,以实现更好和更动态的预置。
When applications exceed the set throughput, requests fail. The DynamoDB GUI console allows monitoring of set and used throughput for better and dynamic provisioning.
Read Consistency
DynamoDB 使用 eventually consistent 和 strongly consistent 读取来支持动态应用程序需求。最终一致性读取并不总能提供当前数据。
DynamoDB uses eventually consistent and strongly consistent reads to support dynamic application needs. Eventually consistent reads do not always deliver current data.
强一致性读取始终提供当前数据(设备故障或网络问题除外)。最终一致性读取是默认设置,要求在 ConsistentRead 参数中设置 true 来更改它。
The strongly consistent reads always deliver current data (with the exception of equipment failure or network problems). Eventually consistent reads serve as the default setting, requiring a setting of true in the ConsistentRead parameter to change it.
Partitions
DynamoDB 使用分区存储数据。这些表的存储分配具有 SSD 支持并跨区域自动复制。DynamoDB 管理所有分区任务,无需用户参与。
DynamoDB uses partitions for data storage. These storage allocations for tables have SSD backing and automatically replicate across zones. DynamoDB manages all the partition tasks, requiring no user involvement.
在创建表时,表进入分配分区的 CREATING 状态。当它进入 ACTIVE 状态时,你可以执行操作。系统在容量达到最大值或更改吞吐量时更改分区。
In table creation, the table enters the CREATING state, which allocates partitions. When it reaches ACTIVE state, you can perform operations. The system alters partitions when its capacity reaches maximum or when you change throughput.