è¿½è¨ (4/15)
ç¾å¨ã¯ Let's Encrypt ã®è¨¼ææ¸ãå©ç¨ã§ããããã«ãªã£ã¦ããããã§ãããªã®ã§ãhttps 㧠Callback ãåãåããªããã¨è¨ãçç±ã®ããã ãã« Amazon API Gateway ã使ãå¿ è¦ãç¡ããªãã¾ããã
LINE Bot API 㯠Callback URL ã https ã®ã¿ã§ãããã Let's Encrypt ã StartSSL ã¨è¨ã£ãç¡æã®è¨¼ææ¸ã使ããªããã©ãã«ãå®ä¾¡ã§ Bot ãåããããã¨ãªã㨠Heroku ã®ãããªãã¡ã¤ã³ãæå®ããªããã° Wildcard 証ææ¸ãå²ãå½ã¦ããã¦ãã PaaS ã使ãã®ãä¸è¬çã§ãããã
ããã Heroku ã¯å¤ã«æãã IP ã¢ãã¬ã¹ãã©ãã©ãå¤ãã£ã¦ããã®ã§ã Bot API ã® IP Whitelist ã«ç»é²ãããã¨ãåºæ¥ãªããä»æ¹ç¡ãã®ã§ Heroku ã« rack-reverse-proxy ãç½®ãã¦ããã¨ã¯ãããã® VPS ã®ãããªåºå® IP ã¢ãã¬ã¹ã®ãããµã¼ã㧠Bot ãåããããã«ãã¾ããã
# Receive Callback [LINE Bot API Callback] -- https --> [Heroku] -- https (Let'sEncrypt ã¨ã) --> [VPS] # Call REST API [VPS] -- https --> [LINE Bot REST API]
ããã Heroku ã®ç¡ææ ã§ã¯ä¸æ¥ 18 æéã¾ã§ããåãããªãããä¸æ¦ã¤ã³ã¹ã¿ã³ã¹ãè½ã¡ãã¨ã¡ãã£ã¨ã¬ã¹ãã³ã¹ã«æéãããã£ã¦ä¸ä¾¿ã ãããã Heroku ã® 1 ã¤ã³ã¹ã¿ã³ã¹ã使ã£ã¦åãªã Reverse Proxy ã建ã¦ãã®ãå¯è±ªãããã
ä¸æ¥ä¸ Bot ã«è©±ãæãã¦ããã Heroku ã®ç¨¼åæéã 18 æéãè¶ãã¦ãã¾ã£ãã®ã§ãæåã¯ãHeroku ã®ã¤ã³ã¹ã¿ã³ã¹ã«ã«ãæããï½ãã¨æã£ã¦ãããã© 7USD ããã£ãããããå°ã㧠RapidSSL ã®è¨¼ææ¸è²·ãã¡ããããªâ¦ããããªæã«è¦ä»ããã®ã Amazon API Gateway ã§ããã
API Gateway ã£ã¦ä½?
ãªã·ã£ã¬ãª Reverse Proxy ã§ããæéãã ãã¶å®ããã
Amazon API Gateway ã®ç¡æå©ç¨æ ã§ã¯ãæ大 12 ãæéã1 ãæããã 100 ä¸åã® API å¼ã³åºããå©ç¨ã§ãã¾ãã1 ãæãããã®å¼ã³åºãããã®æ°å¤ãè¶ ããã¨ãAPI Gateway ã®ã¬ã¼ãã§èª²éããã¾ãã
LINE Bot API ã® Callback ã«è¨å®ããæ¹æ³
ã ãããããèªãã°ããã
ãã¤ã³ãã¨ãã¦ã¯ã API Gateway ã® HTTP Proxy ã¯ãã©ã¡ã¼ã¿ã Body ã¯è»¢éãã¦ããããã©ã HTTP Header ã¯åå¥ã«æå®ããªãã¨è»¢éãã¦ãããªãç¹ã§ãã LINE Bot API ã® Callback ã«ã¯ X-LINE-ChannelSignature
ãä»ãã¦ããã®ã§ãããã転éããããã«ãã¾ãã
ãã¨ã¯ API Gateway ããããã¤ãã¦åºã¦ãã URL ã LINE Developers ã«ç»é²ãã¾ãã
åä½ã¨ãã¦ã¯ Heroku ã« Reverse Proxy ã建ã¦ã¦ããããã¨å ¨ãåãã§ãã
# Receive Callback [LINE Bot API Callback] -- https --> [API Gateway] -- https (Let'sEncrypt ã¨ã) --> [VPS] # Call REST API [VPS] -- https --> [LINE Bot REST API]
Amazon API Gateway ãªã Heroku ã®ç¡ææ ã¨éã£ã¦ã¤ã³ã¹ã¿ã³ã¹ã®ç¨¼åæéã«å¶éã¯ç¡ãã®ã§å¿«é©ã« Callback ãåãåããã¨ãåºæ¥ã¾ãã