ããã«ã¡ã¯ãAWS CLIã好ããªç¦å³¶ã§ãã
- ã¯ããã«
- æ¦è¦å³
- åæ
- æµã
- â IAMããªã·ã¼ã®ä½æ
- â¡IAMãã¼ã«ã®ä½æ
- â¢AWS Chatbotã¨Slackã®é£æº
- â¢-â AWS Chatbotã®ã³ã³ã½ã¼ã«ãéãã¾ãã
- â¢-â¡æ°ããã¯ã©ã¤ã¢ã³ããè¨å®ãæ¼ä¸ãã¾ãã
- â¢-â¢Slackãé¸æããè¨å®ãæ¼ä¸ãã¾ãã
- â¢-â£è¨±å¯ãããæ¼ä¸ãã¾ãã
- â¢-â¤æ°ãããã£ã³ãã«ãè¨å®ãæ¼ä¸ãã¾ãã
- â¢-â¥è¨å®åã¨Slackã®ãã£ã³ãã«IDãå ¥åãã¾ãã
- â¢-â¦æ¢åã®IAMãã¼ã«ã使ç¨ãããé¸æããæ¢åã®ãã¼ã«ã«â¡ã§ä½æããIAMãã¼ã«ããã£ã³ãã«ã¬ã¼ãã¬ã¼ã«ããªã·ã¼ã«â ã§ä½æããIAMããªã·ã¼ãè¨å®ãã¾ãã
- â¢-â§éç¥ã¯ç¹ã«è¨å®ããã«ãè¨å®ãæ¼ä¸ãã¾ãã
- â£SSMããã¥ã¡ã³ãã®ä½æ
- â£-â SSMããã¥ã¡ã³ãã®ã³ã³ã½ã¼ã«ãéãã¾ãã
- â£-â¡Create documentããCommand or Sessionãæ¼ä¸ãã¾ãã
- â£-â¢ä»»æã®ååãä»ããã¿ã¼ã²ããã¿ã¤ãã¯ã/AWS::EC2::Instanceããããã¥ã¡ã³ãã¿ã¤ãã¯ãã³ãã³ãããã¥ã¡ã³ãããè¨å®ãã¾ãã
- â£-â£JSONãè¨å®ããããã¥ã¡ã³ããä½æãæ¼ä¸ãã¾ãã
- â¤åä½ç¢ºèª
- â¤-â Slackä¸ã§ã³ãã³ããå®è¡ãã¾ãã
- â¤-â¡[Run] Commandãæ¼ä¸ãã¾ãã
- â¤-â¢ã³ãã³ããæ£å¸¸ã«å®è¡ãããã¨ä»¥ä¸ã®ãããªåºåã«ãªãã¾ãã
- è£è¶³(SSMã®ã³ã³ã½ã¼ã«ããã確èªãã¦ã¿ã¾ãã)
- çµããã«
ã¯ããã«
ä»åã¯ãAWS Chatbotã使ããSlackããSSMçµç±ã§EC2ä¸ã®ã³ãã³ããå®è¡ããæ¹æ³ãããã°ã«è¨è¼ãããã¾ãã
æ¦è¦å³
åæ
ä»åãç´¹ä»ããæ¹æ³ã¯ãSSMã®æ©è½ã使ã£ã¦ããããã対象ã®EC2ãSSMã®ããã¼ã¸ãã¤ã³ã¹ã¿ã³ã¹ã¨ãã¦èªèããã¦ããå¿ è¦ãããã¾ãã ã¾ã ã®æ¹ã¯ã以ä¸ãåèã«ã»ããã¢ãããã¦ãã ããã
æµã
- â IAMããªã·ã¼ã®ä½æ
- â¡IAMãã¼ã«ã®ä½æ
- â¢AWS Chatbotã¨Slackã®é£æº
- â£SSMããã¥ã¡ã³ãã®ä½æ
- â¤åä½ç¢ºèª
â IAMããªã·ã¼ã®ä½æ
â -â ChatbotãSSMã®ããã¥ã¡ã³ããå®è¡ã§ããããIAMããªã·ã¼ãä½æãã¾ãã
[AWSã¢ã«ã¦ã³ãID],[ããã¥ã¡ã³ãå],[ã¤ã³ã¹ã¿ã³ã¹ID]ã®3ã¤ãé©åãªå¤ã«ç½®ãæãã¾ãã
- IAMããªã·ã¼ã®è¨å®ä¾
{ "Version": "2012-10-17", "Statement": [ { "Action": [ "ssm:SendCommand" ], "Resource": [ "arn:aws:ssm:ap-northeast-1:[AWSã¢ã«ã¦ã³ãID]:document/[ããã¥ã¡ã³ãå]", "arn:aws:ec2:ap-northeast-1:[AWSã¢ã«ã¦ã³ãID]:instance/[ã¤ã³ã¹ã¿ã³ã¹ID]" ], "Effect": "Allow" } ] }
â¡IAMãã¼ã«ã®ä½æ
â¡-â IAMãã¼ã«ãä½æããâ ã§ä½æããIAMããªã·ã¼ãã¢ã¿ããããä¿¡é ¼é¢ä¿ã«ã¯ä»¥ä¸ãè¨å®ãã¾ãã
- ä¿¡é ¼é¢ä¿ã®è¨å®
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "chatbot.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }
â¢AWS Chatbotã¨Slackã®é£æº
AWS Chatbotã¨Slackã®é£æºãè¡ãã¾ãã
â¢-â AWS Chatbotã®ã³ã³ã½ã¼ã«ãéãã¾ãã
https://us-east-2.console.aws.amazon.com/chatbot/home?region=us-east-2#/chat-clients
â¢-â¡æ°ããã¯ã©ã¤ã¢ã³ããè¨å®ãæ¼ä¸ãã¾ãã
â¢-â¢Slackãé¸æããè¨å®ãæ¼ä¸ãã¾ãã
â¢-â£è¨±å¯ãããæ¼ä¸ãã¾ãã
â¢-â¤æ°ãããã£ã³ãã«ãè¨å®ãæ¼ä¸ãã¾ãã
â¢-â¥è¨å®åã¨Slackã®ãã£ã³ãã«IDãå ¥åãã¾ãã
- è£è¶³
ãã£ã³ãã«IDã¯Slackã®URLãåãã£ã³ãã«ã®ãã£ã³ãã«æ å ±ã®æä¸é¨ã§ç¢ºèªã§ãã¾ãã
â¢-â¦æ¢åã®IAMãã¼ã«ã使ç¨ãããé¸æããæ¢åã®ãã¼ã«ã«â¡ã§ä½æããIAMãã¼ã«ããã£ã³ãã«ã¬ã¼ãã¬ã¼ã«ããªã·ã¼ã«â ã§ä½æããIAMããªã·ã¼ãè¨å®ãã¾ãã
- è£è¶³
å®éã«Chatbotã«ä»ä¸ããã権éã¯ãæ¢åã®ãã¼ã«ã«æå®ããIAMãã¼ã«(ã«è¨å®ããã¦ããIAMããªã·ã¼)ã®æ¨©éã«ãªãã¾ãã
ã¬ã¼ãã¬ã¼ã«ããªã·ã¼ã¯Chatbotãæã¦ã権éã®ç¯å²ã«ãªãã¾ãããã®ãããã¬ã¼ãã¬ã¼ã«ã«è¨å®ããããªã·ã¼ä»¥ä¸ã«Chatbotã¯æ¨©éãæã¤ãã¨ã¯ã§ãã¾ããã
â¢-â§éç¥ã¯ç¹ã«è¨å®ããã«ãè¨å®ãæ¼ä¸ãã¾ãã
â£SSMããã¥ã¡ã³ãã®ä½æ
â£-â SSMããã¥ã¡ã³ãã®ã³ã³ã½ã¼ã«ãéãã¾ãã
https://us-east-2.console.aws.amazon.com/systems-manager/documents?region=us-east-2
â£-â¡Create documentããCommand or Sessionãæ¼ä¸ãã¾ãã
â£-â¢ä»»æã®ååãä»ããã¿ã¼ã²ããã¿ã¤ãã¯ã/AWS::EC2::Instanceããããã¥ã¡ã³ãã¿ã¤ãã¯ãã³ãã³ãããã¥ã¡ã³ãããè¨å®ãã¾ãã
â£-â£JSONãè¨å®ããããã¥ã¡ã³ããä½æãæ¼ä¸ãã¾ãã
- Documentã®è¨å®ä¾(Linuxã®å ´å(Actionãaws:runShellScript)))
/home/ec2-user/test.shã®ç®æã¯ãå®è¡ãããã³ãã³ãã«ç½®ãæãã¾ãã
parametersã®defaultå¤ã¯åé¤ãããã¨ã§å¼æ°ã®æå®ãå¿
é ã«ãããã¨ãå¯è½ã§ãã
{ "schemaVersion": "2.2", "description": "Command Document Example JSON Template", "parameters": { "FirstArg": { "type": "String", "description": "First argument of the script", "default": "hoge" }, "SecondArg": { "type": "String", "description": "Second argument of the script", "default": "hoge" } }, "mainSteps": [ { "action": "aws:runShellScript", "name": "example", "inputs": { "runCommand": [ "/home/ec2-user/test.sh {{FirstArg}} {{SecondArg}}" ] } } ] }
- Documentã®è¨å®ä¾(Windowsã®å ´å(Actionãaws:runPowerShellScript))
C:\Users\Administrator\Desktop\test.batã®ç®æã¯ãå®è¡ãããã³ãã³ãã«ç½®ãæãã¾ãã
ãã«ãã¹ãæå®ããå ´åã\ãã¨ã¹ã±ã¼ãããå¿
è¦ãããã¾ãã
ã¾ããparametersã®å¤ã¯ä¸è¦ã§ããã°åé¤å¯è½ã§ãå¼æ°ãè¤æ°æ¬²ããå ´åã追å å¯è½ã§ãã
{ "schemaVersion": "2.2", "description": "Command Document Example JSON Template", "parameters": { "FirstArg": { "type": "String", "description": "First argument of the script" } }, "mainSteps": [ { "action": "aws:runPowerShellScript", "name": "example", "inputs": { "runCommand": [ "C:\\Users\\Administrator\\Desktop\\test.bat {{FirstArg}}" ] } } ] }
â¤åä½ç¢ºèª
Slackããå®éã«ã³ãã³ããå®è¡ãã¦ã¿ã¾ãã
â¤-â Slackä¸ã§ã³ãã³ããå®è¡ãã¾ãã
- ã³ãã³ã
@aws ssm send-command --targets Key=InstanceIds,Values=[ã¤ã³ã¹ã¿ã³ã¹ID] --document-name [ããã¥ã¡ã³ãå] --parameters [ãã©ã¡ã¼ã¿ã¼Key1]=[ãã©ã¡ã¼ã¿ã¼Value1],[ãã©ã¡ã¼ã¿ã¼Key2]=[ãã©ã¡ã¼ã¿ã¼Value2] --region ap-northeast-1
- å®è¡ä¾
@aws ssm send-command --targets Key=InstanceIds,Values=i-0808672558492fde8 --document-name linux-document --parameters FirstArg=1,SecoundArg=2 --region ap-northeast-1
â¤-â¡[Run] Commandãæ¼ä¸ãã¾ãã
â¤-â ãå®è¡ããã¨ç¢ºèªãå ¥ããããåé¡ãªããã°[Run] Commandãæ¼ä¸ãã¾ãã
â¤-â¢ã³ãã³ããæ£å¸¸ã«å®è¡ãããã¨ä»¥ä¸ã®ãããªåºåã«ãªãã¾ãã
è£è¶³(SSMã®ã³ã³ã½ã¼ã«ããã確èªãã¦ã¿ã¾ãã)
以ä¸ã«ã¢ã¯ã»ã¹ãã対象ã®ã³ãã³ãIDãæ¼ä¸ãã¾ãã
https://ap-northeast-1.console.aws.amazon.com/systems-manager/run-command/complete-commands?region=ap-northeast-1
対象ã®ã¤ã³ã¹ã¿ã³ã¹IDã«ãã§ãã¯ãã¤ããåºåã®è¡¨ç¤ºãæ¼ä¸ãã¾ãã
Outputsã®ç®æã§ã³ãã³ãã®å®è¡çµæã確èªã§ãã¾ãã
ã¡ãªã¿ã«ä»åå®è¡ãã/home/ec2-user/test.shã¯ä»¥ä¸ã®éããæå®ããã第1,第2å¼æ°ãåºåããã¹ã¯ãªãããªããã1 2ã¨è¡¨ç¤ºããã¦ãã¾ãã
[ec2-user@ip-10-88-0-59 ~]$ cat test.sh echo $1 $2 [ec2-user@ip-10-88-0-59 ~]$
çµããã«
ä»åã¯ãSlackããSSMçµç±ã§EC2ä¸ã®ã³ãã³ããå®è¡ããæ¹æ³ã«ã¤ãã¦ããã°ã«è¨è¼ãããã¾ããã
ã©ãªããã®ãå½¹ã«ç«ã¦ãã°å¹¸ãã§ãã