Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

【旧版・説明欄参照ください】 サーバーレスアプリケーション向きの DB 設計ベストプラクティス

35,541 views

Published on

【2019/09/12 追記】
この資料は旧版であり、最新版が存在します。
2019/09/12 にアップロードしたものをご参照ください
最新版 → https://www.slideshare.net/AmazonWebServicesJapan/db-20190905

--------(元の文)-------------------
2019/05/09 に #AWSLoft Tokyo で開催されたイベント、「イチから理解するサーバーレスアプリ開発」における講演資料の一つです。

・サーバーレスアプリケーションにおいて Amazon DynamoDB が利用しやすい理由
・RDB と DynamoDB の設計プロセス・考え方の対比・明文化
・実例に沿った DynamoDB の設計プロセス解説とサンプル例題

などを含みます。

イベント: https://understandingbasicserverlessse.splashthat.com/

Published in: Technology
  • ⇒ www.WritePaper.info ⇐ is a good website if you’re looking to get your essay written for you. You can also request things like research papers or dissertations. It’s really convenient and helpful.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • I’ve personally never heard of companies who can produce a paper for you until word got around among my college groupmates. My professor asked me to write a research paper based on a field I have no idea about. My research skills are also very poor. So, I thought I’d give it a try. I chose a writer who matched my writing style and fulfilled every requirement I proposed. I turned my paper in and I actually got a good grade. I highly recommend ⇒ www.HelpWriting.net ⇐
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hi there! I just wanted to share a list of sites that helped me a lot during my studies: .................................................................................................................................... www.EssayWrite.best - Write an essay .................................................................................................................................... www.LitReview.xyz - Summary of books .................................................................................................................................... www.Coursework.best - Online coursework .................................................................................................................................... www.Dissertations.me - proquest dissertations .................................................................................................................................... www.ReMovie.club - Movies reviews .................................................................................................................................... www.WebSlides.vip - Best powerpoint presentations .................................................................................................................................... www.WritePaper.info - Write a research paper .................................................................................................................................... www.EddyHelp.com - Homework help online .................................................................................................................................... www.MyResumeHelp.net - Professional resume writing service .................................................................................................................................. www.HelpWriting.net - Help with writing any papers ......................................................................................................................................... Save so as not to lose
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THAT BOOKS/FILE INTO AVAILABLE FORMAT - (Unlimited) ......................................................................................................................... ......................................................................................................................... Download FULL PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... accessibility Books Library allowing access to top content, including thousands of title from favorite author, plus the ability to read or download a huge selection of books for your pc or smartphone within minutes Christian, Classics, Comics, Contemporary, Cookbooks, Art, Biography, Business, Chick Lit, Children's, Manga, Memoir, Music, Science, Science Fiction, Self Help, History, Horror, Humor And Comedy, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Download or read that Ebooks here ... ......................................................................................................................... DOWNLOAD FULL PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

