AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
创建运行脚本的运行手册(命令行)
以下示例说明如何使用 AWS CLI 或 适用于 PowerShell 的 AWS 工具 创建使用 Attachment
参数运行脚本的 运行手册。
开始前的准备工作
在开始之前,请确保您准备好了以下资源。
-
具有 .yaml 扩展名的 YAML 格式文件(如 MyAutomationDocument.yaml
)中的运行手册的内容。
-
要附加到运行手册的文件。您可以附加脚本文件或 .zip 文件。
对于脚本,Automation 支持 Python 3.6 和 3.7 以及 PowerShell Core 6.0。
-
安装并配置 AWS CLI 或 适用于 PowerShell 的 AWS 工具(如果尚未执行该操作)。
有关信息,请参阅安装或升级 AWS 命令行工具。
附加 S3 存储桶中的单个文件
运行以下命令以使用存储在 S3 存储桶中的脚本文件创建运行手册。
- Linux
-
aws ssm create-document \
--name CustomAutomationScript
\
--content file://Runbook.yaml
\
--document-format YAML \
--attachments "Key=S3FileUrl,Name=script.py
,Values=https://.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://.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://.s3-aws-region.amazonaws.com/filePath
"
}, @{
"Key"="S3FileUrl";
"Name"="Zip-file.zip
";
"Values"="https://.s3-aws-region.amazonaws.com/filePath
"
} `
-DocumentType Automation
附加 S3 存储桶中的文件
运行以下命令以使用 S3 存储桶中存储的一个或多个脚本文件创建运行手册。请注意,未指定文件的 Name
键。该命令附加 S3 存储桶位置中的所有支持的文件。
- Linux
-
aws ssm create-document \
--name CustomAutomationScript
\
--content file://Runbook.yaml
\
--document-format YAML \
--attachments Key=SourceUrl,Values="https://.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://.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://.s3-aws-region.amazonaws.com/filePath
"
} `
-DocumentType Automation
从您 AWS 账户的另一个运行手册附加文件
运行以下命令以使用已附加到您账户中另一个运行手册的脚本创建运行手册。
此命令中键值的格式为 runbook-name/runbook-version-number/file-name
, 例如:
"MyDocument/2/script.py"
- Linux
-
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
-
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