DynamoDB

DynamoDB

 
💡
모든 규모에서 10밀리초 미만의 성능을 제공하는 빠르고 유연한 NoSQL 데이터베이스 서비스
 
무료 사용범위
무료 스토리지 25GB
매월 최대 2억 건의 읽기/쓰기 요청을 AWS 프리 티어로 제공
 
Amazon DynamoDB는 모든 규모에서 고성능 애플리케이션을 실행하도록 설계된 완전관리형의 서버리스 키-값 NoSQL 데이터베이스입니다. DynamoDB는 기본 제공 보안, 지속적인 백업, 자동화된 다중 리전 복제, 인 메모리 캐시 및 데이터 가져오기/내보내기 도구를 제공합니다.
notion image
 
DynamoDB는 높은 트래픽의 대규모 이벤트를 지원하며 초당 수백만 건의 쿼리를 처리할 수 있습니다.
 
DynamoDB 열어 볼 수 있는 NoSQL 워크벤치가 있다. (Mac, Windows 둘다 가능)
 
DAX로 캐시처럼도? 사용 가능함. DynamoDB에서 일관되게 10밀리초 미만의 지연 시간을 제공하지만, DynamoDB와 DAX가 결합되면 성능을 한 단계 업그레이드하여 읽기 중심의 워크로드에서 초당 수백만 개의 요청에도 마이크로초의 응답 시간을 지원합니다. DAX를 사용하면 인기 있는 이벤트 또는 뉴스로 요청 볼륨이 전례 없이 증가하더라도 애플리케이션이 빠른 응답 속도를 유지할 수 있습니다. 튜닝은 필요 없습니다.
notion image
Point-in-time recovery helps protect your tables from accidental write or delete operations. With point-in-time recovery, you can restore a table to any point in time during the last 35 days.
 
DynamoDB allows you to delete expired items from tables automatically to help you reduce storage usage and the cost of storing data that is no longer relevant. For more information, see Expiring items by using DynamoDB Time to Live (TTL). → Google Datastore에서 있었던 기능과 동일한듯
 

High availability and durability

DynamoDB automatically spreads the data and traffic for your tables over a sufficient number of servers to handle your throughput and storage requirements, while maintaining consistent and fast performance.
→ 자동으로 관리되니 트래픽과 데이터양에 따라 자동으로 늘어나고 일관된 성능을 보인다.
 

Amazon DynamoDB: How it works

Core components

DynamoDB uses primary keys to uniquely identify each item in a table and secondary indexes to provide more querying flexibility.
  • Tables – Similar to other database systems, DynamoDB stores data in tables. A table is a collection of data. For example, see the example table called People that you could use to store personal contact information about friends, family, or anyone else of interest. You could also have a Cars table to store information about vehicles that people drive.
  • Items – Each table contains zero or more items. An item is a group of attributes that is uniquely identifiable among all of the other items. In a People table, each item represents a person. For a Cars table, each item represents one vehicle. Items in DynamoDB are similar in many ways to rows, records, or tuples in other database systems. In DynamoDB, there is no limit to the number of items you can store in a table.
  • Attributes – Each item is composed of one or more attributes. An attribute is a fundamental data element, something that does not need to be broken down any further. For example, an item in a People table contains attributes called PersonIDLastNameFirstName, and so on. For a Department table, an item might have attributes such as DepartmentIDNameManager, and so on. Attributes in DynamoDB are similar in many ways to fields or columns in other database systems.
 
Example 1)
People { "PersonID": 101, "LastName": "Smith", "FirstName": "Fred", "Phone": "555-4321" } { "PersonID": 102, "LastName": "Jones", "FirstName": "Mary", "Address": { "Street": "123 Main", "City": "Anytown", "State": "OH", "ZIPCode": 12345 } } { "PersonID": 103, "LastName": "Stephens", "FirstName": "Howard", "Address": { "Street": "123 Main", "City": "London", "PostalCode": "ER3 5K8" }, "FavoriteColor": "Blue" }
 
The primary key consists of one attribute (PersonID)
• Other than the primary key, the People table is schemaless, which means that neither the attributes nor their data types need to be defined beforehand. Each item can have its own distinct attributes.
• Some of the items have a nested attribute (Address). DynamoDB supports nested attributes up to 32 levels deep.
 
