文件範例儲存庫中有更多 AWS SDK可用的範例。 AWS SDK
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
CreateAssociationBatch
搭配 使用 CLI
下列程式碼範例示範如何使用 CreateAssociationBatch
。
- CLI
-
- AWS CLI
-
若要建立多個關聯
此範例會將組態文件與多個執行個體建立關聯。輸出會傳回成功和失敗操作的清單,如適用。
命令:
aws ssm create-association-batch --entries
"Name=AWS-UpdateSSMAgent,InstanceId=i-1234567890abcdef0"
"Name=AWS-UpdateSSMAgent,InstanceId=i-9876543210abcdef0"
輸出:
{ "Successful": [ { "Name": "AWS-UpdateSSMAgent", "InstanceId": "i-1234567890abcdef0", "AssociationVersion": "1", "Date": 1550504725.007, "LastUpdateAssociationDate": 1550504725.007, "Status": { "Date": 1550504725.007, "Name": "Associated", "Message": "Associated with AWS-UpdateSSMAgent" }, "Overview": { "Status": "Pending", "DetailedStatus": "Creating" }, "DocumentVersion": "$DEFAULT", "AssociationId": "8dfe3659-4309-493a-8755-0123456789ab", "Targets": [ { "Key": "InstanceIds", "Values": [ "i-1234567890abcdef0" ] } ] }, { "Name": "AWS-UpdateSSMAgent", "InstanceId": "i-9876543210abcdef0", "AssociationVersion": "1", "Date": 1550504725.057, "LastUpdateAssociationDate": 1550504725.057, "Status": { "Date": 1550504725.057, "Name": "Associated", "Message": "Associated with AWS-UpdateSSMAgent" }, "Overview": { "Status": "Pending", "DetailedStatus": "Creating" }, "DocumentVersion": "$DEFAULT", "AssociationId": "9c9f7f20-5154-4fed-a83e-0123456789ab", "Targets": [ { "Key": "InstanceIds", "Values": [ "i-9876543210abcdef0" ] } ] } ], "Failed": [] }
-
如需API詳細資訊,請參閱 命令參考 CreateAssociationBatch
中的 。 AWS CLI
-
- PowerShell
-
- 適用於 的工具 PowerShell
-
範例 1:此範例會將組態文件與多個執行個體建立關聯。輸出會傳回成功和失敗操作的清單,如適用。
$option1 = @{InstanceId="i-0cb2b964d3e14fd9f";Name=@("AWS-UpdateSSMAgent")} $option2 = @{InstanceId="i-0000293ffd8c57862";Name=@("AWS-UpdateSSMAgent")} New-SSMAssociationFromBatch -Entry $option1,$option2
輸出:
Failed Successful ------ ---------- {} {Amazon.SimpleSystemsManagement.Model.FailedCreateAssociation, Amazon.SimpleSystemsManagement.Model.FailedCreateAsso...
範例 2:此範例會顯示成功操作的完整詳細資訊。
$option1 = @{InstanceId="i-0cb2b964d3e14fd9f";Name=@("AWS-UpdateSSMAgent")} $option2 = @{InstanceId="i-0000293ffd8c57862";Name=@("AWS-UpdateSSMAgent")} (New-SSMAssociationFromBatch -Entry $option1,$option2).Successful
-
如需API詳細資訊,請參閱 AWS Tools for PowerShell Cmdlet 參考 CreateAssociationBatch中的 。
-
CreateAssociation
CreateDocument