Systems Manager Automation アクションのリファレンス - AWS Systems Manager

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Systems Manager Automation アクションのリファレンス

このリファレンスでは、オートメーションランブックで指定できるAutomation アクションについて説明します。オートメーションは の一機能ですAWS Systems Manager これらのアクションは他のタイプの Systems Manager (SSM) ドキュメントでは使用できません。SSM の他のドキュメントタイプのプラグインについては、「コマンドドキュメントプラグインリファレンス」を参照してください。

Systems Manager Automation は、オートエアコンランブックで定義されたステップを実行します。各ステップは、特定のオペレーションに関連付けられます。このアクションは、ステップの入力、動作、出力を決定します。ステップは、ランブックの mainSteps セクションで定義されます。

アクションまたはステップの出力を指定する必要はありません。出力は、ステップに関係付けられるアクションで事前判断されます。Runbook でステップ入力を指定すると、前のステップの 1 つあるいは複数の出力を参照できます。たとえば、aws:runInstances の出力は後続の aws:runCommand アクションで利用できます。Runbook の Output セクションで前のステップの出力を参照することもできます。

重要

AWS Identity and Access Management (IAM) サービスロールを使用して他のサービスを呼び出す自動化ワークフローを実行する場合は、それらのサービスを呼び出すためのアクセス許可をサービスロールに設定する必要がある点に注意してください。この要件は、AWS-ConfigureS3BucketLoggingAWS-CreateDynamoDBBackupAWS-RestartEC2Instance ランブックなど、すべての AWS オートメーションランブック (AWS-* ランブック) に適用されます。この要件は、他のサービスを呼び出すアクションを使用して他の AWS のサービスを呼び出すように作成したカスタムオートメーションランブックにも適用されます。例えば、aws:executeAwsApiaws:createStack、または aws:copyImage のアクションを使用する場合は、それらのサービスを呼び出すためのアクセス許可を持つサービスロールを設定します。ロールに IAM インラインポリシーを追加することで、他の AWS のサービスへのアクセス許可を有効にできます。詳細については、「(オプション) 他の AWS のサービス を呼び出すためのオートメーションインラインポリシーまたはカスタマー管理ポリシーを追加する」を参照してください。

トピック

すべてのアクションで共有されるプロパティ

共通プロパティは、すべてのアクションで見つかるパラメータまたはオプションです。一部のオプションは、ステップの動作を定義します。たとえば、ステップが完了するまで待機する時間や、ステップが失敗した場合の対処方法などです。以下のプロパティは、すべてのアクションに共通です。

description

ランブックまたはステップの目的を説明するために提供する情報。

型: 文字列

必須: いいえ

name

Runbook のすべてのステップ名にわたって一意でなければならない識別子。

タイプ: 文字列

使用できるパターン: [a-zA-Z0-9_]+$

必須: はい

action

ステップが実行するアクションの名前です。aws:runCommand – マネージドインスタンスでコマンドを実行する はここで指定できるアクションの例です。このドキュメントは、使用可能なすべてのアクションの詳細情報を提供します。

型: 文字列

必須: はい

maxAttempts

ステップが失敗した場合は再試行する回数。指定した値が 1 より大きい場合、すべての再試行が失敗するまでステップは失敗したと見なされません。デフォルト値は 1 です。

タイプ: 整数

必須: いいえ

timeoutSeconds

ステップのタイムアウト値。タイムアウトが達したときに maxAttempts の値が 1 以上の場合、すべての再試行が実行されるまでこのステップはタイムアウトとは見なされません。

タイプ: 整数

必須: いいえ

onFailure

失敗時にオートメーションを中止するか、続行するか、別のステップに移行するかを示します。このオプションのデフォルト値は中止です。

型: 文字列

有効な値: Abort | Continue | step:step_name

必須: いいえ

onCancel

ユーザーがオートメーションをキャンセルした場合に、オートメーションがどのステップに進むべきかを示します。Automation は、最大で 2 分間、キャンセルワークフローを実行します。

型: 文字列

有効な値: Abort | step:step_name

必須: いいえ

onCancel プロパティでは、次のアクションへの移動はサポートされていません。

  • aws:approve

  • aws:copyImage

  • aws:createImage

  • aws:createStack

  • aws:createTags

  • aws:loop

  • aws:pause

  • aws:runInstances

  • aws:sleep

isEnd

このオプションでは、特定のステップの最後にオートメーションを停止します。ステップが失敗または成功した場合に、オートメーションが停止します。デフォルト値は false です。

タイプ: ブール値

有効な値: true | false

必須: いいえ

nextStep

ステップを正常に完了した後に、次に処理するオートメーションのステップを指定します。

型: 文字列

必須: いいえ

isCritical

自動化の正常な完了のために、ステップを critical として指定します。この指定のステップが失敗した場合、自動化は自動化の失敗の最終的なステータスをレポートします。このプロパティは、ステップで明示的に定義した場合のみ評価されます。ステップで onFailure プロパティが Continue に設定されている場合、値はデフォルトで false になります。それ以外の場合、このオプションのデフォルト値は true です。

タイプ: ブール値

有効な値: true | false

必須: いいえ

inputs

アクション固有のプロパティ。

型: マップ

必須: はい

