aws dynamodb
The emergence of cloud services has changed the way we build web-applications. This in turn has changed the responsibilities of a Web Developer.
云服務的出現改變了我們構建Web應用程序的方式。 反過來,這改變了Web開發人員的職責。
We used to build everything into a single web-application on a single server. This encompassed multiple responsibilities such as storage, databases, authentication, background jobs, caching, and more.
我們曾經將所有內容構建到單個服務器上的單個Web應用程序中。 這包括多種職責,例如存儲,數據庫,身份驗證,后臺作業,緩存等。
Cloud services allows us to reduce the complexity of our web-app and web-servers by pushing the responsibilities to these highly available, scalable, and durable cloud services.
云服務使我們能夠將責任推到這些高可用性,可擴展且持久的云服務上,從而降低了我們的Web應用程序和Web服務器的復雜性。
A Web Developer who knows how to deploy and integrate cloud services with a web-application is what we call a Cloud Engineer.
一位知道如何將云服務與Web應用程序部署和集成的Web開發人員就是我們所謂的云工程師。
If you want to fast-track your career as a Web Developer in 2020 then the AWS Developer Associate Certification can help you achieve that end goal.
如果您想在2020年快速發展成為Web開發人員的職業,那么AWS開發人員助理認證可以幫助您實現最終目標。
The most important AWS service you need to study to pass that AWS Developer Associate exam is DynamoDB. ?So I have released what I call The Ultimate DynamoDB Cheatsheet for free. You can print this out on the day of your exam to increase your chances of passing.
要通過該AWS Developer Associate考試,您需要學習的最重要的AWS服務是DynamoDB。 因此,我免費發布了所謂的The Ultimate DynamoDB Cheatsheet 。 您可以在考試當天將其打印出來,以增加通過的機會。
It was Nader the AWS Developer Advocate for AWS Amplify who suggested I release my entire cheatsheet for free. You would not have this resource if it wasn't for him.
Nader是AWS Amplify的AWS開發倡導者,他建議我免費發布整個備忘單。 如果不是他的話,您將沒有此資源。
It was Kirk the AWS Senior Technologist specializing in DynamoDB who volunteered his time to ensure the accuracy of this cheatsheet. This turned it from 5 pages to 8 pages long! ?📄📄📄📄📄📄📄📄
專門研究DynamoDB的是AWS高級技術專家Kirk ,他自愿花費時間來確保此備忘單的準確性。 這使它從5頁變成了8頁! 📄📄📄📄📄📄📄📄
If you have Twitter, please do me the favor of thanking them by tweeting at ?@dabit3 and @NoSQLKnowHow with the #AWSCertified hashtag.
如果您有Twitter,請通過使用#AWSCertified主題標簽在@ dabit3和@NoSQLKnowHow發推文,對我表示感謝。
So lets move on to the cheatsheet:
因此,讓我們進入備忘單:
DynamoDB的基礎 (The Basics of DynamoDB)
DynamoDB is a fully managed NoSQL key/value and document database.
DynamoDB是一個完全托管的NoSQL鍵/值和文檔數據庫。
DynamoDB is suited for workloads with any amount of data that require predictable read and write performance and automatic scaling from large to small and everywhere in between.
DynamoDB適合需要任何數據量且需要可預測的讀取和寫入性能以及自動從大到小的縮放以及介于兩者之間的任何地方的工作負載。
DynamoDB scales up and down to support whatever read and write capacity you specify per second in provisioned capacity mode. Or you can set it to On-Demand mode and there is little to no capacity planning.
DynamoDB可以擴展和縮減以支持您在預置容量模式下每秒指定的任何讀寫容量 。 或者,您可以將其設置為按需模式,幾乎沒有容量規劃。
DynamoDB stores 3 copies of data on SSD drives across 3 AZs in a region.
DynamoDB將3個數據副本存儲在一個區域中3個AZ上的SSD驅動器上 。
DynamoDB's most common datatypes are B (Binary), N (Number), and S (String)
DynamoDB最常見的數據類型是B (二進制), N (數字)和S (字符串)
Tables consist of Items (rows) and Items consist of Attributes (columns)
表由項目 (行)組成,項目由屬性 (列)組成
讀寫一致性 (Reads and Writes Consistency)
DynamoDB can be set to support Eventually Consistent Reads (default) and Strongly Consistent Reads on a per-call basis.
可以將DynamoDB設置為在每次調用的基礎上支持最終一致讀取 (默認)和強烈一致讀取 。
Eventually consistent reads data is returned immediately but data can be inconsistent. Copies of data will be generally consistent in 1 second.
最終一致的讀取數據會立即返回,但數據可能會不一致。 數據副本通常會在1秒內保持一致。
Strongly Consistent Reads will always read from the leader partition since it always has an up-to-date copy. Data will never be inconsistent but latency may be higher. Copies of data will be consistent with a guarantee of 1 second.
高度一致的讀取將始終從引導者分區讀取,因為它始終具有最新副本。 數據永遠不會不一致,但是延遲可能會更高。 數據副本將與1秒的保證一致。
分區 (Partitions)
A Partition is when DynamoDB slices your table up into smaller chunks of data. This speeds up reads for very large tables.
分區是指DynamoDB將表切成更小的數據塊。 這會加快超大型表的讀取速度。
DynamoDB automatically creates Partitions for:
DynamoDB自動為以下對象創建分區:
- Every 10 GB of Data or 每10 GB數據或
- When you exceed RCUs (3000) or WCUs (1000) limits for a single partition 當您超出單個分區的RCU(3000)或WCU(1000)限制時
- When DynamoDB sees a pattern of a hot partition, it will split that partition in an attempt to fix the issue. 當DynamoDB看到熱分區的模式時,它將拆分該分區,以嘗試解決此問題。
DynamoDB will try to evenly split the RCUs and WCUs across Partitions
DynamoDB將嘗試在分區之間平均分配 RCU和WCU
主鍵設計 (Primary Key Design)
Primary keys define where and how your data will be stored in partitions
主鍵定義數據在何處以及如何存儲在分區中
The Key schema can be made up of two keys:
密鑰架構可以由兩個密鑰組成:
Partition Key (PK) is also known as HASH
分區密鑰(PK)也稱為HASH
The Sort Key (SK) is also known as RANGE
的 排序鍵(SK)也稱為RANGE
When using the AWS DynamoDB API eg. CLI, SDK they refer to the PK and SK by their alternative names due to legacy reasons.
使用AWS DynamoDB API時 由于傳統原因,CLI,SDK通過備用名稱引用了PK和SK。
Primary key comes in two types:
主鍵有兩種類型:
Simple Primary Key (Using only a Partition Key)
簡單主鍵(僅使用分區鍵)
Composite Primary Key (Using both a Partition and Sort Key)
復合主鍵(同時使用分區鍵和排序鍵)
Key Uniqueness is as follows:
密鑰唯一性如下:
When creating a Simple Primary Key the PK value may be unique
創建簡單主鍵時,PK 值可能是唯一的
When creating a Composite Primary Key the combined PK and ?SK must be unique
創建復合主鍵時,組合的PK和SK必須唯一
When using a Sort key, records on the partition are logically grouped together in Ascending order.
使用排序鍵時,分區上的記錄在邏輯上按升序分組在一起。
次要指標 (Secondary Indexes)
DynamoDB has two types of Indexes:
DynamoDB有兩種類型的索引:
LSI - Local Secondary index
LSI-本地二級索引
GSI - ?Global Secondary Index
GSI-全球二級指數
LSI-本地二級索引 (LSI - Local Secondary index)
Supports strongly or eventual consistency reads
支持強烈或最終的一致性讀取
- Can only be created with initial table (cannot be modified or and cannot deleted unless also deleting the table) 只能使用初始表創建(無法修改或不能刪除,除非也刪除表)
- Only Composite 僅復合
- 10GB or less per partition 每個分區10GB或更少
- Share capacity units with base table 與基本表共享容量單位
- Must share Partition Key (PK) with base table. 必須與基本表共享分區密鑰(PK)。
GSI-全球二級指數 (GSI - ?Global Secondary Index)
Only eventual consistency reads ?(cannot provide strong consistency)
僅讀取最終一致性 (無法提供強一致性)
- Can create, modify, or delete at anytime 可以隨時創建,修改或刪除
- Simple and Composite 簡單和復合
- Can have whatever attributes as Primary Key (PK) or Secondary Key (SK) 可以具有任何屬性,例如主鍵(PK)或輔助鍵(SK)
- No size restriction per partition 每個分區沒有大小限制
- Has its own capacity settings (does not share with base table) 有自己的容量設置(不與基表共享)
掃瞄 (Scan)
Your table(s) should be designed in such a way that your workload primary access patterns do not use Scans. Overall, scans should be needed sparingly, for example for an infrequent report.
表的設計方式應使您的工作負載主要訪問模式不使用掃描。 總體而言,應該少量地進行掃描,例如對于不頻繁的報告。
- Scans through all items in a table and then returns one or more items through filters 掃描表中的所有項目,然后通過過濾器返回一個或多個項目
By default returns all attributes for every item (use ProjectExpression to limit)
默認情況下,返回每個項目的所有屬性(使用ProjectExpression進行限制)
Scans are sequential, and you can speed up a scan through parallel scans using Segments and Total Segments
掃描是順序掃描,您可以使用“ 細分”和“ 總細分”通過并行掃描來加快掃描速度
- Scans can be slow, especially with very large tables and can easily consume your provisioned throughput. 掃描速度可能很慢,尤其是對于非常大的表,掃描很容易消耗您預配置的吞吐量。
- Scans are one of the most expensive ways to access data in DynamoDB. 掃描是訪問DynamoDB中數據的最昂貴的方法之一。
詢問 (Query)
- Find items based on primary key values 根據主鍵值查找項目
- Table must have a composite key in order to be able to query 表必須具有復合鍵才能查詢
By default queries are Eventually Consistent (use ConsistentRead True to change Strongly Consistent)
默認情況下,查詢最終是一致的(使用ConsistentRead True更改為“高度一致”)
By default returns all attributes for each item found by a query (use ProjectExpression to limit)
默認情況下返回查詢找到的每個項目的所有屬性(使用ProjectExpression進行限制)
By default is sorted ascending (use ScanIndexForward to False to reverse order to descending)
默認情況下按升序排序(使用ScanIndexForward為False可以將順序反轉為降序)
容量模式 (Capacity Modes)
DynamoDB has two capacity modes, Provisioned and On-Demand. You can switch between these modes once every 24 hours.
DynamoDB具有兩種容量模式,即Provisioned和On-Demand 。 您可以每24小時在這些模式之間切換一次 。
已配置 (Provisioned)
Provisioned Throughput Capacity is the maximum amount of capacity your application is allowed to read or write per second from a table or index
預配置吞吐量是您的應用程序每秒從表或索引中讀取或寫入的最大容量
Provisioned is suited for predictable or steady state workloads
預配置適用于可預測或穩定的工作負載
RCUs is Read Capacity Unit
RCU是讀取容量單位
WCUs is Write Capacity Unit
WCU是寫入容量單位
You should enable Auto Scaling with Provisioned capacity mode. In this mode, you set a floor and ceiling for the capacity you wish the table to support. DynamoDB will automatically add and remove capacity to between these values on your behalf and throttle calls that go above the ceiling for too long.
您應該啟用“具有預置容量模式的自動擴展” 。 在這種模式下,您可以設置您希望桌子支撐的容量的上限和下限。 DynamoDB將代表您自動添加和刪除這些值之間的容量,并限制超出上限的時間太長的限制調用。
If you go beyond your provisioned capacity, you’ll get an Exception: ?ProvisionedThroughputExceededException (throttling)
如果您超出了預配置的容量,則會收到異常: ProvisionedThroughputExceededException (限制)
Throttling is when requests are blocked due to read or write frequency higher than set thresholds. E.g. exceeding set provisioned capacity, partitions splitting, table/index capacity mismatch.
節流是指由于讀取或寫入頻率高于設置的閾值而阻止請求的情況 。 例如,超出設置的預定容量,分區拆分,表/索引容量不匹配。
一經請求 (On-Demand)
On-Demand Capacity is pay per request. So you pay only for what you use.
按需容量是按請求付費。 因此,您只需為使用的商品付費。
On-Demand is suited for new or unpredictable workloads
按需適用于新的或不可預測的工作負載
- The throughput is only limited by the default upper limits for a table (40K RCUs and 40K WCUs) 吞吐量僅受表的默認上限限制(40K RCU和40K WCU)
Throttling can occur if you exceed double your previous peak capacity (high water mark) within 30 minutes. For example, if you previously peaked to a maximum of 30,000 ops/sec, you could not peak immediately to 90,000 ops/sec, but you could to 60,000 ops/sec.
如果您在30分鐘內超過先前峰值容量(高水位線)的兩倍, 就會發生節流 。 例如,如果您之前的最高峰值為30,000 ops / sec,則無法立即達到90,000 ops / sec,但最高峰值為60,000 ops / sec。
Since there is no hard limit, On-Demand could become very expensive based on emerging scenarios
由于沒有硬性限制, 因此根據新興情況, 按需可能會變得非常昂貴
計算讀寫 (Calculating Reads and Writes)
計算讀數(RCU) (Calculating Reads (RCU))
A read capacity unit represents:
讀取容量單位表示:
- one strongly consistent read per second, 每秒強烈一致的讀取,
- or two eventually consistent reads per second, 或每秒兩次最終一致的讀取,
- for an item up to 4 KB in size. 大小最大為4 KB的項目。
How to calculate RCUs for strong
如何計算強大的 RCU
- Round data up to nearest 4. 將數據四舍五入至最接近的值4。
- Divide data by 4 將數據除以4
- Times by number of reads 讀取次數的倍數
Here's an example:
這是一個例子:
- 50 reads at 40KB per item. (40/4) x 50 = 500 RCUs 每個項目以40KB讀取50次。 (40/4)x 50 = 500個RCU
- 10 reads at 6KB per item. (8/4) x 10 = 20 RCUs 每個項目10讀,大小為6KB。 (8/4)x 10 = 20個RCU
- 33 reads at 17KB per item. (20/4) x 33 = 132 RCUs 每個項目以33KB讀取,大小為17KB。 (20/4)x 33 = 132個RCU
How to calculate RCUs for eventual
如何計算最終的 RCU
- Round data up to nearest 4. 將數據四舍五入到最接近的4。
- Divide data by 4 將數據除以4
- Times by number of reads 讀取次數的倍數
- Divide final number by 2 將最終數字除以2
- Round up to the nearest whole number 四舍五入到最接近的整數
Here's an example:
這是一個例子:
- 50 reads at 40KB per item. (40/4) x 50 / 2 = 250 RCUs 每個項目以40KB讀取50次。 (40/4)x 50/2 = 250個RCU
- 11 reads at 9KB per item. (12/4) x 11 / 2 = 17 RCUs 每個項目11次讀取,大小為9KB。 (12/4)x 11/2 = 17個RCU
- 14 reads at 24KB per item. (24/4) x 14 / 2 = 35 RCUs 14個條目,每個條目24KB。 (24/4)x 14/2 = 35個RCU
計算寫(寫) (Calculating Writes (Writes))
A write capacity unit represents:
寫容量單位表示:
- one write per second, 每秒寫一次
- for an item up to 1 KB 用于最大1 KB的項目
How to calculate Writes
如何計算寫
- Round data up to nearest 1. 將數據四舍五入到最接近的1。
- Times by number of writes 寫入次數
Here's an example:
這是一個例子:
- 50 writes at 40KB per item. 40 x 50 = 2000 WCUs 每個項目40個KB,可寫入50次。 40 x 50 = 2000個WCU
- 11 writes at 1KB per item. 1 x 11 = 11 WCUs 每個項目以1KB寫入11次。 1 x 11 = 11個WCU
- 18 writes at 500 BYTES per item. 1 x 18 = 18 WCUs 每項500次寫入18次寫入。 1 x 18 = 18個WCU
DynamoDB加速器
(DynamoDB Accelerator)
DynamoDB Accelerator (DAX) is a fully managed in-memory write through cache for DynamoDB that runs in a cluster
DynamoDB Accelerator (DAX)是針對群集中運行的DynamoDB的完全托管的內存中直寫式緩存
- Reads are eventually consistent 讀取最終是一致的
- Incoming requests are evenly distributed across all of the nodes in the cluster. 傳入請求均勻分布在集群中的所有節點上。
DAX can reduce read response times to microseconds
DAX可以將讀取響應時間減少到微秒
DAX非常適合: (DAX is ideal for:)
- fastest response times possible 最快的響應時間
- apps that read a small number of items more frequently 讀取少量項目的應用程序
apps that are read intensive
密集閱讀的應用
DAX不適用于: (DAX is not ideal for:)
- Apps that require strongly consistent reads 需要高度一致讀取的應用
- Apps that do not require microsecond read response times 不需要微秒讀取響應時間的應用
Apps that are write intensive, or that do not perform much read activity
寫入密集型或讀取活動不多的應用
If you don’t need DAX consider using ElastiCache
如果您不需要DAX,請考慮使用ElastiCache
DynamoDB事務 (DynamoDB Transactions)
DynamoDB supports transactions via the TransactWriteItems and TransactGetItems API calls.
DynamoDB通過TransactWriteItems和TransactGetItems API調用支持事務。
Transactions let you query multiple tables at once and are an all-or-nothing approach (all API calls must succeed).
事務使您可以一次查詢多個表,這是一種全有或全無的方法(所有API調用必須成功)。
全局表 (Global tables)
DynamoDB Global tables provide a fully managed solution for deploying multi-region, multi-master databases.
DynamoDB Global表提供了用于部署多區域,多主數據庫的完全托管的解決方案。
流 (Streams)
DynamoDB Streams allows you to set up a Lambda function triggered every time data is modified in a table to react to changes. Streams do not consume RCUs.
通過DynamoDB Streams ,您可以設置每次修改表中的數據以響應更改時觸發的Lambda函數。 流不占用RCU。
DynamoDB API (DynamoDB API)
DynamoDB API's most notable commands via CLI: ?aws dynamodb <command>
通過CLI的DynamoDB API最著名的命令: aws dynamodb <命令>
aws dynamodb get-item returns a set of attributes for the item with the given primary key. If no matching item, then it does not return any data and there will be no Item element in the response.
aws dynamodb get-item返回具有給定主鍵的項的一組屬性。 如果沒有匹配的項目,則它不返回任何數據,并且響應中將沒有Item元素。
aws dynamodb put-item Creates a new item, or replaces an old item with a new item. If an item that has the same primary key as the new item already exists in the specified table, the new item completely replaces the existing item.
aws dynamodb put-item創建新項目,或將舊項目替換為新項目。 如果指定表中已經存在與新項目具有相同主鍵的項目,則新項目將完全替換現有項目。
aws dynamodb update-item Edits an existing item's attributes, or adds a new item to the table if it does not already exist.
aws dynamodb update-item編輯現有項目的屬性,或將新項目添加到表(如果尚不存在)。
aws dynamodb batch-get-item returns the attributes of one or more items from one or more tables. You identify requested items by primary key. A single operation can retrieve up to 16 MB of data, which can contain as many as 100 items.
aws dynamodb batch-get-item返回一個或多個表中一個或多個項目的屬性。 您可以通過主鍵標識請求的項目。 一個操作最多可以檢索16 MB的數據 ,其中可以包含多達100個項目 。
aws dynamodb batch-write-item puts or deletes multiple items in one or more tables. Can write up to 16 MB of data, which can comprise as many as 25 put or delete requests. Individual items to be written can be as large as 400 KB.
aws dynamodb batch-write-item在一個或多個表中放置或刪除多個項目。 最多可以寫入16 MB的數據 ,其中可以包含多達25個放置或刪除請求 。 要寫入的單個項目最大可以為400 KB 。
aws dynamodb create-table adds a new table to your account. Table names must be unique within each Region.
aws dynamodb create-table將新表添加到您的帳戶。 表名稱在每個區域內必須唯一。
aws dynamodb update-table Modifies the provisioned throughput settings, global secondary indexes, or DynamoDB Streams settings for a given table.
aws dynamodb update-table修改給定表的預配置吞吐量設置,全局二級索引或DynamoDB流設置。
aws dynamodb delete-table operation deletes a table and all of its items.
aws dynamodb delete-table操作將刪除表及其所有項目。
aws dynamodb transact-get-items is a synchronous operation that atomically retrieves multiple items from one or more tables (but not from indexes) in a single account and Region. Call can contain up to 25 objects. The aggregate size of the items in the transaction cannot exceed 4 MB.
aws dynamodb transact-get-items是一種同步操作,該操作以原子方式從單個帳戶和區域中的一個或多個表(但不是從索引)中檢索多個項目。 呼叫最多可以包含25個對象 。 交易中項目的總大小不能超過4 MB 。
aws dynamodb transact-write-items a synchronous write operation that groups up to 25 action requests. These actions can target items in different tables, but not in different AWS accounts or Regions, and no two actions can target the same item.
aws dynamodb transact-write-items同步寫操作,最多可分組25個操作請求 。 這些操作可以針對不同表中的項目,但不能針對不同的AWS賬戶或區域中的項目,并且沒有兩個操作可以針對同一項目。
aws dynamodb query finds items based on primary key values. You can query table or secondary index that has a composite primary key.
AWS dynamodb 查詢根據主鍵值查找項目。 您可以查詢具有復合主鍵的表或二級索引。
aws dynamodb scan returns one or more items and item attributes by accessing every item in a table or a secondary index.
AWS dynamodb 掃描通過訪問表或二級索引中的每個項目來返回一個或多個項目和項目屬性。
To火箭到火星 (🚀 rocketsToMars)
I want to help you enter the web and cloud industry. That is why I am releasing my free AWS Developer Associate Certification 2020 course on the freeCodeCamp YouTube channel with 10+ hours of additional content I have never released previously.
我想幫助您進入Web和云行業。 這就是為什么我要在freeCodeCamp YouTube頻道上發布我的免費 AWS開發人員協會2020認證課程,其中包含10個小時以上從未有過的額外內容。
This free course will be released in a few days as I apply the final touches.
當我應用最后的修飾時,此免費課程將在幾天后發布。
I believe in making tech education accessible to the world because in-turn the more we upskill, the sooner we can lift people out of poverty, the sooner we can engineer sustainable solutions to keep our planet green and healthy, and the sooner we can launch rockets to Mars.
我相信讓全世界都能接受技術教育是因為反過來,我們的技能提高得越多,我們就能越早使人們擺脫貧困,我們就可以越早設計出可持續的解決方案來保持地球的綠色和健康,就可以越早推出火箭前往火星。
翻譯自: https://www.freecodecamp.org/news/ultimate-dynamodb-2020-cheatsheet/
aws dynamodb