AWS Systems ManagerでサンプルのAutomation Documentを作成・実行してみる(1)
AWS Systems Managerで自作で簡単なAutomation Documentを作成してみたので、そのメモです。
Systems Managerエージェントは既にAmazon LinuxベースのEC2インスタンスにインストール・動作済みで、Managed Instanceとして動作済みの前提とします。
まずは、AWS Management ConsoleにてAWS Systems Managerの画面を開いて、Documentを選択します。
上記画面にてドキュメントを作成を選択。
名前にMySampleAutomationDocument1を入れて、ドキュメントタイプにオートメーションドキュメントを選択、コンテンツには以下を入れます。
{ "description": "Automation Document Example JSON Template", "schemaVersion": "0.3", "assumeRole": "{{ AutomationAssumeRole }}", "parameters": { "AutomationAssumeRole": { "type": "String", "description": "(Optional) The ARN of the role that allows Automation to perform the actions on your behalf.", "default": "" } }, "mainSteps": [ { "name":"createText1", "action":"aws:runCommand", "maxAttempts":3, "timeoutSeconds":1200, "onFailure":"Abort", "inputs":{ "DocumentName":"AWS-RunShellScript", "InstanceIds":[ "i-04e0ac63bc6e4105f" ], "Parameters":{ "workingDirectory":"/home/ec2-user", "commands":[ "echo hello1 > testfile1" ] } } } ] }
オートメーションの実行を選択して、画面右上の「自己所有」を選択して、フィルタする。
先ほど作成したMySampleAutomationDocument1を選択、ドキュメントのバージョンは今回は1(デフォルト)を選択して、オートメーションを実行する。
以下画面にて成功したことを確認する。
個別にステップ(ステップID)を確認してみる。
今回はechoコマンドをテキストファイルに出力しただけなので、特に出力は出ていないが、問題なく成功したことが分かる。念のためEC2インスタンスにsshでログインして見ると
[ec2-user@ip-10-0-1-164 ~]$ ls testfile1
続いて、複数ステップでの実行も試してみる。