本介面用於在一台或多台ECS執行個體中建立並執行雲助手命令,支援Shell、PowerShell或者Bat類型的指令碼,支援定時執行、自訂參數和執行個體內容器執行等功能。
介面說明
該介面為非同步介面,當前請求發送成功後,您可以通過返回的命令 ID 或命令執行 ID 調用 DescribeInvocations 或者 DescribeInvocationResults 查詢執行結果。
使用須知
目標執行個體的狀態為運行中(
Running),您可以調用 DescribeInstances 查詢。- 目標執行個體已經預先安裝雲助手 Agent,您可以通過 InstallCloudAssistant 進行安裝,並通過 DescribeCloudAssistantStatus 查詢安裝狀態。
說明
2017 年 12 月 01 日之後使用公用鏡像建立的 ECS 執行個體,預設預裝了雲助手 Agent。
執行 PowerShell 類型的命令時,您需要確保目標 ECS 執行個體的 Windows 作業系統已經配置了 PowerShell 模組。
注意事項
-
在單一地區下,最多可以保有 500~50,000 條雲助手命令,您也可以申請提升配額,請參見配額管理。
-
雲助手 Agent 版本需要不低於以下對應的版本才能支援定時任務的新特性(固定時間間隔執行、僅在指定時間執行一次、基於 Cron 運算式定時執行時指定年份或時區)。如果結果返回
ClientNeedUpgrade錯誤碼,請參見升級或禁止升級雲助手 Agent,將用戶端更新至最新版本。- Linux:2.2.3.282。 - Windows:2.1.3.282。 -
當您基於 Cron 運算式執行定時任務且指定了時區,時鐘定時執行時間設定基準為您指定的時區;當您沒有指定時區時,時鐘定時執行時間設定基準為 ECS 執行個體內的系統時區,且執行時間以執行個體的系統時間為準。請確保 ECS 執行個體的時間或者時區與您預期的時間一致。關於時區的更多資訊,請參見設定 Linux 執行個體時區和 NTP 服務或設定 Windows 執行個體 NTP 服務。
使用建議
- 逾時設定:您可以通過指定參數
Timeout為命令設定在 ECS 執行個體中執行時最大的逾時時間,命令執行逾時後,雲助手 Agent 會強制終止進程。單次執行逾時後,命令的執行狀態( InvokeRecordStatus )變為執行失敗(Failed)。
定時執行的逾時時間對每一次執行記錄均有效,上次執行逾時不影響下一次執行。某次執行逾時後,執行狀態( InvokeRecordStatus )變為執行失敗(Failed)。
執行失敗:命令可能會因為目標執行個體的狀態異常、網路異常或雲助手 Agent 異常而出現無法執行的情況,無法執行時不會產生執行資訊。更多資訊,請參見執行失敗常見錯誤及修複建議。
自訂參數:
EnableParameter=true時會啟用自訂參數功能。在設定CommandContent時可以通過{{parameter}}的形式表示自訂參數,並在運行命令時,傳入自訂參數索引值對。
調試
您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。
調試
授權資訊
|
操作 |
存取層級 |
資源類型 |
條件關鍵字 |
關聯操作 |
|
ecs:RunCommand |
update |
*Instance
|
|
無 |
請求參數
|
名稱 |
類型 |
必填 |
描述 |
樣本值 |
| RegionId |
string |
是 |
地區 ID。您可以調用 DescribeRegions 查看最新的阿里雲地區列表。 |
cn-hangzhou |
| ResourceGroupId |
string |
否 |
命令執行的資源群組 ID,當指定該參數時:
|
rg-bp67acfmxazb4p**** |
| RegionId |
string |
是 |
地區 ID。您可以調用 DescribeRegions 查看最新的阿里雲地區列表。 |
cn-hangzhou |
| Name |
string |
否 |
命令名稱。支援全字元集,長度不得超過 128 個字元。 |
testName |
| Description |
string |
否 |
命令描述。支援全字元集,長度不得超過 512 個字元。 |
testDescription |
| Type |
string |
是 |
命令類型。取值範圍:
|
RunShellScript |
| CommandContent |
string |
是 |
命令內容。命令內容可以是明文內容或 Base 64 編碼後的內容。您需要注意:
|
ZWNobyAxMjM= |
| WorkingDir |
string |
否 |
命令在 ECS 執行個體中的運行目錄。長度不得超過 200 個字元。 預設值:
|
/home/user |
| Timeout |
integer |
否 |
執行命令的逾時時間,單位:秒。 當因為進程原因、缺失模組、缺失雲助手 Agent 等原因無法運行命令時,會出現逾時現象。逾時後,會強制終止命令進程。 預設值:60。 |
3600 |
| EnableParameter |
boolean |
否 |
命令中是否包含自訂參數。 預設值:false。 |
false |
| RepeatMode |
string |
否 |
設定命令執行的方式。取值範圍:
預設值:
注意事項:
|
Once |
| Timed |
boolean |
否 |
說明
該參數已廢棄,傳入該參數不會生效。 |
true |
| Frequency |
string |
否 |
定時執行命令的執行時間。目前支援三種定時執行方式:固定時間間隔執行(基於 Rate 運算式)、僅在指定時間執行一次、基於時鐘定時執行(基於 Cron 運算式)。
|
0 */20 * * * ? |
| Parameters |
object |
否 |
命令中包含自訂參數時,執行命令時傳入的自訂參數的索引值對。例如,命令內容為 自訂參數的個數範圍為 0~10,且您需要注意:
預設值為空白,表示取消設定該參數從而禁用自訂參數。 |
{"name":"Jack", "accessKey":"LTAI*************"} |
| KeepCommand |
boolean |
否 |
執行完該命令後,是否保留下來。取值範圍:
預設值:false。 |
false |
| ContentEncoding |
string |
否 |
命令內容(
預設值:PlainText,亂填或錯填該取值會當作 PlainText 處理。 |
Base64 |
| Username |
string |
否 |
在 ECS 執行個體中執行命令的使用者名稱稱。長度不得超過 255 個字元。
您也可以指定執行個體中已存在的其他使用者執行命令,以普通使用者執行雲助手命令更加安全。更多資訊,請參見設定普通使用者執行雲助手命令。 |
test |
| WindowsPasswordName |
string |
否 |
在 Windows 執行個體中執行命令的使用者的密碼名稱。長度不得超過 255 個字元。 當您希望以非預設使用者(System)在 Windows 執行個體中執行命令時,需要同時傳入 說明
當您使用 Linux 執行個體的 root 使用者或 Windows 執行個體的 System 使用者執行命令時,不需要傳遞該參數。 |
axtSecretPassword |
| InstanceId |
array |
否 |
ECS 執行個體 ID 數組,數組長度:1~100。 若指定了多台執行個體後,其中某台執行個體不滿足執行條件時,您需要重新選擇。 您也可以在配額中心申請提升配額(配額名稱為命令執行支援執行個體上限數)。 |
i-bp185dy2o3o6neg**** |
|
string |
否 |
ECS 執行個體 ID。 |
i-bp185dy2o3o6neg**** |
|
| Tag |
array<object> |
否 |
標籤對數組,數組長度:0~20。 |
|
|
object |
否 |
標籤對。 |
||
| Value |
string |
否 |
命令執行的標籤值。該值可以為空白字串。 最多支援 128 個字元,不能包含 |
TestValue |
| Key |
string |
否 |
命令執行的標籤鍵。一旦傳入該值,則不允許為空白字串。 使用一個標籤過濾資源,查詢到該標籤下的資源數量不能超過 1000 個。使用多個標籤過濾資源,查詢到同時綁定了多個標籤的資源數量不能超過 1000 個。如果資源數量超過 1000 個,您需要使用 ListTagResources 介面進行查詢。 最多支援 64 個字元,不能以 |
TestKey |
| ContainerId |
string |
否 |
容器 ID。僅支援 64 位元 16 進位字串,允許存在 注意事項:
說明
在 Linux 容器中只支援執行 Shell 指令碼,不支援在指令碼開頭使用類似 |
ab141ddfbacfe02d9dbc25966ed971536124527097398d419a6746873fea**** |
| ContainerName |
string |
否 |
容器名稱。 注意事項:
說明
在 Linux 容器中只支援執行 Shell 指令碼,不支援在指令碼開頭使用類似 |
test-container |
| ClientToken |
string |
否 |
保證請求等冪性。從您的用戶端產生一個參數值,確保不同請求間該參數值唯一。ClientToken 只支援 ASCII 字元,且不能超過 64 個字元。更多資訊,請參見如何保證等冪性。 |
123e4567-e89b-12d3-a456-426655440000 |
| OssOutputDelivery |
string |
否 |
命令執行 Output OSS 投遞配置。
|
oss://testBucket/testPrefix |
| ResourceTag |
array<object> |
否 |
用於篩選執行個體的標籤數組,數組長度:0~20。可以在不指定 InstanceId 的情況下,向具有相同標籤的執行個體批量執行命令。 |
|
|
object |
否 |
用於篩選執行個體的標籤。可以在不指定 InstanceId 的情況下,向具有相同標籤的執行個體批量執行命令。 |
||
| Value |
string |
否 |
用於篩選執行個體的標籤值。 注意事項:
|
TestValue |
| Key |
string |
否 |
用於篩選執行個體的標籤鍵。 注意事項:
|
TestKey |
| TerminationMode |
string |
否 |
停止任務(手動停止或執行逾時打斷)時的模式。可能值:
|
ProcessTree |
| Launcher |
string |
否 |
指令碼執行的引導程式。長度不能超過 1 KB。 |
python3 -u {{ACS::ScriptFileName|Ext(".py")}} |
返回參數
|
名稱 |
類型 |
描述 |
樣本值 |
|
object |
|||
| RequestId |
string |
請求 ID。 |
473469C7-AA6F-4DC5-B3DB-A3DC0DE3**** |
| CommandId |
string |
命令 ID。 |
c-7d2a745b412b4601b2d47f6a768d**** |
| InvokeId |
string |
命令執行 ID。 |
t-7d2a745b412b4601b2d47f6a768d**** |
樣本
正常返回樣本
JSON格式
{
"RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****",
"CommandId": "c-7d2a745b412b4601b2d47f6a768d****",
"InvokeId": "t-7d2a745b412b4601b2d47f6a768d****"
}
錯誤碼
|
HTTP status code |
錯誤碼 |
錯誤資訊 |
描述 |
|---|---|---|---|
| 400 | RegionId.ApiNotSupported | The api is not supported in this region. | 指定地區下不支援調用 API。請檢查 RegionId 參數取值是否正確。 |
| 400 | ResourceBusy.SlrCreation | The ServiceLinkedRole is still being created or has not taken effect yet. Please try again later. | |
| 400 | MissingParam.InstanceId | The parameter instanceId is missing or empty. | 執行個體ID為空白。 |
| 400 | NumberExceed.Tags | Ensure the number of tag parameters is not greater than 20. | 標籤個數超過最大限制。 |
| 400 | InvalidTagValue.Malformed | The specified Tag.n.Value is not valid. | 指定的標籤值參數有誤。 |
| 400 | Duplicate.TagKey | The Tag.N.Key contain duplicate key. | 標籤中存在重複的鍵,請保持鍵的唯一性。 |
| 400 | InvalidTagKey.Malformed | The specified Tag.n.Key is not valid. | 指定的標籤鍵參數有誤。 |
| 400 | MissingParameter.TagKey | You must specify Tag.N.Key. | 請指定標籤鍵。 |
| 400 | InvalidContainerId.Malformed | The specified parameter ContainerId is not valid. | 指定的容器ID不合法。 |
| 400 | InvalidContainerName.Malformed | The specified parameter ContainerName is not valid. | 指定的容器名稱不合法。 |
| 400 | InvalidClientToken.Malformed | The specified parameter clientToken is not valid. | 指定的等冪參數不合法。 |
| 400 | CmdParam.EmptyKey | Command parameters can not be empty. | |
| 400 | CmdParam.InvalidParamName | A command parameter name is invalid. | |
| 400 | CmdContent.DecodeError | The CommandContent can not be base64 decoded. | 命令內容無法通過Base64解碼。 |
| 400 | InvalidInstance.NotMatch | The specified instance type does not match the command. | |
| 400 | MissingParam.Frequency | The frequency must be specified when you create a timed task. | |
| 400 | InvalidParam.Frequency | The specified frequency is invalid. | |
| 400 | ParameterKey.Duplicate | The parameter may not contain duplicate keys. | 參數名稱不能重複,請確認後重試。 |
| 400 | Parameter.NotMatched | The parameters of creation do not match those of invocation. | 傳入的自訂參數與建立命令時定義的自訂參數不匹配。 |
| 400 | WindowsPasswordName.Missed | WindowsPasswordName must be specified when you create a Windows task. | |
| 400 | Parameter.Disabled | Parameters should not be passed when CreateCommand.EnableParameter is false. | 當您禁用命令自訂參數功能時,請不要傳遞自訂參數。 |
| 400 | InvalidParameter.WorkingDir | The specified parameter WorkingDir is not valid. | 指定的參數WorkingDir不合法。 |
| 400 | NumberExceed.ResourceTags | The maximum number of ResourceTags is exceeded. | |
| 400 | MissingParameter.ResourceTagKey | You must specify ResourceTag.N.Key. | |
| 400 | InvalidResourceTagKey.Malformed | The specified ResourceTag key is not valid. | |
| 400 | InvalidResourceTagValue.Malformed | The specified ResourceTag value is not valid. | |
| 400 | Duplicate.ResourceTagKey | The ResourceTag contains duplicate keys. | |
| 400 | InvalidResourceTag.InstanceNotFound | InstanceIds are not found by the specified ResourceTag. | |
| 400 | InvalidResourceTag.ConflictWithInstanceIds | The specified param ResourceTag conflicts with InstanceId. | |
| 400 | InvalidOssOutputDelivery.BucketInOtherRegion | The OSS bucket specified in the parameter OssOutputDelivery is in another region. | 參數OssOutputDelivery 中指定的 OSS bucket在其他地區。 |
| 400 | InvalidParameter.OssOutputDelivery | The specified parameter OssOutputDelivery is not valid. | 指定的參數OssOutputDelivery不合法。 |
| 400 | InvalidOssOutputDelivery.KeyPrefixMalformed | The prefix of the OSS key specified in the parameter OssOutputDelivery is not valid. | 參數OssOutputDelivery中指定的prefix不合法。 |
| 500 | InternalError.Dispatch | An error occurred when you dispatched the request. | 發送請求時發生錯誤,請稍後重試。 |
| 403 | InvalidOssOutputDelivery.BucketAccessDenied | The error message returned by the OSS API is: %s | |
| 403 | CmdContent.ExceedLimit | The length of the command content exceeds the upper limit. | 命令內容長度超過上限。 |
| 403 | CmdName.ExceedLimit | The length of the command name exceeds the upper limit. | 命令名稱長度超過上限。 |
| 403 | CmdDesc.ExceedLimit | The length of the command description exceeds the upper limit. | 命令描述長度超過上限。 |
| 403 | CmdCount.ExceedQuota | The total number of commands in the current region exceeds the quota. | 當前地區下的雲助手命令數量已超出限制。 |
| 403 | CmdParamCount.ExceedLimit | You've reached the limit on the count of command parameters. | |
| 403 | CmdParamName.ExceedLimit | The length of the command parameter name exceeds the limit. | 命令中自訂參數名稱長度超過上限。 |
| 403 | InstanceIds.ExceedLimit | The number of instance IDs exceeds the upper limit. | 目標執行個體數量超過上限。 |
| 403 | Invocation.ExceedQuota | The invocation quota in the current region has been reached for today. | 在當前地區命令執行次數已到達今天的額度。 |
| 403 | ParameterCount.ExceedLimit | The number of command parameters exceeds the maximum number that can be set. | 自訂參數的個數超過限制。 |
| 403 | ParameterKey.ExceedLimit | The length of the specified parameter key exceeds the maximum length that can be set. | 指定的參數Key長度超過可設定的最大長度。 |
| 403 | ParameterType.NotSupported | The type of parameter value is not supported. | |
| 403 | Username.ExceedLimit | The length of the username exceeds the upper limit. | 使用者名稱長度超過上限。 |
| 403 | WindowsPasswordName.ExceedLimit | The length of the WindowsPasswordName exceeds the upper limit. | 指定的WindowsPasswordName參數長度超過上限。 |
| 403 | ParameterStore.NotSupported | Parameter Store is not supported in this region. | |
| 403 | TemporaryAccessKey.Error | The temporary accessKey is invalid. | |
| 403 | ParameterStore.InvalidParameters | The parameter is invalid in Parameter Store. | 未找到命令內容中的{{oos:?}}所指定的參數。 |
| 403 | ParameterStore.NoPermission | You have no access to Parameter Store. | |
| 403 | OperationDenied.BidOwnResource | Bid user can not own resource. | |
| 403 | Operation.Forbidden | The operation is not permitted. | 該操作是不被允許的。 |
| 403 | IdempotentParameterMismatch | The specified parameter has changed while using an already used clientToken. | 指定的客戶令牌已經被使用。 |
| 403 | IdempotentProcessing | The previous idempotent request(s) is still processing. | 先前的等冪請求仍在處理中,請稍後重試。 |
| 403 | InvalidStatus.ResourceGroup | You cannot perform an operation on a resource group that is being created or deleted. | 資源群組正在建立或刪除時不允許操作。 |
| 403 | InvalidParameterCharacter.CommandName | The command Name contains illegal characters. | 命令名稱包含非法字元。 |
| 403 | InvalidParameterCharacter.CommandDescription | The command Description contains illegal characters. | 命令描述包含非法字元。 |
| 403 | InvalidParameterCharacter.CommandWorkingDir | The command WorkingDir contains illegal characters. | 命令執行路徑包含非法字元。 |
| 403 | InvalidLauncher.LengthLimitExceeded | The length of the parameter Launcher exceeds the limit of 1 KB characters. | 參數Launcher的長度超過了 1 KB個字元的限制。 |
| 403 | InvalidParameterCharset.Parameters | The parameter Parameters contains illegal charset. | 命令參數包含非法字元集。 |
| 403 | CreateServiceLinkedRole.NoPermission | You do not have permission to create ServiceLinkedRole for output delivery. | 您沒有為output投遞功能建立服務關聯角色的許可權。 |
| 403 | InvalidTimeout.ExceedLimit | The specified parameter Timeout exceeds the upper limit. | |
| 404 | InvalidCmdType.NotFound | The specified command type does not exist. | |
| 404 | InvalidRepeatMode.NotFound | The specified repeat mode does not exist. | 指定的命令執行方式不存在。 |
| 404 | InvalidRegionId.NotFound | The RegionId provided does not exist in our records. | 地區資訊錯誤 |
| 404 | InvalidInstance.NotFound | The specified instance does not exist. | 指定的執行個體不存在。 |
| 404 | InvalidCmdId.NotFound | The specified command ID does not exist. | 指定的 CommandId 參數有誤,請檢查參數值是否正確。您可以通過介面 DescribeCommands 查詢所有可用的 CommandId。 |
| 404 | InvalidResourceGroup.NotFound | The ResourceGroup provided does not exist in our records. | 資源群組並不在記錄中。 |
| 404 | InvalidTerminationMode.NotFound | The specified parameter TerminationMode does not exist. | 指定的參數TerminationMode不存在。 |
| 404 | InvalidOssOutputDelivery.BucketNotFound | The OSS bucket specified in the parameter OssOutputDelivery does not exist. | 參數OssOutputDelivery中指定的bucket不存在。 |
訪問錯誤中心查看更多錯誤碼。
變更歷史
更多資訊,參考變更詳情。