オートメーションシステム変数 - AWS Systems Manager

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

オートメーションシステム変数

AWS Systems Manager オートメーションランブックでは、以下の変数が使用されます。これらの変数の使用例については、AWS-UpdateWindowsAmi Runbook の JSON ソースを参照してください。

AWS-UpdateWindowsAmi ランブックの JSON ソースを表示するには
  1. AWS Systems Manager コンソール (https://console.aws.amazon.com/systems-manager/) を開きます。

  2. ナビゲーションペインで、[ドキュメント] を選択します。

  3. ドキュメントリストで、検索バーまたは検索バーの右側にある数字のいずれかを使用して、ランブック AWS-UpdateWindowsAmi を選択します。

  4. [Content] タブを選択します。

システム変数

オートメーションランブックでは、以下のシステム変数がサポートされています。

変数 詳細

global:ACCOUNT_ID

オートメーションを実行するユーザーまたはロールの AWS アカウント ID です。

global:DATE

yyyy-MM-dd 形式の日付 (実行時)。

global:DATE_TIME

yyyy-MM-dd_HH.mm.ss 形式の日時 (実行時)。

global:AWS_PARTITION

リソースが置かれているパーティションです。標準 AWS リージョン の場合、パーティションは aws です。他のパーティションのリソースについては、パーティションは aws-partitionname です。例えば、AWS GovCloud (米国西部) リージョンのリソースのパーティションは aws-us-gov です。

global:REGION

Runbook が実行されるリージョン。たとえば、us-east-2 です。

オートメーション変数

オートメーションランブックでは、以下の Automation 変数がサポートされています。

変数 詳細

automation:EXECUTION_ID

現在のオートメーションに割り当てられた一意の識別子 例えば、1a2b3c-1a2b3c-1a2b3c-1a2b3c1a2b3c1a2b3c です。

用語

以下の用語では、変数とパラメータの解決方法について説明します。

期間 定義

定数 ARN

変数を含まない有効な Amazon リソースネーム (ARN)。

arn:aws:iam::123456789012:role/roleName

Runbook パラメータ

Runbook レベル (instanceId など) で定義されたパラメータ。このパラメータは基本的な文字列置換で使用されます。その値は Start Execution 時に渡されます。

{ "description": "Create Image Demo", "version": "0.3", "assumeRole": "Your_Automation_Assume_Role_ARN", "parameters":{ "instanceId": { "type": "String", "description": "Instance to create image from" } }

システム変数

Runbook のいずれかの部分が評価されたときに Runbook に代入される一般的な変数。

"activities": [ { "id": "copyImage", "activityType": "AWS-CopyImage", "maxAttempts": 1, "onFailure": "Continue", "inputs": { "ImageName": "{{imageName}}", "SourceImageId": "{{sourceImageId}}", "SourceRegion": "{{sourceRegion}}", "Encrypted": true, "ImageDescription": "Test CopyImage Description created on {{global:DATE}}" } } ]

Automation 変数

Runbook のいずれかの部分が評価されたときに Runbook に代入される、オートメーションに関連した変数。

{ "name": "runFixedCmds", "action": "aws:runCommand", "maxAttempts": 1, "onFailure": "Continue", "inputs": { "DocumentName": "AWS-RunPowerShellScript", "InstanceIds": [ "{{LaunchInstance.InstanceIds}}" ], "Parameters": { "commands": [ "dir", "date", "“{{outputFormat}}” -f “left”,”right”,”{{global:DATE}}”,”{{automation:EXECUTION_ID}}” ] } } }

Systems Manager パラメータ

AWS Systems Manager Parameter Store 内で定義された変数。ステップ入力で直接参照することはできません。パラメータにアクセスするにはアクセス許可が必要な場合があります。

description: Launch new Windows test instance schemaVersion: '0.3' assumeRole: '{{AutomationAssumeRole}}' parameters: AutomationAssumeRole: type: String default: '' 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. LatestAmi: type: String default: >- {{ssm:/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base}} description: The latest Windows Server 2016 AMI queried from the public parameter. mainSteps: - name: launchInstance action: 'aws:runInstances' maxAttempts: 3 timeoutSeconds: 1200 onFailure: Abort inputs: ImageId: '{{LatestAmi}}' ...

サポートされるシナリオ

シナリオ コメント

作成時の一定 ARN assumeRole

権限付与チェックが実行されて、呼び出し元ユーザーが assumeRole の委譲を許可されていることが確認されます。

{ "description": "Test all Automation resolvable parameters", "schemaVersion": "0.3", "assumeRole": "arn:aws:iam::123456789012:role/roleName", "parameters": { ...

オートメーションの開始時に、AssumeRole に与えられる Runbook のパラメータ。

Runbook のパラメータリストで定義する必要があります。

{ "description": "Test all Automation resolvable parameters", "schemaVersion": "0.3", "assumeRole": "{{dynamicARN}}", "parameters": { ...

開始時に Runbook パラメータに渡される値

お客様がパラメータに使用する値を指定します。開始時に渡される入力は、Runbook のパラメータリストで定義する必要があります。

... "parameters": { "amiId": { "type": "String", "default": "ami-12345678", "description": "list of commands to run as part of first step" }, ...

Start Automation Execution への入力には {"amiId" : ["ami-12345678"] } を含めます。

ランブックコンテンツ内で参照される Systems Manager パラメータ。

変数は、顧客のアカウント内に存在するか、パブリックにアクセス可能なパラメータであり、Runbook の AssumeRole に変数へのアクセスがあります。作成時にチェックが実行されて、AssumeRole が変数にアクセスできることが確認されます。パラメータは、ステップ入力で直接参照することはできません。

... parameters: LatestAmi: type: String default: >- {{ssm:/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base}} description: The latest Windows Server 2016 AMI queried from the public parameter. mainSteps: - name: launchInstance action: 'aws:runInstances' maxAttempts: 3 timeoutSeconds: 1200 onFailure: Abort inputs: ImageId: '{{LatestAmi}}' ...

ステップ定義内で参照されるシステム変数

オートメーションが開始されると、システム変数が Runbook に代入されます。Runbook に挿入される値は、代入時の変数の値に対して相対的になります。たとえば、ステップ 1 で挿入される時間変数の値は、ステップの実行にかかる時間のため、ステップ 3 で挿入される時間変数の値とは異なります。システム変数は、ランブックのパラメータリストで設定する必要はありません。

... "mainSteps": [ { "name": "RunSomeCommands", "action": "aws:runCommand", "maxAttempts": 1, "onFailure": "Continue", "inputs": { "DocumentName": "AWS:RunPowerShell", "InstanceIds": ["{{LaunchInstance.InstanceIds}}"], "Parameters": { "commands" : [ "echo {The time is now {{global:DATE_TIME}}}" ] } } }, ...

ステップ定義内で参照される自動化の変数

Automation 変数は、ランブックのパラメータリストで設定する必要はありません。サポートされる Automation 変数は automation:EXECUTION_ID のみです。

... "mainSteps": [ { "name": "invokeLambdaFunction", "action": "aws:invokeLambdaFunction", "maxAttempts": 1, "onFailure": "Continue", "inputs": { "FunctionName": "Hello-World-LambdaFunction", "Payload" : "{ "executionId" : "{{automation:EXECUTION_ID}}" }" } } ...

次のステップ定義内からの前のステップの出力の参照

これはパラメータのリダイレクトです。前のステップの出力は、構文 {{stepName.OutputName}} を使用して参照されます。この構文は、お客様がランブックのパラメータに対して使用することはできません。これは、参照ステップの実行時に解決されます。ランブックのパラメータリストでは設定されません。

... "mainSteps": [ { "name": "LaunchInstance", "action": "aws:runInstances", "maxAttempts": 1, "onFailure": "Continue", "inputs": { "ImageId": "{{amiId}}", "MinInstanceCount": 1, "MaxInstanceCount": 2 } }, { "name":"changeState", "action": "aws:changeInstanceState", "maxAttempts": 1, "onFailure": "Continue", "inputs": { "InstanceIds": ["{{LaunchInstance.InstanceIds}}"], "DesiredState": "terminated" } } ...

サポートされないシナリオ

シナリオ コメント

作成時に assumeRole に渡される Systems Manager パラメータ

サポート外。

... { "description": "Test all Automation resolvable parameters", "schemaVersion": "0.3", "assumeRole": "{{ssm:administratorRoleARN}}", "parameters": { ...

ステップ入力で直接参照される Systems Manager パラメータ。

作成時に InvalidDocumentContent 例外を返します。

... mainSteps: - name: launchInstance action: 'aws:runInstances' maxAttempts: 3 timeoutSeconds: 1200 onFailure: Abort inputs: ImageId: '{{ssm:/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base}}' ...

変数によるステップの定義

Runbook 内のステップの定義は変数によって構成されます。

... "mainSteps": [ { "name": "LaunchInstance", "action": "aws:runInstances", "{{attemptModel}}": 1, "onFailure": "Continue", "inputs": { "ImageId": "ami-12345678", "MinInstanceCount": 1, "MaxInstanceCount": 2 } ... User supplies input : { "attemptModel" : "minAttempts" }

Runbook パラメータの相互参照

ユーザーは開始時に入力パラメータとして、Runbook 内の別のパラメータへの参照を渡します。

... "parameters": { "amiId": { "type": "String", "default": "ami-7f2e6015", "description": "list of commands to run as part of first step" }, "alternateAmiId": { "type": "String", "description": "The alternate AMI to try if this first fails". "default" : "{{amiId}}" }, ...

複数レベルの展開

Runbook で、変数の名前に評価される変数を定義します。これは、変数区切り記号 ({{ }}) 内にあり、変数/パラメータの値に展開されます。

... "parameters": { "firstParameter": { "type": "String", "default": "param2", "description": "The parameter to reference" }, "secondParameter": { "type": "String", "default" : "echo {Hello world}", "description": "What to run" } }, "mainSteps": [{ "name": "runFixedCmds", "action": "aws:runCommand", "maxAttempts": 1, "onFailure": "Continue", "inputs": { "DocumentName": "AWS-RunPowerShellScript", "InstanceIds" : "{{LaunchInstance.InstanceIds}}", "Parameters": { "commands": [ "{{ {{firstParameter}} }}"] } ... Note: The customer intention here would be to run a command of "echo {Hello world}"

別の変数タイプであるRunbook ステップからの出力の参照

ユーザーは前のRunbook ステップからの出力を後続のステップ内で参照します。出力は、後続のステップのアクションの要件を満たしていない変数タイプです。

... mainSteps: - name: getImageId action: aws:executeAwsApi inputs: Service: ec2 Api: DescribeImages Filters: - Name: "name" Values: - "{{ImageName}}" outputs: - Name: ImageIdList Selector: "$.Images" Type: "StringList" - name: copyMyImages action: aws:copyImage maxAttempts: 3 onFailure: Abort inputs: SourceImageId: {{getImageId.ImageIdList}} SourceRegion: ap-northeast-2 ImageName: Encrypted Copies of LAMP base AMI in ap-northeast-2 Encrypted: true ... Note: You must provide the type required by the Automation action. In this case, aws:copyImage requires a "String" type variable but the preceding step outputs a "StringList" type variable.