搭UpdateDocument配 AWS SDK或使用 CLI - AWS SDK 程式碼範例

AWS 文檔 AWS SDK示例 GitHub 回購中有更多SDK示例

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

UpdateDocument配 AWS SDK或使用 CLI

下列程式碼範例會示範如何使用UpdateDocument

CLI
AWS CLI

若要建立文件的新版本

下列update-document範例會在 Windows 電腦上執行時建立文件的新版本。由指定的文件--document必須是JSON格式。請注意,file://必須在後面加上內容檔案的路徑參考。因為$--document-version參數的開頭,在 Windows 上,您必須用雙引號括住值。在 Linux、MacOS 或出現提 PowerShell 示時,您必須以單引號括住該值。

視窗版本

aws ssm update-document \ --name "RunShellScript" \ --content "file://RunShellScript.json" \ --document-version "$LATEST"

Linux/Mac 版本:

aws ssm update-document \ --name "RunShellScript" \ --content "file://RunShellScript.json" \ --document-version '$LATEST'

輸出:

{ "DocumentDescription": { "Status": "Updating", "Hash": "f775e5df4904c6fa46686c4722fae9de1950dace25cd9608ff8d622046b68d9b", "Name": "RunShellScript", "Parameters": [ { "Type": "StringList", "Name": "commands", "Description": "(Required) Specify a shell script or a command to run." } ], "DocumentType": "Command", "PlatformTypes": [ "Linux" ], "DocumentVersion": "2", "HashType": "Sha256", "CreatedDate": 1487899655.152, "Owner": "809632081692", "SchemaVersion": "2.0", "DefaultVersion": "1", "LatestVersion": "2", "Description": "Run an updated script" } }
  • 如需詳API細資訊,請參閱AWS CLI 指令參考UpdateDocument中的。

PowerShell
適用的工具 PowerShell

示例 1:這將創建一個新版本的文檔,其中包含您指定的 json 文件的更新內容。文件必須是格JSON式。您可以使用「Get-SSMDocumentVersionList」指令程式取得文件版本。

Update-SSMDocument -Name RunShellScript -DocumentVersion "1" -Content (Get-Content -Raw "c:\temp\RunShellScript.json")

輸出:

CreatedDate : 3/1/2017 2:59:17 AM DefaultVersion : 1 Description : Run an updated script DocumentType : Command DocumentVersion : 2 Hash : 1d5ce820e999ff051eb4841ed887593daf77120fd76cae0d18a53cc42e4e22c1 HashType : Sha256 LatestVersion : 2 Name : RunShellScript Owner : 809632081692 Parameters : {commands} PlatformTypes : {Linux} SchemaVersion : 2.0 Sha1 : Status : Updating
  • 如需詳API細資訊,請參閱AWS Tools for PowerShell 指令程UpdateDocument式參考中的。