スクリプトを実行するランブックの作成 (コマンドライン)
次の例は、AWS CLI または AWS Tools for PowerShellを使用して、Attachment
パラメーターを使用してスクリプトを実行するランブックを作成する方法を示しています。
開始する前に
開始する前に、次のリソースが準備されていることを確認してください。
-
MyAutomationDocument.yaml
などの yaml 拡張子を持つ YAML 形式のランブックのコンテンツです。
-
ランブックに添付するファイル。スクリプトファイルまたは.zip ファイルを添付できます。
スクリプトの場合、オートメーションは Python 3.6 および 3.7、PowerShell Core 6.0 をサポートしています。
まだ AWS CLI または AWS Tools for PowerShell をインストールして設定していない場合は、インストールして設定します。
詳細については、「AWS コマンドラインツールのインストールまたはアップグレード」を参照してください。
S3 バケットから 1 つのファイルを添付する
S3 バケットに保存されているスクリプトファイルを使用してランブックを作成するには、次のコマンドを実行します。
- Linux & macOS
-
aws ssm create-document \
--name CustomAutomationScript
\
--content file://Runbook.yaml
\
--document-format YAML \
--attachments "Key=S3FileUrl,Name=script.py
,Values=https://DOC-EXAMPLE-BUCKET
.s3-aws-region.amazonaws.com/filePath
" \
--document-type Automation
- Windows
-
aws ssm create-document ^
--name CustomAutomationScript
^
--content file://AutomationDocument.yaml
^
--document-format YAML ^
--attachments Key=S3FileUrl,Name=script.py
,Values="https://DOC-EXAMPLE-BUCKET
.s3-aws-region.amazonaws.com/filePath
" ^
--document-type Automation
- PowerShell
-
New-SSMDocument `
-Name CustomAutomationScript
`
-Content file://AutomationDocument.yaml
`
-DocumentFormat YAML `
-Attachments @{
"Key"="S3FileUrl";
"Name"="script.py
";
"Values"="https://DOC-EXAMPLE-BUCKET
.s3-aws-region.amazonaws.com/filePath
"
}, @{
"Key"="S3FileUrl";
"Name"="Zip-file.zip
";
"Values"="https://DOC-EXAMPLE-BUCKET
.s3-aws-region.amazonaws.com/filePath
"
} `
-DocumentType Automation
S3 バケットからのファイルの添付
S3 バケットに保存されているスクリプトまたは複数のスクリプトファイルを使用して、ランブックを作成するには、次のコマンドを実行します。ファイルの Name
キーは指定されていません。コマンドは、サポートされているすべてのファイルを S3 バケットの場所から添付します。
- Linux & macOS
-
aws ssm create-document \
--name CustomAutomationScript
\
--content file://Runbook.yaml
\
--document-format YAML \
--attachments Key=SourceUrl,Values="https://DOC-EXAMPLE-BUCKET
.s3-aws-region.amazonaws.com/filePath
" \
--document-type Automation
- Windows
-
aws ssm create-document ^
--name CustomAutomationScript
^
--content file://Runbook.yaml
^
--document-format YAML ^
--attachments Key=SourceUrl,Values="https://DOC-EXAMPLE-BUCKET
.s3-aws-region.amazonaws.com/filePath
" ^
--document-type Automation
- PowerShell
-
New-SSMDocument `
-Name CustomAutomationScript
`
-Content file://Runbook.yaml
`
-DocumentFormat YAML `
-Attachments @{
"Key"="SourceUrl";
"Values"="https://DOC-EXAMPLE-BUCKET
.s3-aws-region.amazonaws.com/filePath
"
} `
-DocumentType Automation
アカウント内の別のランブックのファイルをアタッチするAWS アカウント
アカウント内の別のランブックに既にアタッチされているスクリプトを使用してランブックを作成するには、次のコマンドを実行します。
このコマンドのキー値の形式は、runbook-name/runbook-version-number/file-name
です。次の例を参照してください。
"MyDocument/2/script.py"
- Linux & macOS
-
aws ssm create-document \
--name CustomAutomationScript
\
--content file://Runbook.yaml
\
--document-format YAML \
--attachments Key=AttachmentReference,Values="runbook-name/runbook-version-number
/file-name" \
--document-type Automation
- Windows
-
aws ssm create-document ^
--name CustomAutomationScript
^
--content file://Runbook.yaml
^
--document-format YAML ^
--attachments Key=AttachmentReference,Values="runbook-name/runbook-version-number/file-name
" ^
--document-type Automation
- PowerShell
-
New-SSMDocument `
-Name CustomAutomationScript
`
-Content file://Runbook.yaml
`
-DocumentFormat YAML `
-Attachments @{
"Key"="AttachmentReference";
"Values"="runbook-name/runbook-version-number/file-name
"
} `
-DocumentType Automation
別の にランブックからファイルを添付するAWS アカウント
次のコマンドを実行して、別の から共有されているランブックに既にアタッチされているスクリプトを使用してランブックを作成しますAWS アカウント
このコマンドのキー値の形式は、runbook-arn/runbook-version-number/file-name
です。次の例を参照してください。
"arn:aws:ssm:us-east-2:123456789012:document/OtherAccountDocument/2/script.py"
- Linux & macOS
-
aws ssm create-document \
--name CustomAutomationScript
\
--content file://Runbook.yaml
\
--document-format YAML \
--attachments Key=AttachmentReference,Values="runbook-arn/runbook-version-number/file-name
/file-name" \
--document-type Automation
- Windows
-
aws ssm create-document ^
--name CustomAutomationScript
^
--content file://Runbook.yaml
^
--document-format YAML ^
--attachments Key=AttachmentReference,Values="runbook-arn/runbook-version-number/file-name
" ^
--document-type Automation
- PowerShell
-
New-SSMDocument `
-Name CustomAutomationScript
`
-Content file://Runbook.yaml
`
-DocumentFormat YAML `
-Attachments @{
"Key"="AttachmentReference";
"Values"="runbook-arn/runbook-version-number/file-name
"
} `
-DocumentType Automation