建立一條Shell、PowerShell或者Bat指令碼類型的雲助手命令。
介面說明
介面說明
- 您可以建立以下類型的命令:
Windows 執行個體適用的 Bat 指令碼(RunBatScript)。
Windows 執行個體適用的 PowerShell 指令碼(RunPowerShellScript)。
Linux 執行個體適用的 Shell 指令碼(RunShellScript)。
- 您可以通過指定參數 Timeout 為命令設定在 ECS 執行個體中執行時最大的逾時時間,命令執行逾時後,雲助手 Agent會強制終止命令進程,即取消命令的 PID。
對於單次執行,逾時後,該命令針對指定的 ECS 執行個體的執行狀態( InvokeRecordStatus )變為執行失敗(Failed)。
- 對於定時執行:
定時執行的逾時時間對每一次執行記錄均有效。
某次執行逾時後,該次執行記錄的狀態( InvokeRecordStatus )變為執行失敗(Failed)。
上次執行逾時與否不影響下一次執行。
在一個地區下,您最多可以保有 500~50,000 條雲助手命令,您也可以申請提升配額,關於如何查詢及提升配額,請參見配額管理。
您可以通過指定參數 WorkingDir 為命令指定執行路徑。對於 Linux 執行個體,預設在管理員 root 使用者的 home 目錄下,具體為
/root目錄。對於 Windows 執行個體,預設在雲助手 Agent 進程所在目錄,例如:C:\Windows\System32。您可以通過指定參數 EnableParameter=true 啟用自訂參數功能。在設定 CommandContent 時可以通過{{parameter}}的形式表示自訂參數,並在運行命令( InvokeCommand )時,傳入自訂參數索引值對。例如,您在建立命令時,建立了
echo {{name}}命令,在 InvokeCommand 時,通過 Parameters 參數傳入索引值對<name, Jack>。則自訂參數將自動替換命令,您會得到一條新的命令,並在執行個體中執行echo Jack。
調試
您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。
調試
授權資訊
|
操作 |
存取層級 |
資源類型 |
條件關鍵字 |
關聯操作 |
|
ecs:CreateCommand |
create |
*Command
|
無 | 無 |
請求參數
|
名稱 |
類型 |
必填 |
描述 |
樣本值 |
| RegionId |
string |
是 |
地區 ID。您可以調用 DescribeRegions 查看最新的阿里雲地區列表。 |
cn-hangzhou |
| 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 |
否 |
您建立的命令在 ECS 執行個體中執行時最大的逾時時間,單位為秒。當因為某種原因無法運行您建立的命令時,會出現逾時現象。逾時後,會強制終止命令進程,即取消命令的 PID。 預設值:60。 |
60 |
| EnableParameter |
boolean |
否 |
建立的命令是否使用自訂參數。 預設值:false。 |
false |
| ContentEncoding |
string |
否 |
命令內容(CommandContent)的編碼方式。取值範圍:
預設值:Base64。 說明
錯填該取值會當作 Base64 處理。 |
PlainText |
| ClientToken |
string |
否 |
保證請求等冪性。從您的用戶端產生一個參數值,確保不同請求間該參數值唯一。ClientToken 只支援 ASCII 字元,且不能超過 64 個字元。更多資訊,請參見如何保證等冪性。 |
123e4567-e89b-12d3-a456-426655440000 |
| ResourceGroupId |
string |
否 |
命令所屬的資源群組 ID。 |
rg-123****** |
| Launcher |
string |
否 |
指令碼執行的引導程式。長度不能超過 1 KB。 |
python3 -u {{ACS::ScriptFileName|Ext(".py")}} |
| Tag |
array<object> |
否 |
標籤列表。 |
|
|
object |
否 |
標籤列表。 |
||
| Key |
string |
否 |
命令的標籤鍵。N 的取值範圍為 1~20。一旦傳入該值,則不允許為空白字串。 使用一個標籤過濾資源,查詢到該標籤下的資源數量不能超過 1000 個。使用多個標籤過濾資源,查詢到同時綁定了多個標籤的資源數量不能超過 1000 個。如果資源數量超過 1000 個,您需要使用 ListTagResources 介面進行查詢。 最多支援 64 個字元,不能以 |
TestKey |
| Value |
string |
否 |
命令的標籤值。N 的取值範圍為 1~20。該值可以為空白字串。 最多支援 128 個字元,不能包含 |
TestValue |
返回參數
|
名稱 |
類型 |
描述 |
樣本值 |
|
object |
|||
| CommandId |
string |
命令 ID。 |
c-7d2a745b412b4601b2d47f6a768d**** |
| RequestId |
string |
請求 ID。 |
473469C7-AA6F-4DC5-B3DB-A3DC0DE3**** |
樣本
正常返回樣本
JSON格式
{
"CommandId": "c-7d2a745b412b4601b2d47f6a768d****",
"RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****"
}
錯誤碼
|
HTTP status code |
錯誤碼 |
錯誤資訊 |
描述 |
|---|---|---|---|
| 400 | RegionId.ApiNotSupported | The api is not supported in this region. | 指定地區下不支援調用 API。請檢查 RegionId 參數取值是否正確。 |
| 400 | CmdParam.EmptyKey | You must specify the parameter names. | |
| 400 | CmdParam.InvalidParamName | Invalid parameter name. The name can contain only lowercase letters (a to z), uppercase letters (A to Z), numbers (0 to 9), hyphens (-), and underscores (_). | |
| 400 | CmdContent.DecodeError | The CommandContent can not be base64 decoded. | 命令內容無法通過Base64解碼。 |
| 400 | InvalidParameter.WorkingDir | The specified parameter WorkingDir is not valid. | 指定的參數WorkingDir不合法。 |
| 400 | InvalidClientToken.Malformed | The specified parameter clientToken is not valid. | 指定的等冪參數不合法。 |
| 500 | InternalError.Dispatch | An error occurred when you dispatched the request. | 發送請求時發生錯誤,請稍後重試。 |
| 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 | The maximum number of custom parameters is exceeded. | 參數數量超出最大可設定數量。 |
| 403 | CmdParamName.ExceedLimit | The maximum length of a parameter name is exceeded. | 您的自訂參數的參數名長度超過限制。 |
| 403 | Operation.Forbidden | The operation is not permitted. | 該操作是不被允許的。 |
| 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 | InvalidTimeout.ExceedLimit | The specified parameter Timeout exceeds the upper limit. | |
| 403 | IdempotentParameterMismatch | The specified parameter has changed while using an already used clientToken. | 指定的客戶令牌已經被使用。 |
| 403 | IdempotentProcessing | The previous idempotent request(s) is still processing. | 先前的等冪請求仍在處理中,請稍後重試。 |
| 404 | InvalidCmdType.NotFound | The specified command type does not exist. | |
| 404 | InvalidRegionId.NotFound | The RegionId provided does not exist in our records. | 地區資訊錯誤 |
| 404 | InvalidResourceGroup.NotFound | The ResourceGroup provided does not exist in our records. | 資源群組並不在記錄中。 |
訪問錯誤中心查看更多錯誤碼。
變更歷史
更多資訊,參考變更詳情。