node.js
â»ãã®ããã°ã¯ã4/30(ç«) 19:00~éå¬ã®ãJAWS-UGæå¹ ãªã³ã©ã¤ã³ããããä¼ #95ãã«ã¦è¨è¼ããå 容ã«ãªã£ã¦ããã¾ãã jawsug-sapporo.connpass.com ã¯ããã« 4/24(æ°´)ã«ãNode.jsã®ææ°çã§ããNode.js 22ããªãªã¼ã¹ããã¾ããã ããã§ä»åã¯ããã£ããNodâ¦
ä»åã®å 容 AWS LambdaãAWS SDK for JavaScript v3(以ä¸ãv3ãã¨è¨è¼)ã§æ¸ã ç¾å¨ã¡ã¸ã£ã¼(ã ã¨æã)ã®ã¯AWS SDK for JavaScript v2(以ä¸ãv2ãã¨è¨è¼) ãµã³ãã«ã¨ãã¦ãDynamoDBã®ãã¼ã¿ãåå¾ããã³ã¼ããæ¸ã åèãµã¤ã AWS SDK for JavaScript v3 (AWSâ¦
æ¬é¡ JavaScriptã®ä»æ§ã§ããECMAScript(=ES)ã«ã¤ãã¦ãããããææ°çã®ES2022ãæ¿èªããããã¨ããã®ãICSããã®ããã°(ãåèãµã¤ããåç §)ã§ç¥ãã¾ããã ãªã®ã§ä»åã¯ãES2022ã§æ£å¼æ¡ç¨ãããæ©è½ã«ã¤ãã¦ãã³ã¼ãä¾ãæãã¦èª¬æãããã¨æãã¾ãã ãªâ¦
ã¯ããã« å æ¥(2021/6/28)ããNodeå¦å 36æéç® ãªã³ã©ã¤ã³ãã¨ããã¤ãã³ãã§ãNode16ã®æ°æ©è½ã®ç´¹ä»ãã¨ããå 容ã§çºè¡¨ããã¦é ãã¾ããã(è¦è´ï¼ãªã¢ã¯ã·ã§ã³ãã ãã£ãæ¹ã ããããã¨ããããã¾ãã) nodejs.connpass.com ãã®ä¸ã®çºè¡¨è³æã§Sleepæ©è½(â¦
ã¯ããã« 2021å¹´4æã«ãNode.jsã®version10ããµãã¼ãçµäºã¨ãªããAWSããããLambdaã®ãã¼ã¸ã§ã³ãæ´æ°ãã¦ãã ãããã¨ããæ¡å ãæ¥ã¦ã¾ããã ããã¦ãããã¨åãã¿ã¤ãã³ã°ã§version16ããªãªã¼ã¹ããã¾ããã ä»å¹´ã®10æã«ã¹ãã¼ã¿ã¹ãActiveã«ãªãã¾ãâ¦
ã¯ããã« ã¤ãå æ¥(2/3)ãAWS LambdaãNode.js 14ã®ãµãã¼ããéå§ãã¾ããã AWS Lambda ã Node.js 14 ã®ãµãã¼ããéå§ Node.js 10ã4ææ«ã§EOL(æ°è¦Lambdaä½æã¯3ææ«ãããã¾ã§)ã«ãªãã®ã§ããã®ã¿ã¤ãã³ã°ã§Node.js 14(ã¾ãã¯12)ã¸ã®ç§»è¡ãæ¤è¨ãã¦ãâ¦
æ¦è¦ JavaScriptã®ã½ã¼ã¹ãåä½ãã¹ãããéãJestã使ã£ã¦ãã人ãå¤ãã¨æãã¾ãã jestjs.io ã§ãããé¢æ°ã®ãã¹ããããéã«ããã®é¢æ°ãå¼ã¶å¥ã®é¢æ°ãä¸æçã«mocké¢æ°ã«ãããå ´åãããã¾ãã Jestã§ã¯ããããspyOn()ã¨ããã¡ã½ããã使ããã¨ã§å®â¦
ã¯ããã« æ°å¹´ããã¾ãã¦ããã§ã¨ããããã¾ãã(ãã1/25ã ãã©) å»å¹´ãããããããã¾ããããä»å¹´ãæ£æä¼ã¿ãçµããããããã平常é転ã«ãæ £ãã¦ããã®ã§ãããã°ã®æ¹ãéå§ãããã¨æãã¾ããã ã§ãæ°å¹´ä¸çºç®ã®ãã¿ã§ãããæåã¯å®å®ã®Serverless Fâ¦
æ¦è¦ Lambdaã®ã½ã¼ã¹ã³ã¼ããæ¸ããéã«ããã¼ã«ã«ç°å¢ã§åä½ãã¹ããå®æ½ããå ´åãããã¨æãã¾ãã å®ã¯ä»ã¾ã§æ¥åã§ã¯ãããã¾ã§åä½ãã¹ããæ¸ãã¦ããªãã£ãã®ã§ãã*1ãä¸åº¦æ¸ãã¦ã¿ãããããã便å©ã ãã¨æããæ¬è °ãå ¥ãã¦åä½ãã¹ããåå¼·ãå§ãâ¦
ã¯ããã« JavaScriptã®éåæå¦ç(Promiseã¨ãasync/await)ã«ã¤ãã¦ãä»å¹´ã®1æã«ãä¸è¨ã®ããã°ãæ¸ãã¾ããã makky12.hatenablog.com ããæè¿AWS Lambdaã®éåæå¦çãJavaScriptã§æ¸ãã¦ãã¦ãã¡ãã£ã¨ãããããã£ã¦ãã¾ã£ããã¨ããã£ãã®ã§ãåå¿é²â¦
æ¦è¦ Serverless Frameworkã§ããã±ã¼ã¸ã³ã°ããããã¤ãè¡ãéã«ãã¡ã¢ãªä¸è¶³ã§å¤±æãããã¨ãããã¾ãããã®å ´åã®å¯¾è±¡æ¹æ³ã§ãã serverless.com ç¾è±¡ å æ¥ãæ¥åã§éçºãããµã¼ãã¼ã¬ã¹SPAãServerless Frameworkã§ãããã¤ãããã¨ããããããã±ã¼ã¸ã³â¦
ååã¯Promiseã«ã¤ãã¦æ¸ãã¾ãããããã®ç¶ãã§ä»åã¯async/awaitã«ã¤ãã¦ã ãåèã async/await å ¥éï¼JavaScriptï¼ asyncã¨ã¯ éåæé¢æ°ãå®ç¾©ããé¢æ°å®£è¨ã®ãã¨ã asyncé¢æ°ã¯ã以ä¸ã®åä½ãããã Promiseãè¿ã å¤ãreturnããã¨ãPromiseã¯ãããâ¦