Example 2)
Music { "Artist": "No One You Know", "SongTitle": "My Dog Spot", "AlbumTitle": "Hey Now", "Price": 1.98, "Genre": "Country", "CriticRating": 8.4 } { "Artist": "No One You Know", "SongTitle": "Somewhere Down The Road", "AlbumTitle": "Somewhat Famous", "Genre": "Country", "CriticRating": 8.4, "Year": 1984 } { "Artist": "The Acme Band", "SongTitle": "Still in Love", "AlbumTitle": "The Buck Starts Here", "Price": 2.47, "Genre": "Rock", "PromotionInfo": { "RadioStationsPlaying": { "KHCR", "KQBX", "WTNR", "WJJH" }, "TourDates": { "Seattle": "20150622", "Cleveland": "20150630" }, "Rotation": "Heavy" } } { "Artist": "The Acme Band", "SongTitle": "Look Out, World", "AlbumTitle": "The Buck Starts Here", "Price": 0.99, "Genre": "Rock" }
여기는 Primary Key가 없어 보이는데 과연 그럴까?
Answer
  • The primary key for Music consists of two attributes (Artist and SongTitle). Each item in the table must have these two attributes. The combination of Artist and SongTitle distinguishes each item in the table from all of the others.
  • Other than the primary key, the Music table is schemaless, which means that neither the attributes nor their data types need to be defined beforehand. Each item can have its own distinct attributes.
  • One of the items has a nested attribute (PromotionInfo), which contains other nested attributes. DynamoDB supports nested attributes up to 32 levels deep.
 
Primary key
When you create a table, in addition to the table name, you must specify the primary key of the table. The primary key uniquely identifies each item in the table, so that no two items can have the same key.
 
DynamoDB supports two different kinds of primary keys:
  • Partition key – A simple primary key, composed of one attribute known as the partition key. DynamoDB uses the partition key's value as input to an internal hash function.
  • Partition key and sort key – Referred to as a composite primary key, this type of key is composed of two attributes. The first attribute is the partition key, and the second attribute is the sort key In a table that has a partition key and a sort key, it's possible for multiple items to have the same partition key value. However, those items must have different sort key values.
    Note
    The partition key of an item is also known as its hash attribute. The term hash attribute derives from the use of an internal hash function in DynamoDB that evenly distributes data items across partitions, based on their partition key values.
    The sort key of an item is also known as its range attribute. The term range attribute derives from the way DynamoDB stores items with the same partition key physically close together, in sorted order by the sort key value.
     

    Secondary indexes

    You can create one or more secondary indexes on a table. A secondary index lets you query the data in the table using an alternate key, in addition to queries against the primary key. DynamoDB doesn't require that you use indexes, but they give your applications more flexibility when querying your data. After you create a secondary index on a table, you can read data from the index in much the same way as you do from the table.
    DynamoDB supports two kinds of indexes:
    • Global secondary index – An index with a partition key and sort key that can be different from those on the table.
    • Local secondary index – An index that has the same partition key as the table, but a different sort key.
    Each table in DynamoDB has a quota of 20 global secondary indexes (default quota) and 5 local secondary indexes.
     

    DynamoDB Streams

    DynamoDB Streams is an optional feature that captures data modification events in DynamoDB tables. The data about these events appear in the stream in near-real time, and in the order that the events occurred.
    Each event is represented by a stream record. If you enable a stream on a table, DynamoDB Streams writes a stream record whenever one of the following events occurs:
    • A new item is added to the table: The stream captures an image of the entire item, including all of its attributes.
    • An item is updated: The stream captures the "before" and "after" image of any attributes that were modified in the item.
    • An item is deleted from the table: The stream captures an image of the entire item before it was deleted.
     
    Each stream record also contains the name of the table, the event timestamp, and other metadata. Stream records have a lifetime of 24 hours; after that, they are automatically removed from the stream.
     
    You can use DynamoDB Streams together with AWS Lambda to create a trigger —code that runs automatically whenever an event of interest appears in a stream. For example, consider a Customers table that contains customer information for a company. Suppose that you want to send a "welcome" email to each new customer. You could enable a stream on that table, and then associate the stream with a Lambda function. The Lambda function would run whenever a new stream record appears, but only process new items added to the Customers table. For any item that has an EmailAddress attribute, the Lambda function would invoke Amazon Simple Email Service (Amazon SES) to send an email to that address.
     
    notion image
    Note
    In this example, the last customer, Craig Roe, will not receive an email because he doesn't have an EmailAddress.
     
    In addition to triggers, DynamoDB Streams enables powerful solutions such as data replication within and across AWS Regions, materialized views of data in DynamoDB tables, data analysis using Kinesis materialized views, and much more.
     

     
     

    DynamoDB API

     
    Topics
     

    Control plane

     
     
     
     

    Data plane

     
     
     

    DynamoDB streams

     
     
     

    Transactions

     
     
     
     
     
     
     
     
     
    .