---
description: "Custom Automation Example" schemaVersion: '0.3' assumeRole: "{{ AutomationAssumeRole }}" parameters: AutomationAssumeRole: type: String description: "(Required) The ARN of the role that allows Automation to perform the actions on your behalf. If no role is specified, Systems Manager Automation uses your IAM permissions to run this runbook." default: '' InstanceId: type: String description: "(Required) The Instance Id whose root EBS volume you want to restore the latest Snapshot." default: '' mainSteps:
- name: getInstanceDetails action: aws:executeAwsApi onFailure: Abort inputs: Service: ec2 Api: DescribeInstances InstanceIds: - "{{ InstanceId }}" outputs: - Name: availabilityZone Selector: "$.Reservations[0].Instances[0].Placement.AvailabilityZone" Type: String - Name: rootDeviceName Selector: "$.Reservations[0].Instances[0].RootDeviceName" Type: String nextStep: getRootVolumeId - name: getRootVolumeId
action: aws:executeAwsApi
maxAttempts: 3 onFailure: Abort inputs: Service: ec2 Api: DescribeVolumes Filters: - Name: attachment.device Values: ["{{ getInstanceDetails.rootDeviceName }}"] - Name: attachment.instance-id Values: ["{{ InstanceId }}"] outputs: - Name: rootVolumeId Selector: "$.Volumes[0].VolumeId" Type: String nextStep: getSnapshotsByStartTime - name: getSnapshotsByStartTime action: aws:executeScript
timeoutSeconds: 45
onFailure: Abort inputs: Runtime: python3.8 Handler: getSnapshotsByStartTime InputPayload: rootVolumeId : "{{ getRootVolumeId.rootVolumeId }}" Script: |- def getSnapshotsByStartTime(events,context): import boto3 #Initialize client ec2 = boto3.client('ec2') rootVolumeId = events['rootVolumeId'] snapshotsQuery = ec2.describe_snapshots( Filters=[ { "Name": "volume-id", "Values": [rootVolumeId] } ] ) if not snapshotsQuery['Snapshots']: noSnapshotFoundString = "NoSnapshotFound" return { 'noSnapshotFound' : noSnapshotFoundString } else: jsonSnapshots = snapshotsQuery['Snapshots'] sortedSnapshots = sorted(jsonSnapshots, key=lambda k: k['StartTime'], reverse=True) latestSortedSnapshotId = sortedSnapshots[0]['SnapshotId'] return { 'latestSnapshotId' : latestSortedSnapshotId } outputs: - Name: Payload Selector: $.Payload Type: StringMap - Name: latestSnapshotId Selector: $.Payload.latestSnapshotId Type: String - Name: noSnapshotFound Selector: $.Payload.noSnapshotFound Type: String nextStep: branchFromResults - name: branchFromResults action: aws:branch onFailure: Abort
onCancel: step:startInstance inputs: Choices: - NextStep: createNewRootVolumeFromSnapshot Not: Variable: "{{ getSnapshotsByStartTime.noSnapshotFound }}" StringEquals: "NoSnapshotFound"
isEnd: true - name: createNewRootVolumeFromSnapshot action: aws:executeAwsApi onFailure: Abort inputs: Service: ec2 Api: CreateVolume AvailabilityZone: "{{ getInstanceDetails.availabilityZone }}" SnapshotId: "{{ getSnapshotsByStartTime.latestSnapshotId }}" outputs: - Name: newRootVolumeId Selector: "$.VolumeId" Type: String
nextStep: stopInstance - name: stopInstance action: aws:executeAwsApi onFailure: Abort inputs: Service: ec2 Api: StopInstances InstanceIds: - "{{ InstanceId }}" nextStep: verifyVolumeAvailability - name: verifyVolumeAvailability action: aws:waitForAwsResourceProperty timeoutSeconds: 120 inputs: Service: ec2 Api: DescribeVolumes VolumeIds: - "{{ createNewRootVolumeFromSnapshot.newRootVolumeId }}" PropertySelector: "$.Volumes[0].State" DesiredValues: - "available" nextStep: verifyInstanceStopped - name: verifyInstanceStopped action: aws:waitForAwsResourceProperty timeoutSeconds: 120 inputs: Service: ec2 Api: DescribeInstances InstanceIds: - "{{ InstanceId }}" PropertySelector: "$.Reservations[0].Instances[0].State.Name" DesiredValues: - "stopped" nextStep: detachRootVolume - name: detachRootVolume action: aws:executeAwsApi onFailure: Abort
isCritical: true inputs: Service: ec2 Api: DetachVolume VolumeId: "{{ getRootVolumeId.rootVolumeId }}" nextStep: verifyRootVolumeDetached - name: verifyRootVolumeDetached action: aws:waitForAwsResourceProperty timeoutSeconds: 30 inputs: Service: ec2 Api: DescribeVolumes VolumeIds: - "{{ getRootVolumeId.rootVolumeId }}" PropertySelector: "$.Volumes[0].State" DesiredValues: - "available" nextStep: attachNewRootVolume - name: attachNewRootVolume action: aws:executeAwsApi onFailure: Abort inputs: Service: ec2 Api: AttachVolume Device: "{{ getInstanceDetails.rootDeviceName }}" InstanceId: "{{ InstanceId }}" VolumeId: "{{ createNewRootVolumeFromSnapshot.newRootVolumeId }}" nextStep: verifyNewRootVolumeAttached - name: verifyNewRootVolumeAttached action: aws:waitForAwsResourceProperty timeoutSeconds: 30
inputs: Service: ec2 Api: DescribeVolumes VolumeIds: - "{{ createNewRootVolumeFromSnapshot.newRootVolumeId }}" PropertySelector: "$.Volumes[0].Attachments[0].State" DesiredValues: - "attached" nextStep: startInstance - name: startInstance action: aws:executeAwsApi onFailure: Abort inputs: Service: ec2 Api: StartInstances InstanceIds: - "{{ InstanceId }}"