新建一條 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 |
| Name |
string |
是 |
命令名稱,支援全字元集。長度不得超過 128 個字元。 |
testName |
| Description |
string |
否 |
命令描述,支援全字元集。長度不得超過 512 個字元。 |
testDescription |
| Type |
string |
是 |
命令的類型。取值範圍:
|
RunShellScript |
| CommandContent |
string |
是 |
命令 Base64 編碼後的內容。
|
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. | |
| 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. | |
| 400 | InvalidParameter.WorkingDir | The specified parameter WorkingDir is not valid. | |
| 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. | |
| 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. |
訪問錯誤中心查看更多錯誤碼。
變更歷史
更多資訊,參考變更詳情。