【旧版・説明欄参照ください】 サーバーレスアプリケーション向きの DB 設計ベストプラクティス

  1. 1. B 2019.05.09 Amazon Web Services Japan K.K. Akihiro Tsukada, Startup Solutions Architect, Manager
  2. 2. • # # # • # • # # # 2
  3. 3. • D A R • A D • B 3
  4. 4. 9 B A 9 t D S p z O • 9 B A 9 oml a • • 9 B A 9 e dg W O k s n 9 B 0 1 ci[ • - 1 9 . 9 B A 9 2 1 2 p y • A 9 ] h [| 9 1 1 • A 1 v PL A 9 rsb] 4
  5. 5. S LP D A B [ OL W ] 5
  6. 6. AWS Lambda 7
  7. 7. AWS Lambda Amazon RDSAmazon Aurora Amazon DynamoDB Amazon ElastiCache Amazon Neptune ...etc 8
  8. 8. ., 9 b AWS Lambda ., @ a D B R L ., 5 01 2 Amazon RDS Amazon Aurora 9
  9. 9. a S AWS Lambda Amazon RDS Amazon Aurora D L b L M 1 1 B 1 d B R B . . … ! 10
  10. 10. Private subnet . B a IbD i L P DN V R S E D 2 C I . L P ICE . C e Id I AWS Lambda Amazon Aurora Amazon RDS VPC ✕ Any Subnet Elastic network interface 11
  11. 11. Private subnet .1 0. aBb RN LI L B L P L PV 2 B C .1 0. D d E AWS Lambda Amazon Aurora Amazon RDS VPC Any Subnet Elastic network interface 12
  12. 12. DuoB • n D V S m pt uy • D ACPS m g m Oz B D • elc am - e U id Amazon DynamoDBAWS Lambda … ! 14
  13. 13. B u eK 1 t m a • r P • r a a B K S D • o m • r A Q P • 1 P ) ( ) 1 ( )( IP )( + ( +( : K D a • + 1 IP ) • i a P r c r • r a I D https://docs.aws.amazon.com/ja_jp/amazondynamodb/latest/developerguide/best-practices.html ao aP n y m B 16
  14. 14. B o R O Q • S M O B tf R Q R • l e • tfR Q R B i n a • pf o R Q a L • L D c O E • R 17
  15. 15. B c IET • B Ic • o E t B t R • Re I t • m I • I ED B aI • B I • y I • n I • B 18
  16. 16. D B 19
  17. 17. B c IET • B Ic • o E t B t R • Re I t • m I • I ED B aI • B I • y I • n I • B 20
  18. 18. k E (from re:Invent 2018 session) • c • . 1 i E • B e d b R A a • b d 21
  19. 19. B c IET • B Ic • o E t B t R • Re I t • m I • I ED B aI • B I • y I • n I • B 22
  20. 20. F IMKDP R E DI DI I Use Case C C 2 A2 2 # B C A2 2A A2 2A A2 2A A2 2A A2 2A 2 A2 2A A. A2 2A 2 A2 2A # 2A 2A C 2A 2 C A2 A2 23
  21. 21. B c IET • B Ic • o E t B t R • Re I t • m I • I ED B aI • B I • y I • n I • B 24
  22. 22. .TABLE Primary Key Attributes PK SK, GSI-3-PK GSI-1-PK GSI-2-PK Acr TargetACR AcrInfo1 AcrInfo2 EbookAsin ABOOKACR1 ABOOKACR1-v0 ABOOK-ASIN1 ABOOK-SKU1 MAP-EBOOKACR1 SyncFileAcr ABOOK-ASIN1 ABOOKACR1#TRACK#1 ABOOK-ASIN1 ABOOK-SKU1 ABOOKACR1#TRACK#2 ABOOK-ASIN1 ABOOK-SKU1 EBOOKACR1 EBOOKACR1 EBOOK-SKU1 ASIN 25
  23. 23. .GSI1 GSI Partition Key Projected Attributes GSI-1-PK Acr (Primary Table PK) TargetACR (Primary Table SK) ABOOK-ASIN1 ABOOKACR1 ABOOKACR1-v1 ABOOKACR1#TRACK#1 ABOOKACR1#TRACK#2 SyncFileAcr ABOOKACR1 MAP-EBOOKACR1 EBOOK-SKU1 ABOOKACR1 EBOOKACR1 GSI2 GSI Partition Key Projected Attributes GSI-2-PK Acr (Primary Table PK) TargetACR (Primary Table SK) ABOOK-ASIN1 ABOOKACR1 MAP-EBOOKACR1 ABOOK-SKU1 ABOOKACR1 ABOOKACR1-v0 ABOOKACR1#TRACK#1 ABOOKACR1#TRACK#2 GSI3 GSI Partition Key Projected Attributes TargetACR (Primary Table SK) Acr (Primary Table PK) TargetACR (Primary Table SK) ABOOKACR1-v0 ABOOKACR1 ABOOKACR1-v0 MAP-EBOOKACR1 ABOOKACR1 MAP-EBOOKACR1 ABOOKACR1#TRACK#1 ABOOKACR1 ABOOKACR1#TRACK#1 ABOOKACR1#TRACK#2 ABOOKACR1 ABOOKACR1#TRACK#2 EBOOKACR1 EBOOKACR1 EBOOKACR1 26
  24. 24. B c IET • B Ic • o E t B t R • Re I t • m I • I ED B aI • B I • y I • n I • B 27
  25. 25. # Entity Use Case Lookup parameters Table / INDEX Key Conditions Filter Conditions 1 CompanionMapping getCompanionMappingsByAsin audiobookAsin/ebookSku GSI2 GSI-2=ABOOK-ASIN1 None 2 CompanionMapping getCompanionMappingsByEbookAn dAudiobookContentId ebookAcr/sku,version,format or audiobookAcr/asin,version,format GSI-3 on TargetACR attribute OR PrimaryKey on Table GSI-3=MAP-EBOOKACR1 version=v and format=f 3 CompanionMapping getCompanionMappingsFromCache ebookAcr/sku,version,format or audiobookAcr/asin,version,format GSI-3 on TargetACR attribute OR PrimaryKey on Table GSI-3=MAP-EBOOKACR1 version=v and format=f 4 CompanionMapping getCompanionMappings syncfileAcr, ebookAcr?, audiobookAcr? GSI1 GSI-1=SyncFileAcr None 5 CompanionMapping getCompanionMappingsAvailable ebookAcr, audiobookAcr Primary Key on Table Acr=ABOOKACR1 and TargetACR beginswith "MAP-" 6 AcrInfo getACRInfo acr Primary Key on Table Acr=ABOOKACR1 and TargetACR beginswith "ABOOKACR1-v" 7 AcrInfo getACRs acr / asin,version,format Primary Key on Table Acr=ABOOKACR1 version=v and format=f 8 AcrInfo getACRInfos acr Primary Key on table Acr=ABOOKACR1 and TargetACR beginswith "ABOOKACR1" 9 AcrInfo getACRInfosBySKU sku GSI2 GSI-2=ABOOK-SKU1 10 AudioProduct getAudioProductsForACRs acr Primary Key on table Acr=ABOOKACR1 and TargetACR beginswith "ABOOKACR1" 11 AudioProduct getAudioProducts sku, version, format GSI2 GSI-2=ABOOK-SKU1 version=v and format=f 12 AudioProduct deleteAudioProductsMatchingSkuV ersions sku, version GSI2 GSI-2=ABOOK-SKU1 version=v 13 AudioProduct getChildAudioProductsForSKU sku GSI2 GSI-2=ABOOK-SKU1 14 Product getProductInfoByAsins asin GSI1 GSI-1=ABOOK-ASIN1 15 Product getParentChildDataByParentAsins asin GSI1 GSI-1=ABOOK-ASIN1 16 AudioFile getAudioFilesForACR acr Primary Key on table Acr=ABOOKACR1 and TargetACR beginswith "ABOOKACR1#" 28
  26. 26. D e m a IET • mD e m • I D E R • y a R m yB m I • ot I B • R I m D c I • D I • R I m B n • m I • D I 29
  27. 27. B D 30
  28. 28. B B D 31
  29. 29. E ID: : AWS Loft Tokyo: : : ID 2 DynamoDB AWS Loft Tokyo yy/3/4 #DynamoDB #Serverless 14 AWS Loft Tokyo yy/5/9 #Serverless #Lambda #Design 33 API Night AWS Loft Tokyo yy/6/23 #WebAPI #JWT #APIGateway #Auth #OAuth #OIDC #Cognito > >><< < 33
  30. 30. D e m a IET • mD e m • I D E R • y a R m yB m I • ot I B • R I m D c I • D I • R I m B n • m I • D I 34
  31. 31. id (PK) name venue_id (FK) date Events id (PK) name Tags event_id (PK, FK) tag_id (PK, FK) EventTags id (PK) name address Venues -- SQL -- : SELECT e.id, v.name... FROM Events e JOIN Venues v ON v.id = e.venue_id JOIN EventTags et ON et.event_id = e.id JOIN Tags t ON t.id = et.tag_id WHERE v.name = :vname AND t.name = :tname 35
  32. 32. 2 2 2 Use Case . . . . . . . . . . . . . . . # . . . . . . . 36
  33. 33. i n t hc et Ql tTABLE Partition Key Attributes {EventID} {EventName} {VenueName} {TagName1, ...} {yyyy-mm-dd} ... ... ... ... ... • . . . .3 GB I S G D +- 3 . Q G • +- 3 i n t hc m t lma t Sr c • QE +- 3 Q F D vQ D u +- 3 QE . . . -/ . . S D BS y F 38
  34. 34. e b l cTABLE Primary Key Attributes Partition Key GSI-1-PK GSI-2-PK GSI-3-PK GSI-4-PK {EventID} {EventName} {VenueName} {TagName1, ...} {yyyy-mm-dd} ... ... ... ... ... • / + / . 0- 2 0-. 3.2 G • S u b le b r a b b • l o y x b dn c Q I 39
  35. 35. -
  36. 36. GTABLE Primary Key Attributes PK, GSI-1-SK SK GSI-1-PK GSI-2-PK ID DataType DataValue VenueName VenueAddress {EventID} EventName {EventName} {EventID} VenueID {VenueID} {EventID} Date {yyyy-mm-dd} {EventID} Tag_{TagName} Tag_{TagName} {VenueID} VenueInfo {VenueName} {Address} • S 3 • . I G • 3 1 41
  37. 37. 3 3GSI1 GSI Partition Key Projected Attributes GSI-1-PK GSI-1-SK (Primary Table SK) DataValue ID DataType VenueAddress {EventName} {EventID} EventName {VenueID} {EventID} Venue {yyyy-mm-dd} {EventID} Date Tag_{TagName} {EventID} Tag_{TagName} GSI2 GSI Partition Key Projected Attributes GSI-2-PK (Primary Table PK) VenueName ID VenueAddress {VenueName} {VenueID} {Address} • . . 42
  38. 38. TABLE Primary Key Attributes PK, GSI-1-SK SK GSI-1-PK GSI-2-PK ID DataType DataValue VenueName VenueAddress E123 EventName DynamoDB E123 VenueID V32 E123 Date yy/3/4 E123 Tag_#DynamoDB Tag_#DynamoDB E123 Tag_#Serverless Tag_#Serverless E145 EventName E145 VenueID V32 E145 Date yy/5/9 E145 Tag_#Serverless Tag_#Serverless E145 Tag_#Lambda Tag_#Lambda E145 Tag_#Design Tag_#Design V32 VenueInfo AWS Loft Tokyo • . .4 • . 4 2 E 51 4 3 43
  39. 39. TABLE Primary Key Attributes PK, GSI-1-SK SK GSI-1-PK GSI-2-PK ID DataType DataValue VenueName VenueAddress E123 EventName DynamoDB E123 VenueID V32 E123 Date yy/3/4 E123 Tag_#DynamoDB Tag_#DynamoDB E123 Tag_#Serverless Tag_#Serverless E145 EventName E145 VenueID V32 E145 Date yy/5/9 E145 Tag_#Serverless Tag_#Serverless E145 Tag_#Lambda Tag_#Lambda E145 Tag_#Design Tag_#Design V32 VenueInfo AWS Loft Tokyo 1 3 Query(ID = :eventId) . 3 : . Table Query(ID = "E123") 44
  40. 40. TABLE Primary Key Attributes PK, GSI-1-SK SK GSI-1-PK GSI-2-PK ID DataType DataValue VenueName VenueAddress E123 EventName DynamoDB E123 VenueID V32 E123 Date yy/3/4 E123 Tag_#DynamoDB Tag_#DynamoDB E123 Tag_#Serverless Tag_#Serverless E145 EventName E145 VenueID V32 E145 Date yy/5/9 E145 Tag_#Serverless Tag_#Serverless E145 Tag_#Lambda Tag_#Lambda E145 Tag_#Design Tag_#Design V32 VenueInfo AWS Loft Tokyo 1 3 Query(DataValue = :tagName) . : . GSI1.Query(DataValue = "Tag_#Serverless") 45
  41. 41. dcj nlr Use Case Parameters Table/Index API & Key Conditions . DI I. DI . DI1- G C G B 4 G 1- ) ( DI1 . DI I. DI . DI2 C 1 4 G - I B ) ( DI2 C . DI I. DI D 2 C 1 1 4 G D 2 C ) ( D 2 C 4 G - I B ) ( D 1 . DI I. DI - I 1 4 G - I B ) ( I # . DI I. DI 1 4 G - I B ) (I 2 C I . DI1- G C G B 4 G 1- ) ( DI1 D I D . DI1- G C G B G C G B I1I C 1- ) ( DI1 D - I F ) D 1- I1I C 1- ) ( D 1 D - I F ) D 1D=E • i fe f B 1D bp N Sh gb m aV TP I1I C I I:?1I C 4 G : D Qbus • / BI G ,ED I ED GE :I ED . FG ED bot 46
  42. 42. A • . . . a . 1 B4 • y 2 D • n 3 . . . . o o • m z o 3 48
  43. 43. s ztL P • 9 B A 9 rpo [d • A 9 h cg ]a • 9 B A 9 h cg ]a n 9 B 0 1 l • - 1 9 . 9 B A 9 2 1 2 s • A 9 bD ibkm 9 1 1 • A 1 y S OW A 9 v e Dm 49
  44. 44. D GI1 E A S D GI TABLE Primary Key Attributes PK, GSI-1-SK SK GSI-1-PK ID DataType DataValue1 DataValue2 {EventID} EventName {EventName} {EventID} VenueInfo {VenueName} {Address} {EventID} Date {yyyy-mm-dd} {EventID} Tag_{TagName} Tag_{TagName} • . - D 52
  45. 45. -1 .TABLE Primary Key Attributes PK, GSI-1-SK SK GSI-1-PK ID DataType DataValue1 DataValue2 E123 EventName DynamoDB E123 VenueInfo AWS Loft Tokyo E123 Date yy/3/4 E123 Tag_#DynamoDB Tag_#DynamoDB E123 Tag_#Serverless Tag_#Serverless E145 EventName E145 VenueID AWS Loft Tokyo E145 Date yy/5/9 E145 Tag_#Serverless Tag_#Serverless E145 Tag_#Lambda Tag_#Lambda E145 Tag_#Design Tag_#Design 53
  46. 46. 1 -. 1 -.GSI1 GSI Partition Key Projected Attributes GSI-1-PK GSI-1-SK (Primary Table SK) DataValue ID DataValue1 DataValue2 {EventName} {EventID} EventName {VenueID} {EventID} Venue {yyyy-mm-dd} {EventID} Date Tag_{TagName} {EventID} Tag_{TagName} {VenueName} {EventID} {VenueName} {Address} 54
  47. 47. (BB =I _iurmv Use Case Parameters Table/Index API & Key Conditions G ED E G E) G E. C= C 1 C . G E. G ED E G ED) G E/ - . 1 C E G E/ G ED E G ED) / - . 1 C E G / G ED E G ED) E - . 1 C E E # G ED E G ED) - . 1 C E E / D E D) G E. C= C 1 C . G E. E B = D =E E ) G E. C= C - E.E . G E E B . :A • T o w h a i e nr V • tl fd y xP CAD A D y Q NpS sg b 55
  48. 48. 2 U m E SVg I d 1 - 1 - . d nm A- . B d , . e x um • V I E EU G E U • G 2 d I a S a m d • i s • A my t e VB • ir v p NS S G E 56
  49. 49. - 2. TABLE Primary Key Attributes PK SK, GSI-1-PK GSI-1-SK EventID DataType DataValue {EventID} EventName {EventName} {EventID} VenueName {VenueName} {EventID} VenueAddress {VenueAddress} {EventID} Date {yyyy-mm-dd} {EventID} Tag_{n} {TagName} 58
  50. 50. 2 - . TABLE Primary Key Attributes PK SK, GSI-1-PK GSI-1-SK EventID DataType DataValue E123 EventName DynamoDB E123 VenueName AWS Loft Tokyo E123 VenueAddress E123 Date yy/3/4 E123 Tag_1 #DynamoDB E123 Tag_2 #Serverless E145 EventName E145 VenueName AWS Loft Tokyo E145 VenueAddress E145 Date yy/5/9 E145 Tag_1 #Serverless E145 Tag_2 #Lambda E145 Tag_3 #Design 59
  51. 51. 2 . -GSI1 GSI Partition Key Projected Attributes GSI-1-PK GSI-1-SK (Primary Table SK) DataType DataValue EventID EventName {EventName} {EventID} VenueName {VenueName} {EventID} VenueAddress {VenueAddress} {EventID} Date {yyyy-mm-dd} {EventID} Tag_{n} {TagName} {EventID} 60
  52. 52. :: TS Use Case Parameters Table/Index Key Conditions = = = A = - 1 A 12 = = = = = A = 1 . 1=1 A: = 1 = 1 = 1 = = = A 1 . 1=1 A: 1 1 1 # = = = A 1= . 1=1 A: 1= 1= 1= = = = A 1 4825 6 57 3 1 1 = 1 A 1 1 1 = 1 A = = A = • P = = A 1 I N P BDaG V E 61
  53. 53. . - N . . N PB GSI1 GSI Partition Key Projected Attributes GSI-1-PK GSI-1-SK (Primary Table SK) DataType DataValue EventID EventName {EventName} {EventID} VenueName {VenueName} {EventID} VenueAddress {VenueAddress} {EventID} Date {yyyy-mm-dd} {EventID} Tag_{n} {TagName} {EventID} • 2. BS . b KT Query(DataType = begins_with("Tag_") and DataValue = :tagName) . _ . B AN • Query(DataType = Tag_{n} and DataValue = :tagName) dBS Pe TE . a N 62

×