funasaki memo

このブログ上の投稿は個人のものであり、所属する企業を代表する投稿ではありません。所属:AWSのSolutions Architect

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を選択します。

f:id:kenjifunasaki:20180413114022p:plain

上記画面にてドキュメントを作成を選択。

f:id:kenjifunasaki:20180413114200p:plain

名前に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"
          ]
        }
      }
    }
  ]
}

オートメーションの実行を選択して、画面右上の「自己所有」を選択して、フィルタする。

f:id:kenjifunasaki:20180413135000p:plain

先ほど作成したMySampleAutomationDocument1を選択、ドキュメントのバージョンは今回は1(デフォルト)を選択して、オートメーションを実行する。

f:id:kenjifunasaki:20180413135024p:plain

以下画面にて成功したことを確認する。

f:id:kenjifunasaki:20180413135041p:plain

個別にステップ(ステップID)を確認してみる。

f:id:kenjifunasaki:20180413140210p:plain

今回はechoコマンドをテキストファイルに出力しただけなので、特に出力は出ていないが、問題なく成功したことが分かる。念のためEC2インスタンスsshでログインして見ると

[ec2-user@ip-10-0-1-164 ~]$ ls
testfile1

続いて、複数ステップでの実行も試してみる。