Day1ã«éå¬ãããã "S.P.E.C. - Serverless Performance Empowerment Challenge" ã¨ããã¯ã¼ã¯ã·ã§ããããåãã§ããããï¼
â»éå¬æ¦è¦ã¯ãã¡ã
ãã£ããè¨ãã¨ISUCONã®ãããªããã©ã¼ãã³ã¹ãã¥ã¼ãã³ã°ã³ã³ãã¹ãã®ãµã¼ãã¼ã¬ã¹çã§ããåå è ã«ãé¡ã¨ãªãã¢ããªã±ã¼ã·ã§ã³ãé ãããæéå ã«ã¢ããªã®ããã©ã¼ãã³ã¹ãæ¹åãã¾ãããã³ããã¼ã«ã¼ã¸ã®å¿çæ§è½ã«ãã£ã¦ç²å¾ã¹ã³ã¢ãç®åºãããã¹ã³ã¢ã®åè¨ããã¼ã éã§ç«¶ãåãã¾ãã
ç§ã¯ãã®ä¼ç»ã®ãæä¼ãã¨ãã¦ãã©ã³ãã³ã°è¡¨ç¤ºããªã¢ã«ã¿ã¤ã ã«è¡ãããç°¡åãªåå è åããã¼ã¿ã«ã®å®è£ ããã£ã¦ãã¾ããã
ãããªã®â
å®è£ ã¯AWS Amplify & Amplify CLIã使ã£ã¦ãã¾ããããã¯ã¨ã³ãã¯AppSync(GraphQL)ã§ãã
AmplifyãGraphQLãçµé¨ã»ã¼çç¡ã®ç¶æ ããã®ã¹ã¿ã¼ãã§ãããããªãã¨ãã¤ãã³ãèªä½ãæç«ããã¨ããã¾ã§æã£ã¦ãããã®ã¯ä¸å±±ãã(@k1nakayama)ã®å¤å¤§ãªãµãã¼ãã«ããã¨ãããé常ã«å¤§ããã§ãããããã¨ããããã¾ãã
ã¬ãã¼ãããã°ã¯ãã®Workshopã®ä¸»å¬ã§ããå¼ç¤¾ã®ç §äº(@marcy_terui) ã以ä¸ã®è¨äºãæ¸ãã¦ããã®ã§ããã¡ããã覧ãã ããã
ãã®ããã°ã§ã¯ããã¼ã¿ã«ãµã¤ãã®å®è£ ããã£ã¦ã¿ã¦ã®ææ³ã¨ããæè¡çãªé¢ã§ã®æ¯ãè¿ããã¬ãã¼ããããã¨æãã¾ãã
è¿½è¨ (2019.11.22)
ã³ã³ãã¹ãã«ä½¿ç¨ããã½ã¼ã¹ãå ¬éãã¾ããã
ã¢ããªæ¦è¦
æ§æå³ã¯ãã¡ãã
ããããã·ã³ãã«ãªæ§æã«ãªã£ã¦ãã¾ãããã¼ã¿ã«å´ã§ã¯Mutationãè¡ããããã³ããã¼ã«ã¼ãåãã¼ã ã«å¯¾ãã¦å®è¡ãããã³ããã¼ã¯ã®çµæãæ¸ãè¾¼ã¿ã¾ãããã¼ã¿ã«å´ã§ã¯ãããSubscribeãã¦ç»é¢ã«åæ ãã¾ãã
ãã¼ã¿ã¢ã¯ã»ã¹ã®è¦ä»¶ã¨ï¼éå¬æ¥æç¹ã§ã®ï¼è¨è¨
ã©ã³ãã³ã°ãã¼ã¿ã«ããè¦ãã¨ããã¼ã¿ã¢ã¯ã»ã¹ã®è¦ä»¶ã¯ä»¥ä¸ã®2éãã§ãã
- ãã¼ã ãã¨ã«ç²å¾ç¹æ°ã®éè¨çµæã表示
- ãã¼ã ãã¨ã«ãã³ããã¼ã¯ã®å試è¡ãã¨ã®çµæã表示
ãã³ããã¼ã«ã¼ã¯ ãAPIãªã¯ã¨ã¹ãNåã1ã¤ã®ã»ããã¨ãã¦ãåãã¼ã ãã¨ãä¸å®ééãã¨ã«1ã»ãããå®è¡ã ã¨ããæåããã¾ãã競ææéãéãã¦ç¶ç¶çã«å®è¡ããã¾ãã
ãã³ããã¼ã¯ã®ã©ã³ãã³ã°ãã¼ã¿ã«ãªã®ã§ãå½ç¶ãã³ããã¼ã¯çµæãéè¨ãã¦ã©ã³ãã³ã°è¡¨ç¤ºããä»çµã¿ãå¿ è¦ã§ããã¾ãã競æè ãä»ã®ã¢ããªã®åé¡ç¹ãèå¯ããããã«ã¯ãã³ããã¼ã«ã¼ãå試è¡ã§åºåããçµæãé²è¦§ã§ãããã¨ãï¼éããªãå¿ é ã«è¿ãï¼è¦ä»¶ã¨è¨ãã¾ãããã£ã¦ããã³ããã¼ã¯ã®å試è¡ã«é¢ãããã¼ã¿ã¨ãã®éè¨çµæããã¼ã¿ã¹ãã¢ã¯æã£ã¦ããå¿ è¦ãããã¾ãã
éå¬æ¥æç¹ã®è¨è¨ã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ãã
- éè¨æ¸ã¿ãã¼ã¿ã¨ãã³ããã¼ã¯ãã¹ããªã管çãããã¼ãã«ãããããç¨æããç¬ç«ã«ç®¡çãã
- åãã¼ã ãã¨ã®ãã³ããã¼ã¯ã®éè¨ãæ ¼ç´ããããã®ãã¼ãã«
- ãã³ããã¼ã¯ã®ãã¹ããªãæ ¼ç´ããããã®ãã¼ãã«
- ãã³ããã¼ã«ã¼ã¯1ã»ããåã®çµæã2åã«åãã¦Mutationsãã
- çµæéè¨ã«åæ ããããã®Mutation
- 1ã»ããåã®ãã³ããã¼ã¯çµæã®ãã¹ããªãæããããã®Mutation
è¦å´ãããã¨
ä¸è¨ã®ãã¼ã¿ã¢ã¯ã»ã¹ã®è¦ä»¶ã«åºã¥ãã¦ãGraphQLã®ã¹ãã¼ãããã¼ã¿ã¹ãã¢ãã©ãè¨è¨ããã®ãï¼ã¨ããé¨åã«è¦æ ®ãã¾ãããã¾ããAmplify CLIã§ããæãã«æ§ç¯ã§ããç¯å²ã«ãéãããããäºåæ¤è¨¼ã®æ®µéã§ããªãé£åãã¾ãã...ããã®ã¸ãã®æ¤è¨äºé ã»å¶ç´ï¼ãã¨æéçãªç¶äºï¼ã¨æ¦ãã¤ã¤ã©ãç¾å®çãªå®è£ ã«è½ã¨ããã¨ããã®ã大ããªèª²é¡ã§ãã£ãããã«æãã¾ãã
åè¿°ã®è¨è¨ã¯ããããä¸çªæçã«ãããç¾å®è§£ã ã£ãã®ããªã¨æãã¾ãããè¨è¨ã¨ãã¦ã¯ã¾ã ã¾ã æ¹åä½å°ãããã¨æã£ã¦ãã¾ãã以éã§ãã©ãããã¹ãã ã£ãããã®ææãè¿°ã¹ã¾ã
ã©ã®ãããªæ¹åãèããããã
ã¾ã ç§ãèªä¿¡ãããããã§ã¯ããã¾ããããæ¹åæ¡ãæããã¨ãããªã以ä¸ã®ããã«èããã¨æãã¾ãã
æ¡1 - ãã¤ãã©ã¤ã³ãªã¾ã«ãã使ã
ãã³ããã¼ã«ã¼ããã1ååã®ãã³ããã¼ã¯çµæãããéè¨æ´æ°ç¨ã®Mutationãããã¹ããªè¿½è¨ç¨ã®Mutationãã®2ã¤ã«åãã¦æããå®è£ ã«ãªã£ã¦ããã®ã¯ç¡é§ãªæããããã¾ãã1åã§æ¸ã¾ããããè¨è¨ã®æ¹ããã¿ã¼ã«è¦ãã¾ãã
æã£åãæ©ãæ¹æ³ã¨ãã¦ã¯ããã¤ãã©ã¤ã³ãªã¾ã«ãã使ãã®ãè¯ãããã§ãã
ãã¹ããªè¿½å ã®Mutationã¨éè¨åæ ç¨ã®Mutationãããããå ¥åã®å¼æ°ã¯ã»ã¼å ±éãªã®ã§ãMutationãçµ±åãã¦ãã¤ãã©ã¤ã³ãªã¾ã«ãã®1段ç®ã«éè¨ç¨ã®VTLã2段ç®ã«ãã¹ããªè¿½å ç¨ã®VTLãæããã¨ã§ãã³ããã¼ã«ã¼ããã®Mutationã1åã§æ¸ãããã«ãªãã¾ãã
æ¡2 - DynamoDBãã¼ãã«ã1ã¤ã«çµ±åãã
è£ã®DynamoDBãã¼ãã«ã¯ãéè¨çµæç¨ã¨ãã¹ããªç¨ã§åé¢ãã¦ãã¾ããããããåä¸ã®ãã¼ãã«ã«çµ±åãã¾ãããã¼ãã«ãçµ±åãããã¨ã§ãã¼ãã£ã·ã§ã³ãã¨ã®I/Oãåããããã£ãã·ãã£ã®å©ç¨å¹çæ¹åãè¦è¾¼ãã¾ãã
ã¤ã³ããã¯ã¹ã®è¨è¨ã©ãããã®ãã¯æ©ã¿ã©ããã§ã¯ããã¾ãã...ããããã¯ãéè¨çµæãã®ã¢ã¤ãã ã¨ããã¹ããªãã®ã¢ã¤ãã ã "RecordType" ã®ãããªãã¼ã§åºå¥ããä»æ§ã¨ããGSIã®ãã¡ã²ã¨ã¤ã¯RecordTypeãHASH KEYã«æã¤ãããªè¨è¨ãæ¡ããã¨ã«ãªãã¨æãã¾ãã
ãããè¨è¨æ¡ã¨ãã¦ã¯å¿µé ã«ãã£ãã®ã§ããããªã¾ã«ãã®ãããã³ã°ãã³ãã¬ã¼ããã¯ããã¨ããGraphQLå´ãåãããæéãå«ãããå²ã¨é¢åãããããªã®ã§ãæéçãªç¶äºããæ¡ç¨ã¯è¦éãã¾ããï¼è² ãæãã¿ï¼
ã¾ã¨ã
ä»åã®ã¤ãã³ããéãã¦ã®ææ³ã§ãã
éçºçµé¨ãè±å¯ãªããã§ããªããæ¡ç¨ããæè¡ã¹ã¿ãã¯ã«ãæãããªãç¶æ ããã®ã¹ã¿ã¼ãã§ããããå®éã«ã¢ããªãç«ã¡ä¸ãã¦ä½¿ã£ã¦ãããã¨ããã¾ã§ã®ä½é¨ãéããã®ã¯é常ã«è¯ãçµé¨ã«ãªãã¾ããã
ç¹°ãè¿ãã«ãªãã¾ãããæ²ããªãã«ãéçºãããä»°ããã®ã¯ä¸å±±ãã(@k1nakayama)ã®ãå©åãã£ã¦ã®ãã¨ã§ããæ¬å½ã«ãããã¨ããããã¾ããã
ã¾ããç §äºãã(@marcy_terui)ãç´ æ´ãããä¼ç»ããããã¨ããããã¾ããã次åããã®ä¼ç»ããããã¯ã¾ã ããããªãã§ãããããã°æ¯éã¾ãæºãããããªã¨æããä¼ç»ã§ããã次åã¾ã§ã«ä½åã«ãé¢ããããããã®ã¹ãã«ã身ã«çããã...!
æå¾ã«ãS.P.E.Cã«ãåå ããã ããåå è ã®çæ§ãæ¬å½ã«ãããã¨ããããã¾ããããã®å ´ããåããã¦æè¬ç³ãä¸ãã¾ãã 決ãã¦è¯ãUI/UXã®ã¢ããªã§ã¯ãªãã£ãã¨æãã¾ãããä¼ç»ã¨ãã¦ãæºè¶³ããã ãããªãã°éå¶å´ã®äººéã¨ãã¦ã¯å¹¸çã§ããä»åéçºãããã¼ã¿ã«ã®ã½ã¼ã¹ã¯ãªãæ©ã§å ¬éãããã®ã§ãããã¾ã æ´åãè¡ãå±ãã¦ãããããããã°ããå¾ ã¡ä¸ãã..ð
ä½è«
ä½è«ã¨ãã¦ãè¨è¨æ¹åæ¡ã®(3)ã追è¨ãã¦ããã¾ãã
è¦è§£ã¨ãã¦ã¯å´ä¸å¯ãã®ãªã®ã§ä½è«æ±ãã¨ãã¾ãããããã®æ¡ã«è¿ã話ã£ã¦å²ã¨ãããããã¿ã¼ã³ã ãããªã¨æãã¾ããã®ã§åèã¾ã§ã«ã
ãµã¼ãã¼ã¬ã¹ã®ä¸çãã¾ã ã¾ã ç§ã«ã¯é£ãã...ã
â» ... ä»åã®ã¢ããªã®äºæ ã ã¨ä»¥ä¸ã§è¿°ã¹ãæ¡(3)ã¯ãã¾ãã¤ã±ã¦ãªãã ãã...ã¨ããã ãã®è©±ãªã®ã§ãè¦ä»¶ãæ§æãéãã°ãããæ£è§£ã®ã²ã¨ã¤ã«ãªãããã¨ã¯æã£ã¦ã¾ã
æ¡3 - éè¨è¨ç®ã¨çµæã®æ°¸ç¶åå¦çãå°ç¨ã®lambdaã«åãé¢ãã¦è¿½å å®è£ ãã
éè¨å¦çã¯ããã¹ããªãã¼ãã«ãå¤é¨ã®scheduled lambdaããå®æçã«å©ãã¦è¨ç®ããlambdaããéè¨çµæãã¼ãã«ã«æ ¼ç´ããããã«ããããã¨ããèãæ¹ã§ãã
è¨ç®éå§ãããªã¬ã¼ããå½¹ç®ã¨éè¨ã®å®å¦çãéè¨ç¨lambdaã«åãåºããã¾ãããã®ããããã³ããã¼ã«ã¼å´ããã®mutationã¯éè¨æ´æ°ç¨Mutationãä¸è¦ã«ãªããã¹ããªè¿½è¨ã®1ååã ãã§æ¸ãããã«ãªãã¾ãã
ãã®æ¡ã®æ¯éã«ã¤ãã¦ã¯ç §äºã«ãè¦è§£ãèãã¦ã¿ã¾ããããå¾®å¦ãã¨ã®ãã¨ã§ãããAppSyncãå«ãããã³ãã¨ã³ãã¯ã§ããã ãã·ã³ãã«ã«å©ç¨ãã¹ãã§ããããã¸ãã¯ã®è¤éãã¯ã§ããã ãããã¯ã¨ã³ããµã¼ãã¹ã«å¯ãã¦ããè¨è¨ã®ã»ããæ£è§£ãªã®ã§ã¯ãªããï¼ãã¨ã®åçãããã¾ããããªãã»ã©ããããããªã...ã
â» ... ç¥ã£ã¦ãæ¹ã«ã¨ã£ã¦ã¯å²ã¨å½ç¶ãã¨æãã¾ããããã®lambda functionã®ä¸ã§DynamoDBãscanããã®ã¯ã¢ã³ããã¿ã¼ã³ã§ããè¨ç®éããã¼ã¿éã«æ¯ä¾ããå®è£ ã«ãªã£ã¦ãã¾ã大å¤éå¹çã§ãããç¡é§ãªscanã¯ããã¹ãã§ã¯ããã¾ãããè¨è¨æ¬¡ç¬¬ã§scanã¯åé¿å¯è½ã§ãã
ç§ãªãã®è¦è§£ã¨ãã¦ã¯ããã®æ¡ã®ã¡ãªããã¯ä»¥ä¸ã®éãã¨èãã¾ãããããã代æ¿æ¡ããã£ãããæ¬ã¢ããªã®è¦ä»¶ã«ç §ããã¦ãã»ã©ãããããªãããã ã£ããã§ãæ¡ç¨ã®æ義ãèãã¨æã£ã¦ãã¾ãã
- UIå´ã§ãã©ã³ãã³ã°ã¨ãã¹ããªã®æ´æ°é »åº¦ãåå¥ã«æ±ããããã¨ãã追å è¦ä»¶ãæ³å®ãå¾ãå ´åã«æè»æ§ããã
- DynamoDBã®è² è·ã軽æ¸ã§ããï¼ãã¹ããªã1件追å ããããã¨ã«éè¨å¦çãå®è¡ããå®è£ ã¨æ¯ã¹ãå ´åï¼
(1)ã¯ãããæ¬å½ã«ãã®è¦ä»¶ãæ³å®ãããã®ãªãéè¨lambdaã®æ¤è¨ä¾¡å¤ãããã¨æãã¾ããããå®éã«ã¯ãæ³å®ããå¿ è¦ã®ãªãéå°æ³å®ãã§ãããããã¦ã¼ã¶ã¼ãç®ã§è¿½ããç¨åº¦ã®ãé©åº¦ãªé度ã§ãæç»ãæ´æ°ã§ãã¦ããã°UIã¨ãã¦ã¯æä½éOKã ã¨æã£ã¦ã¾ããã¾ããæç»æ´æ°ã®é »åº¦ãã³ã³ããã¼ã«ããããã°ããã³ããã¼ã«ã¼å´ã§kinesisãåã¾ãã¦ãããåä½ã«ã¾ã¨ãã¦ããmutationãæãè¾¼ãããã«ãããã¨ããã¢ããã¼ããèãããã¾ããéè¨lambdaãåã¾ããå¿ ç¶æ§ã¯ãªãã§ãã
(2)ã¯ãä»ã®å®è£ ã¨æ¯ã¹ãå ´åã ã¨ãã»ã©å¤§ããªã¡ãªãããæãããã¾ããããã£ã¦å´ä¸ã§ãã
â» ... ä»ã®å®è£ ã¯ãéè¨å¦çãèªä½ãä¸è¦ã«ãªãããã«è¨è¨ãã¦ãã¾ãããã¼ã ã®ç²å¾ã¹ã³ã¢ã®æ´æ°ã¯ãUpdateItemã§ãåè¨ã¹ã³ã¢ã®å·®åæ´æ°ããè¡ããã¨ã«ãã£ã¦å®ç¾ãã¦ãã¾ãã
æ©æ¬ æå¼¥(è¨äºä¸è¦§)
ããã¼ã¸ããµã¼ãã¹é¨
å 製éçºä¸å¿ã«ãã£ã¦ã¾ããæ®æ®µã¯ãµã¼ãã¼ã¬ã¹é¢é£ã CDK ã触ããã¨ãå¤ãã§ã