{"id":2264,"date":"2019-08-22T11:21:44","date_gmt":"2019-08-22T11:21:44","guid":{"rendered":"https:\/\/www.testpreptraining.com\/tutorial\/?page_id=2264"},"modified":"2020-05-02T07:49:00","modified_gmt":"2020-05-02T07:49:00","slug":"dynamo-db-basics","status":"publish","type":"page","link":"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/","title":{"rendered":"Dynamo DB Basics"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><li>It is a fully managed NoSQL database service <\/li><li>It provides fast and predictable performance with seamless scalability. <\/li><li>Offload the administrative burdens of operating and scaling a distributed database<\/li><li>It also offers encryption at rest<\/li><li>Create database tables that can store and retrieve any amount of data<\/li><li>Serve any level of request traffic. <\/li><li>Scale up or down tables&#8217; throughput capacity without downtime or performance degradation<\/li><li>Use the AWS Management Console to monitor resource utilization. <\/li><li>Also, provides on-demand backup capability with full backups of tables for long-term retention and archival.<\/li><li>tables, items, and attributes are the core components 2084<\/li><li>A table is a collection of items<\/li><li>item is a collection of attributes. <\/li><li>primary keys are used to uniquely identify each item in a table <\/li><li>secondary indexes provide more querying flexibility<\/li><li>DynamoDB Streams capture data modification events in DynamoDB tables. <\/li><li>Collection of Tables, tables highest level structure within DB, WCU number of 1KB blocks per second, RCU number of 4KB blocks per second.<\/li><li>eventually consistent (less cost\/RCU)\/immediate consistent<\/li><li>Hash Key\/Partition Key<\/li><li>Range Key\/Sort Key<\/li><li>Partitions: <ul><li>Underlying storage and processing nodes of DynamoDB. Initially one table -> one partition, one partition can store 10 GB, <\/li><\/ul><ul><li>handles 3000 RCU and 1000 WCU, data distributed based on Hash\/Partition Key, can scale indefinitely, no decrease in performance,<\/li><\/ul><ul><li>allocated WCU and RCU is split between partitions.<\/li><\/ul><\/li><li>GSI\/LSI:<ul><li>DynamoDB offers 2 data retrieval operations, SCAN (scan entire table) and QUERY (select single\/multiple item by partition key value)<\/li><\/ul><ul><li>Index allows efficient queries<\/li><\/ul><ul><li>Global Secondary Index &#8211; can be created anytime, can have alternative Partition &amp; Sort Key, RCU and WCU are defined on GSI.<\/li><\/ul><ul><li>GSI only support evetually consistent reads.<\/li><\/ul><ul><li>Local Secondary Index &#8211; can only be created at the time of table creation; contains Partition, Sort key and New Sort Key, Projected values<\/li><\/ul><ul><li>LSI storage concerns &#8211; Beware of ItemCollections, ItemCollections max size is 10 GB, ItemCollectionSizeLimitExceededException &#8211; Answer<\/li><\/ul><ul><li>LSI and capacity exceeded 10GB<\/li><\/ul><\/li><li>Streams &amp; Replications: <ul><li>Streams: ordered record of updates to a DynamoDB table, If stream enabled records table and stores for 24 hours. <\/li><\/ul><ul><li>AWS guarantee no duplication and real time. can be configured with 4 views; <\/li><\/ul><ul><li>KEYS_ONLY (only key attributes are written to the stream)<\/li><\/ul><ul><li>NEW_IMAGE (entire item POST update)<\/li><\/ul><ul><li>OLD_IMAGE (entire item PRE update)<\/li><\/ul><ul><li>NEW_AND_OLD_IMAGES (PRE and POST operation state)<\/li><\/ul><ul><li>Use cases of Stream: Replication, Triggers, Games or large distributed app with user worldwide, DR, Lambda function triggered when items are added perform analytics etc<\/li><\/ul><\/li><li>Replication<ul><li>not built in DynamoDB. Create or select table to be replicated, apply CFN stack and wait, get the location from URL of CFN output<\/li><\/ul><\/li><li>test a simple cross region replication<\/li><li>Use SQS as Management write buffer. <\/li><li>Increase in RCU is dangerous.<\/li><li>prefix\/suffix key additions to improve keyspace load leveling<\/li><li>Buffering read\/writes with SQS and Caching <\/li><\/ul>\n\n\n\n<p><strong>DynamoDB\ncomponents<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Tables <ul><li>Similar\nto other database systems, DynamoDB stores data in tables. <\/li><\/ul><ul><li>A\ntable is a collection of data<\/li><\/ul><ul><li>Example,\nsee the example table called People, is listed below, to store personal contact\ninformation about friends, family, or anyone else of interest. You could also\nhave a Cars table to store information about vehicles that people drive.<\/li><\/ul><\/li><li>Items <ul><li>Each\ntable contains zero or more items<\/li><\/ul><ul><li>An\nitem is a group of attributes that is uniquely identifiable among all of the\nother items. <\/li><\/ul><ul><li>In\na People table, each item represents a person. For a Cars table, each item\nrepresents one vehicle. <\/li><\/ul><ul><li>Items\nare similar in many ways to rows, or tuples in other database systems. <\/li><\/ul><ul><li>There\nis no limit to the number of items you can store in a table.<\/li><\/ul><\/li><li>Attributes <ul><li>Each\nitem is composed of one or more attributes. <\/li><\/ul><ul><li>It\nis a fundamental data element, and is not to be broken down any further. <\/li><\/ul><ul><li>For\nexample, an item in a People table contains attributes called PersonID,\nLastName, FirstName, and so on. <\/li><\/ul><ul><li>Attributes\nare similar to fields or columns in other database systems.<\/li><\/ul><\/li><\/ul>\n\n\n\n<p>The following diagram shows a table named People with some example items and attributes.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"217\" height=\"400\" src=\"https:\/\/www.testpreptraining.ai\/tutorial\/wp-content\/uploads\/2019\/08\/image-192-217x400.png\" alt=\"\" class=\"wp-image-2342\" srcset=\"https:\/\/www.testpreptraining.ai\/tutorial\/wp-content\/uploads\/2019\/08\/image-192-217x400.png 217w, https:\/\/www.testpreptraining.ai\/tutorial\/wp-content\/uploads\/2019\/08\/image-192.png 274w\" sizes=\"auto, (max-width: 217px) 100vw, 217px\" \/><\/figure><\/div>\n\n\n\n<p>Note the following about the People table:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Each item in the table has a unique identifier,\nor primary key, that distinguishes the item from all of the others in the\ntable. In the People table, the primary key consists of one attribute\n(PersonID).<\/li><li>Other than the primary key, the People table is\nschemaless, which means that neither the attributes nor their data types need\nto be defined beforehand. Each item can have its own distinct attributes.<\/li><li>Most of the attributes are scalar, which means\nthat they can have only one value. Strings and numbers are common examples of\nscalars.<\/li><li>Some of the items have a nested attribute\n(Address). DynamoDB supports nested attributes up to 32 levels deep.<\/li><\/ul>\n\n\n\n<p>DynamoDB supports two different kinds of primary keys:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Partition key \u2013 A simple primary key, composed\nof one attribute known as the partition key. Partition key&#8217;s value is input to\nan internal hash function. The output from the hash function determines the\npartition (physical storage internal to DynamoDB) in which the item will be\nstored. In a table that has only a partition key, no two items can have the\nsame partition key value. The People table has a simple primary key (PersonID)\nto access any item in the table directly by providing it.<\/li><li>Partition key and sort key \u2013&nbsp; Called as a composite primary key. Has two\nattributes &#8211; first is the partition key, and second is the sort key. Partition\nkey value as input to an internal hash function. The output from the hash\nfunction determines the partition (physical storage internal to DynamoDB) in\nwhich the item will be stored. All items with the same partition key value are\nstored together, in sorted order by sort key value. <\/li><\/ul>\n\n\n\n<p><strong>Secondary\nIndexes \u2013 <\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Can create one or more secondary indexes on a\ntable. <\/li><li>Query the table using an alternate key by\nsecondary index, instead of primary key. <\/li><li>DynamoDB doesn&#8217;t require index, but index give\nmore flexibility during querying data. <\/li><li>With a secondary index on a table, read data\nfrom index similar as, from the table.<\/li><\/ul>\n\n\n\n<p><strong>DynamoDB index types<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Global secondary index \u2013 Partition key and sort\nkey that can be different from those on the table.<\/li><li>Local secondary index \u2013Same partition key as the\ntable, but a different sort key.<\/li><\/ul>\n\n\n\n<p>DynamoDB supports eventually consistent and strongly\nconsistent reads.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Eventually Consistent Reads &#8211; When you read data from a DynamoDB table, the response might not reflect the results of a recently completed write operation. The response might include some stale data. If you repeat read request after a short time, the response should return the latest data.<\/li><li>Strongly Consistent Reads &#8211; When you request a strongly consistent read, DynamoDB returns a response with the most up-to-date data, reflecting the updates from all prior write operations that were successful. A strongly consistent read might not be available if there is a network delay or outage. Consistent reads are not supported on global secondary indexes (GSI). <\/li><\/ul>\n\n\n\n<p><strong>Naming Rules<\/strong><\/p>\n\n\n\n<p>Tables, attributes, and other\nobjects in DynamoDB must have names. Names should be meaningful and concise\u2014for\nexample, names such as Products, Books, and Authors are self-explanatory.<\/p>\n\n\n\n<p>The following are the naming rules\nfor DynamoDB:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>All names must be encoded using UTF-8, and are\ncase-sensitive.<\/li><li>Table names and index names must be between 3\nand 255 characters long, and can contain only the following characters:<ul><li>a-z<\/li><\/ul><ul><li>A-Z<\/li><\/ul><ul><li>0-9<\/li><\/ul><ul><li>_\n(underscore)<\/li><\/ul><ul><li>&#8211;\n(dash)<\/li><\/ul><ul><li>.\n(dot)<\/li><\/ul><\/li><li>Attribute names must be between 1 and 255\ncharacters long.<\/li><\/ul>\n\n\n\n<p><strong>Reserved Words and Special Characters<\/strong><\/p>\n\n\n\n<p>DynamoDB has a list of reserved\nwords and special characters. For a complete list of reserved words in\nDynamoDB, see Reserved Words in DynamoDB. Also, the following characters have\nspecial meaning in DynamoDB: # (hash) and : (colon).<\/p>\n\n\n\n<p>Although DynamoDB allows you to use\nthese reserved words and special characters for names, we recommend that you\navoid doing so because you have to define placeholder variables whenever you\nuse these names in an expression. <\/p>\n\n\n\n<p><strong>Data Types<\/strong><\/p>\n\n\n\n<p>DynamoDB supports many different\ndata types for attributes within a table. They can be categorized as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Scalar Types \u2013 A scalar type can represent\nexactly one value. The scalar types are number, string, binary, Boolean, and\nnull.<\/li><li>Document Types \u2013 A document type can represent a\ncomplex structure with nested attributes, such as you would find in a JSON\ndocument. The document types are list and map.<\/li><li>Set Types \u2013 A set type can represent multiple\nscalar values. The set types are string set, number set, and binary set.<\/li><\/ul>\n\n\n\n<p>When you create a table or a secondary index, you must specify the names and data types of each primary key attribute (partition key and sort key). Furthermore, each primary key attribute must be defined as type string, number, or binary. <\/p>\n\n\n\n<p>DynamoDB is a NoSQL database and is schemaless. This means that, other than the primary key attributes, you don&#8217;t have to define any attributes or data types when you create tables. By comparison, relational databases require you to define the names and data types of each column when you create a table. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is a fully managed NoSQL database service It provides fast and predictable performance with seamless scalability. Offload the administrative burdens of operating and scaling a distributed database It also offers encryption at rest Create database tables that can store and retrieve any amount of data Serve any level of request traffic. Scale up or&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2084,"menu_order":52,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[7,376,436],"class_list":["post-2264","page","type-page","status-publish","hentry","category-amazon-aws","tag-aws","tag-aws-devops","tag-db-basics"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Dynamo DB Basics - Testprep Training Tutorials<\/title>\n<meta name=\"description\" content=\"Dynamo DB Basics is a fully managed NoSQL database service\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dynamo DB Basics - Testprep Training Tutorials\" \/>\n<meta property=\"og:description\" content=\"Dynamo DB Basics is a fully managed NoSQL database service\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/\" \/>\n<meta property=\"og:site_name\" content=\"Testprep Training Tutorials\" \/>\n<meta property=\"article:modified_time\" content=\"2020-05-02T07:49:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.testpreptraining.ai\/tutorial\/wp-content\/uploads\/2019\/08\/image-192-217x400.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/\",\"url\":\"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/\",\"name\":\"Dynamo DB Basics - Testprep Training Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/www.testpreptraining.ai\/tutorial\/#website\"},\"datePublished\":\"2019-08-22T11:21:44+00:00\",\"dateModified\":\"2020-05-02T07:49:00+00:00\",\"description\":\"Dynamo DB Basics is a fully managed NoSQL database service\",\"breadcrumb\":{\"@id\":\"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.testpreptraining.ai\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AWS Certified DevOps Engineer Professional\",\"item\":\"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Dynamo DB Basics\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.testpreptraining.ai\/tutorial\/#website\",\"url\":\"https:\/\/www.testpreptraining.ai\/tutorial\/\",\"name\":\"Testprep Training Tutorials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.testpreptraining.ai\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.testpreptraining.ai\/tutorial\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.testpreptraining.ai\/tutorial\/#organization\",\"name\":\"Testprep Training\",\"url\":\"https:\/\/www.testpreptraining.ai\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.testpreptraining.ai\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.testpreptraining.com\/tutorial\/wp-content\/uploads\/2020\/07\/tpt-logo-6.png\",\"contentUrl\":\"https:\/\/www.testpreptraining.com\/tutorial\/wp-content\/uploads\/2020\/07\/tpt-logo-6.png\",\"width\":583,\"height\":153,\"caption\":\"Testprep Training\"},\"image\":{\"@id\":\"https:\/\/www.testpreptraining.ai\/tutorial\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dynamo DB Basics - Testprep Training Tutorials","description":"Dynamo DB Basics is a fully managed NoSQL database service","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/","og_locale":"en_US","og_type":"article","og_title":"Dynamo DB Basics - Testprep Training Tutorials","og_description":"Dynamo DB Basics is a fully managed NoSQL database service","og_url":"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/","og_site_name":"Testprep Training Tutorials","article_modified_time":"2020-05-02T07:49:00+00:00","og_image":[{"url":"https:\/\/www.testpreptraining.ai\/tutorial\/wp-content\/uploads\/2019\/08\/image-192-217x400.png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/","url":"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/","name":"Dynamo DB Basics - Testprep Training Tutorials","isPartOf":{"@id":"https:\/\/www.testpreptraining.ai\/tutorial\/#website"},"datePublished":"2019-08-22T11:21:44+00:00","dateModified":"2020-05-02T07:49:00+00:00","description":"Dynamo DB Basics is a fully managed NoSQL database service","breadcrumb":{"@id":"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/dynamo-db-basics\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.testpreptraining.ai\/tutorial\/"},{"@type":"ListItem","position":2,"name":"AWS Certified DevOps Engineer Professional","item":"https:\/\/www.testpreptraining.ai\/tutorial\/aws-devops-engineer\/"},{"@type":"ListItem","position":3,"name":"Dynamo DB Basics"}]},{"@type":"WebSite","@id":"https:\/\/www.testpreptraining.ai\/tutorial\/#website","url":"https:\/\/www.testpreptraining.ai\/tutorial\/","name":"Testprep Training Tutorials","description":"","publisher":{"@id":"https:\/\/www.testpreptraining.ai\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.testpreptraining.ai\/tutorial\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.testpreptraining.ai\/tutorial\/#organization","name":"Testprep Training","url":"https:\/\/www.testpreptraining.ai\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.testpreptraining.ai\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.testpreptraining.com\/tutorial\/wp-content\/uploads\/2020\/07\/tpt-logo-6.png","contentUrl":"https:\/\/www.testpreptraining.com\/tutorial\/wp-content\/uploads\/2020\/07\/tpt-logo-6.png","width":583,"height":153,"caption":"Testprep Training"},"image":{"@id":"https:\/\/www.testpreptraining.ai\/tutorial\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.testpreptraining.ai\/tutorial\/wp-json\/wp\/v2\/pages\/2264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testpreptraining.ai\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.testpreptraining.ai\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.testpreptraining.ai\/tutorial\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testpreptraining.ai\/tutorial\/wp-json\/wp\/v2\/comments?post=2264"}],"version-history":[{"count":5,"href":"https:\/\/www.testpreptraining.ai\/tutorial\/wp-json\/wp\/v2\/pages\/2264\/revisions"}],"predecessor-version":[{"id":5287,"href":"https:\/\/www.testpreptraining.ai\/tutorial\/wp-json\/wp\/v2\/pages\/2264\/revisions\/5287"}],"up":[{"embeddable":true,"href":"https:\/\/www.testpreptraining.ai\/tutorial\/wp-json\/wp\/v2\/pages\/2084"}],"wp:attachment":[{"href":"https:\/\/www.testpreptraining.ai\/tutorial\/wp-json\/wp\/v2\/media?parent=2264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testpreptraining.ai\/tutorial\/wp-json\/wp\/v2\/categories?post=2264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testpreptraining.ai\/tutorial\/wp-json\/wp\/v2\/tags?post=2264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}