建立執行指令碼的 Runbook (命令列)
下列範例顯示如何使用 AWS CLI 或 AWS Tools for PowerShell,來建立使用 Attachment
參數執行指令碼的自動化文件。
開始之前
開始之前,請確保已準備好下列資源。
-
在具有 .yaml 副檔名的 YAML 格式檔案中 Runbook 的內容,例如 MyAutomationDocument.yaml
。
-
要連接至 Runbook 的檔案。您可以附加指令碼文件或 .zip 檔案。
對於指令碼,自動化支援 Python 3.6 和 3.7、PowerShell Core 6.0。
如果您尚未安裝並設定 AWS CLI 或 AWS Tools for PowerShell,請進行相應的操作。
如需相關資訊,請參閱安裝或升級 AWS 命令列工具。
從 S3 儲存貯體連接單一檔案
執行下列命令,使用儲存在 S3 儲存貯體中的一或多個指令檔案來建立 Runbook。
- 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 儲存貯體中的一或多個指令碼來建立 Runbook。未指定檔案的 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 連接檔案
執行下列命令,使用已連接至您帳戶中另一個 Runbook 的指令碼來建立 Runbook。
此命令中索引鍵值的格式是 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 帳戶 中的 Runbook 連接檔案
使用已連接至來自另一個 AWS 帳戶 且已經與您共用之 Runbook 的指令碼來執行以下命令建立 Runbook。
此命令中索引鍵值的格式是 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