AWS CLIã¨ã·ã§ã«ã¹ã¯ãªãããããã¤ä½¿ãï¼æ´»ç¨ã¦ãããå ´é¢ã¨Tipsç´¹ä» #devio2024 / AWS CLI and Shell Tips
EC2ã¤ã³ã¹ã¿ã³ã¹ã®è¸ã¿å°ãç¨æããããªã ããã«ã¡ã¯ãã®ãã(@non____97)ã§ãã çããã¯EC2ã¤ã³ã¹ã¿ã³ã¹ã®è¸ã¿å°ãç¨æããããªãã¨æã£ããã¨ã¯ããã¾ãã? ç§ã¯ããã¾ãã VPCä¸ã®RDS DBã¤ã³ã¹ã¿ã³ã¹ãRedisã¯ã©ã¹ã¿ã¼ãOpenSearch Service ãã¡ã¤ã³ãªã©ã®ãªã½ã¼ã¹ã«æ¥ç¶ãããå ´åãSite-to-Site VPNãClient VPNãDirect Connectããªããã°è¸ã¿å°(Bastion)ãå¿ è¦ã«ãªãã¾ãã è¸ã¿å°ã¸ã®ã¢ã¯ã»ã¹æ¹æ³ã¯ä»¥ä¸ã®ãããªãã®ãããã¾ãã ç´æ¥SSH SSMã»ãã·ã§ã³ããã¼ã¸ã£ã¼ EC2 Instance Connect ããã¦ãè¸ã¿å°ã¨ãªããªã½ã¼ã¹ã¨ãã¦æ¡ç¨ãããå¤ããEC2ã¤ã³ã¹ã¿ã³ã¹ã ã¨èãã¾ããEC2ã¤ã³ã¹ã¿ã³ã¹ã®å ´åãOSå¨ãã®é¢åãã¿ãå¿ è¦ãããã¾ããOSå ã®ããã±ã¼ã¸ã®ã¢ãããã¼ããé¢åã§ããã°ãè¸ã¿å°ã
ã©ãããå°æã§ãã ã¿ãªãããèªååãã¦ã¾ããï¼ ç§ã®èª²ã§ã¯ç¹å®ã®é¡§å®¢ã®ã·ã¹ãã ãå¤æ°éç¨ãã¦ãã¾ãã ããªãå¤ãã®ã·ã¹ãã ãããã顧客å´ã®æ å½è ãç°ãªããããå¼ç¤¾å´ã§ãè¤æ°ã®ãã¼ã ãçµãã§æåããã¦ã·ã¹ãã ãæ å½ãã¦ãã¾ãã ãã¼ã ã顧客æ å½è ãç°ãªãã¨ãªãã°ãå½ç¶éç¨ã®ããæ¹ã¯ã·ã¹ãã ãã¨ã«å¤ãã£ã¦ãã¾ãããã®ä¸æ¹ã§çµ±ä¸ã§ããé¨åã¯çµ±ä¸ãã¦ãããªãã¨å ¨ä½ã®çµ±å¶ã¯å¹ãã¥ãããªã£ã¦ãã¾ãã¾ãã ããã§ãæ¨æºåãã¼ã ããçºè¶³ãããã¼ã éã§å ±ç¨ããã·ã¹ãã ã®ã¢ã«ã¦ã³ã管çããã®ç³è«ã«ã¼ã«ãé¡§å®¢å ±åãã¡ã³ãã¼ã®å¤æ 管çã¨ãã£ããã®ã®æ¨æºåãé²ãã¦ãã¾ãã æ¨æºåã®æ©æµã®ã²ã¨ã¤ã¨ãã¦ããä½æ¥ãåç´åã§ãã¦èªååãããããªããã¨ããç¹ãæãããã¾ãã ä¾ãã°ã¢ã«ã¦ã³ãçºè¡ã®ç³è«ãã©ã¼ããããçµ±ä¸ããã¨ãããã©ã¼ãããã«ãããã£ã¦è¨è¼ãããããã¹ãããããã«èªã¿è¾¼ã¾ãã¦ã¢ã«ã¦ã³ããèªåçã«çºè¡ãããã¨
ã¯ããã« è¸ã¿å°ãµã¼ãã¼çµç±ã§æ¥ç¶ããæ¹æ³ â ã»ãã¥ãªãã£ã°ã«ã¼ããä½æãã â¡ãããªãã¯ãµããããã«è¸ã¿å°ãµã¼ããä½æãã â¢ãã©ã¤ãã¼ããµããããã«EC2ã¤ã³ã¹ã¿ã³ã¹ãä½æãã â£è¸ã¿å°ãµã¼ãã¼ã«ãã©ã¤ãã¼ããµããããã«é ç½®ãããEC2ã¤ã³ã¹ã¿ã³ã¹ã®ãã¼ãã¢ãã³ãã¼ãã â¤è¸ã¿å°ãµã¼ãã¼ã«ã¢ã¯ã»ã¹ãã â¥è¸ã¿å°ãµã¼ãã¼ãããã©ã¤ãã¼ããµããããã«ããEC2ã¤ã³ã¹ã¿ã³ã¹ã«ã¢ã¯ã»ã¹ãã SSMã»ãã·ã§ã³ããã¼ã¸ã£ã¼çµç±ã§æ¥ç¶ããæ¹æ³ VPCã¨ã³ããã¤ã³ãã使ç¨ããæ¹æ³ â ã»ãã¥ãªãã£ã°ã«ã¼ãã¨IAMãã¼ã«ãä½æãã â¡ãã©ã¤ãã¼ããµããããã«EC2ã¤ã³ã¹ã¿ã³ã¹ãä½æãã â¢VPCã¨ã³ããã¤ã³ããä½æãã â£SSMã»ãã·ã§ã³ããã¼ã¸ã£ã¼çµç±ã§EC2ã¤ã³ã¹ã¿ã³ã¹ã«æ¥ç¶ãã NATã²ã¼ãã¦ã§ã¤ã使ç¨ããæ¹æ³ â IAMãã¼ã«ãä½æãã â¡ãã©ã¤ãã¼ããµããããã«EC2ã¤ã³ã¹ã¿ã³ã¹ãä½æãã â¢NA
ã¯ããã« çªç¶ã§ãããEC2ã¤ã³ã¹ã¿ã³ã¹ã«ã¢ã¯ã»ã¹ããã¨ãçæ§ã¯ã©ã®ãããªæ¹æ³ã§ã¢ã¯ã»ã¹ãã¦ãã¾ããã ç§ã¯ä»ã¾ã§ãã¼ãã¢ã使ã£ã¦ãã¼ã«ã«PCããSSHæ¥ç¶ãããæ¹æ³ãå½ããåã ã¨æã£ã¦ãã¾ããããAWSããã¸ã¡ã³ãã³ã³ã½ã¼ã«ããç´æ¥ã¢ã¯ã»ã¹ã§ãããã¨ãç¥ã£ã¦é©ãã¾ããï¼ AWS Systems Managerã®æ©è½ã®1ã¤ã§ããSession Managerã使ãã¨ããã¼ãã¢ã使ãSSHæ¥ç¶ãããã»ãã¥ã¢ãªæ¥ç¶ãå®ç¾ã§ãã¾ããå ·ä½çã«ã¯æ¬¡ã®ãããªã¡ãªãããããã¾ãã ãã¼ãã¢ã使ããªãã®ã§ããã¼ãã¢ãç´å¤±ããéã®æ å ±æ¼æ´©ãé²ããã¨ãã§ãã ã¤ã³ãã¦ã³ãã«ã¼ã«ã§SSHãã¼ã(ãã¼ãçªå·22)ãéããå¿ è¦ããªããªã ãã©ã¤ãã¼ããµããããã«ããEC2ã¤ã³ã¹ã¿ã³ã¹ã«ãè¸ã¿å°ãµã¼ãã¼ãªãã§ã¢ã¯ã»ã¹ãã§ãã â»ããã«ã¯Nat Gatewayãããã¯VPCã¨ã³ããã¤ã³ããå¿ è¦ã¨ãªãï¼è©³ç´°ã¯å¾è¿°ï¼ æ¬è¨
ãAWSããGCPãGCEã«SSM Agentãã¤ã³ã¹ãã¼ã«ããAWS Systems Managerãããã°ã¤ã³ãã¦ã¿ã¾ããAWSgceSSMSystemsManagerGoogleCloud åæ¸ AWSã®Systems Managerã®ã»ãã·ã§ã³ããã¼ã¸ã£ã¼æ©è½ã¯ãã¾ãã«ã便å©ããã§ãå人çã«ã¯ãã®ãµã¼ãã¹ã大好ãã§ãï¼ï¼ SSM Agentãããµã¼ãã¼å ã«ã¤ã³ã¹ãã¼ã«ãã¦ããã°ãã¢ã¦ããã¦ã³ãéä¿¡ãAWSå´ã®Systems Managerã¨ã®çéãããã§ãã¦ããã°ãSystems Manageræ©è½ããã«æ´»ç¨ãããã¨ãã§ãã¾ãã ãªã®ã§ãGCPå´ã®GCEã«SSM Agentãã¤ã³ã¹ãã¼ã«ããAWSã®Systems Managerã®ã»ãã·ã§ã³ããã¼ã¸ã£ã¼æ©è½ããå©ç¨ãã¦ã¿ã¾ããï¼ ï¼ï¼AWSå´ã§ã¢ã¯ãã£ãã¼ã·ã§ã³ä½æ ã¾ããSystems Mangaerå´ã«Systems Manag
èæ¯ AWSã®EC2ã«SSHæ¥ç¶ããéãEC2ã®SSHãã¼(pemãã¡ã¤ã«)ã使ç¨ãã¦æ¥ç¶ãããã¨ãå¤ã§ãããSSHãã¼ã®ç®¡çãé¢åã ã£ãããã»ãã¥ãªãã£çã«ãSSHãã¼ã使ç¨ããã®ã¯é¿ãããå ´åãããã¾ãã ãã®è¨äºã§ã¯OSå¥ãIDEå¥ã«SSHãã¼ã使ç¨ããã«EC2ã«æ¥ç¶ããæ¹æ³ãç´¹ä»ãã¾ãã åææ¡ä»¶ Session Managerãæå¹åããã¦ããEC2ã¤ã³ã¹ã¿ã³ã¹ãããã㨠OpenSSHãã¤ã³ã¹ãã¼ã«ããã¦ããã㨠OpenSSHã®ã¤ã³ã¹ãã¼ã«æ¹æ³: Windows: Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*' 管çè 権éã§PowerShellãèµ·åãããã¨ãå¿ è¦ã§ãã詳細ã¯ãã¡ã Mac/Linux: brew install openssh äºåæºå - Remoteæ¡å¼µæ©è½ã®ã»ããã¢ã
ãã°ãã§ãã ååã®è¨äºã§.NET on AWSã®éçºç°å¢ã«ã¯ãEC2ã§VS Code Remote Developmentã使ããã®ããã¹ãã¨è¨ãã¾ããã æ¬è¨äºã§ã¯ãã®å ·ä½çãªæé ã解説ãã¾ãã VS Code Remoteæ¦è¦ Visual Studio Code(VS Code)ã¯ããèªèº«ããµã¼ãã¼ã¨ãã¦åä½ããã¯ã©ã¤ã¢ã³ããããªã¢ã¼ãä¸ã«ããVS Codeã使ã£ããªã¢ã¼ãéçºãå¯è½ã§ãã VS Code Remote Development VS Codeã®ãªã¢ã¼ãæ¥ç¶ã¯å¤§å¥ãã¦ä»¥ä¸ã®ä¸ç¨®ã®æ¹å¼ãããã¾ãã Dev Containers : ãã¹ãããã³ã³ããç°å¢ã¸æ¥ç¶ Remote SSH : ã¯ã©ã¤ã¢ã³ããããªã¢ã¼ãç°å¢ã¸SSHæ¥ç¶ Remote Tunnels : ã»ãã¥ã¢ãã³ãã«ãã¤ãã£ãæ¥ç¶ Dev Containersã¯ã³ã³ããã®è©±ãªã®ã§é¤å¤ãã¦Remote SSHã¨
ããã«ã¡ã¯ãæ«»äºã§ãã EC2ã使ã£ã¦éçºãè¡ãéãã¿ã¼ããã«ä¸ã§SSHæ¥ç¶ãè¡ãVimãªã©ã§éçºããæ¹æ³ããVS Codeã®Remote-SSHã使ãæ¹æ³ãªã©ãæãããã¾ãã ä»åã¯ã»ãã¥ãªãã£ã¼ã°ã«ã¼ãã§SSHã®ãã¼ããéããã«ãAWS Systems Manager ã»ãã·ã§ã³ããã¼ã¸ã£ã¼ï¼ä»¥ä¸ã»ãã·ã§ã³ããã¼ã¸ã£ã¼ï¼ã§VS Codeã®Remote-SSHã使ããããã«ãããã¨ã§ãã»ãã¥ãªãã£ã¼ãå ç¢ãªã·ã¹ãã ãæ§ç¯ãåã³ã¹ã ã¼ãºã«éçºã§ããç°å¢ãç´¹ä»ãã¾ãã ã»ãã·ã§ã³ããã¼ã¸ã£ã¼è¶ãã«SSHãããã¡ãªãããã¾ã¨ãã¦ããè¨äºãããã®ã§ãæ°ã«ãªãæ¹ã¯ä»¥ä¸ã®ãªã³ã¯ãåç §ãã¦ãã ããã ã»ãã·ã§ã³ããã¼ã¸ã£ã¼è¶ãã«SSHã¢ã¯ã»ã¹ããã¨ä½ãå¬ããã®ã åæ Windowsã®PCã使ã£ã¦ãã VS Codeãã¤ã³ã¹ãã¼ã«æ¸ã¿ ã»ãã·ã§ã³ããã¼ã¸ã£ã¼ã使ã£ã¦ãã°ã¤ã³ã§ããEC2ã¨ç°å¢ãããï¼ä¸
ã»ãã·ã§ã³ããã¼ã¸ã£ã¼è¶ãã«SSHã¢ã¯ã»ã¹ããæ§æã®ã¡ãªããã«ã¤ãã¦èãã¦ã¿ã¾ããã ãªã«ããï¼ å ¬å¼ããã¥ã¡ã³ãã§ããã¨ä»¥ä¸å 容ã®ãã¨ã§ãã Step 8: (Optional) Enable SSH connections through Session Manager ããå°ã詳ãã ã¾ããã¯ã©ã¤ã¢ã³ãã¯ã»ãã·ã§ã³ããã¼ã¸ã£ã¼ã使ã£ã¦ã¢ã¯ã»ã¹ãããã¤ã³ã¹ã¿ã³ã¹ã«ã¢ã¯ã»ã¹ãã¾ãã ããå°ããã®é¨åãå ·ä½çã«èª¬æããã¨ãã¯ã©ã¤ã¢ã³ããã¢ã¯ã»ã¹ãã¦ããã®ã¯ã¤ã³ã¹ã¿ã³ã¹ã§ã¯ãªããSSM(Systems Manager)ã®ã¨ã³ããã¤ã³ãã§ãã ããã¦ãã¢ã¯ã»ã¹å ã¤ã³ã¹ã¿ã³ã¹å ã®SSM Agentããã¼ãªã³ã°ã¢ã¯ã»ã¹ãã¦ãã¦ããã¡ããéãã¦ã¢ã¯ã»ã¹ãã¦ãã¾ãã ããã¦ããã®æ¥ç¶ã®å ã§ãSSHæ¥ç¶ãç´ãã¦ããã¤ã¡ã¼ã¸ã«ãªãã¾ãããããä»åæ±ããã»ãã·ã§ã³ããã¼ã¸ã£ã¼è¶ãã«SSHã¢ã¯ã»ã¹ãã§ãã ã
2019å¹´9æã® AWS Systems Manager ã®ã¢ãããã¼ãã«ãããã»ãã·ã§ã³ããã¼ã¸ã£ã¼ã使ç¨ãã¦ãã¯ã©ã¤ã¢ã³ãã¨ãµã¼ãã¼é㧠SSH (Secure Shell) ããã³ SCP (Secure Copy) ãã©ãã£ãã¯ããã³ããªã³ã°ãããã¨ãã§ããããã«ãªãã¾ããã ã»ãã·ã§ã³ããã¼ã¸ã£ã¼ã SSH 㨠SCP ã®ãã³ããªã³ã°ãµãã¼ããéå§ æåã ãè¦ãã¨ä½ãã§ããããã«ãªã£ãããµãããªã§ããããã®ã¢ãããã¼ãã«ãããEC2 ã« SSH ããããã« 22 çªãã¼ããéããå¿ è¦ããªããªãã¾ããããã©ã¤ãã¼ããµããããã«ãããã°ãã¼ãã« IP ããããªã EC2 ã«ãè¸ã¿å°ãªã㧠SSH ã¢ã¯ã»ã¹ãã§ããããã«ãªãã¾ãããããã°è¸ã¿å°ãµã¼ãã¼ã å®éã«è¨å®ãã¦ã¿ãã¨ãç´°ããæ¡ä»¶ããã£ãããããã¥ã¡ã³ããæ£ãã°ã£ã¦ããããã¦çµæ§æããã£ãã®ã§ãåç §ããããã¥ã¡ã³ããæé ãªã©ãã¾
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}