1つ以上の ECS インスタンス上で、シェル、 PowerShell 、または Bat スクリプトなどのクラウドアシスタントコマンドを作成して実行します。この操作は、スケジュール実行、カスタムパラメーター、およびコンテナでの実行にも対応しています。
操作説明
本 API は非同期 API です。リクエストが成功すると、返されるコマンド ID または呼び出し ID を使用して DescribeInvocations または DescribeInvocationResults を呼び出し、実行結果を照会できます。
使用上の注意
-
ターゲットインスタンスは
Running状態である必要があります。DescribeInstances を呼び出してインスタンスステータスを照会できます。 -
ターゲットインスタンスに Cloud Assistant Agent が事前にインストールされている必要があります。そうでない場合は、InstallCloudAssistant を呼び出してインストールし、その後 DescribeCloudAssistantStatus を呼び出してインストールステータスを照会します。
説明デフォルトでは、2017 年 12 月 1 日以降にパブリックイメージから作成された Elastic Compute Service (ECS) インスタンスには、Cloud Assistant Agent がプリインストールされています。
-
PowerShell コマンドを実行する場合、インスタンスの Windows オペレーティングシステムに PowerShell モジュールが設定されていることを確認してください。
注意事項
-
単一のリージョンに 500〜50,000 個の Cloud Assistant コマンドを保持できます。より高いクォータをリクエストするには、「クォータ管理」をご参照ください。
-
定期タスクの新しい機能 (固定間隔でのタスクの実行、指定した時刻にタスクを 1 回だけ実行、cron 式ベースのタスクの年またはタイムゾーンの指定など) を使用するには、Cloud Assistant Agent が次のいずれかのバージョン以降である必要があります。
ClientNeedUpgradeエラーコードが返された場合は、「Cloud Assistant Agent のアップグレードまたはアップグレードの停止」を参照して、エージェントを最新バージョンに更新してください。- Linux: 2.2.3.282 - Windows: 2.1.3.282 -
cron 式に基づいて定期タスクを実行し、タイムゾーンを指定すると、タスクは指定されたタイムゾーンで実行されます。タイムゾーンを指定しない場合、タスクは ECS インスタンスのシステムタイムゾーンで実行され、実行時間はインスタンスのシステムクロックに依存します。ECS インスタンスの時刻とタイムゾーンが想定どおりに設定されていることを確認してください。タイムゾーンの詳細については、「Linux インスタンスのタイムゾーンと NTP サービスの設定」または「Windows インスタンスの NTP サービスの設定」をご参照ください。
推奨事項
-
タイムアウト設定:
Timeoutパラメーターを指定して、ECS インスタンスでのコマンドの最大実行タイムアウトを設定できます。コマンドの実行がタイムアウトすると、Cloud Assistant Agent はプロセスを強制的に終了します。-
一回実行がタイムアウトした場合、その実行ステータス (InvokeRecordStatus) は失敗になります。
-
定期タスクの場合、タイムアウト期間は各実行に適用されます。ある実行でのタイムアウトが次の実行に影響することはありません。実行がタイムアウトした場合、その実行ステータス (InvokeRecordStatus) は失敗になります。
-
-
実行の失敗: コマンドは、インスタンスの異常な状態、ネットワークの問題、または無応答の Cloud Assistant Agent が原因で失敗することがあります。これらの場合、実行情報は生成されません。詳細については、「実行失敗に関する一般的なエラーと推奨される修正方法」をご参照ください。
-
カスタムパラメーター: カスタムパラメーターを使用するには、
EnableParameterをtrueに設定します。その後、{{parameter}}フォーマットを使用してCommandContentでパラメーターを定義し、コマンドの実行時に対応するキーと値のペアを渡すことができます。
今すぐお試しください
テスト
RAM 認証
|
アクション |
アクセスレベル |
リソースタイプ |
条件キー |
依存アクション |
|
ecs:RunCommand |
update |
*Instance
|
|
なし |
リクエストパラメーター
|
パラメーター |
型 |
必須 / 任意 |
説明 |
例 |
| RegionId |
string |
必須 |
リージョン ID。DescribeRegions API を呼び出して、Alibaba Cloud の最新のリージョン情報を照会できます。 |
cn-hangzhou |
| ResourceGroupId |
string |
任意 |
コマンド実行のリソースグループ ID。このパラメーターを指定する場合、次のルールが適用されます。
|
rg-bp67acfmxazb4p**** |
| RegionId |
string |
必須 |
The ID of the region. You can call the DescribeRegions operation to query the latest Alibaba Cloud regions. |
cn-hangzhou |
| Name |
string |
任意 |
コマンドの名前。長さは最大 128 文字で、すべての文字セットをサポートします。 |
testName |
| Description |
string |
任意 |
コマンドの説明。長さは最大 512 文字で、すべての文字セットをサポートします。 |
testDescription |
| Type |
string |
必須 |
コマンドのタイプ。有効な値:
|
RunShellScript |
| CommandContent |
string |
必須 |
コマンドの内容。プレーンテキスト、または Base64 でエンコードして指定します。以下の点にご注意ください。
|
ZWNobyAxMjM= |
| WorkingDir |
string |
任意 |
コマンドを実行するインスタンス上の作業ディレクトリ。パスの長さは最大 200 文字です。 デフォルト値:
|
/home/user |
| Timeout |
integer |
任意 |
コマンド実行のタイムアウト時間 (秒単位)。 プロセス競合、モジュールの欠落、または Cloud Assistant Agent の無効化などの例外によりコマンドの実行に失敗した場合、タイムアウトによってコマンドプロセスが強制的に終了されます。 デフォルト値: 60。 |
3600 |
| EnableParameter |
boolean |
任意 |
コマンドでカスタムパラメーターを使用するかどうかを指定します。 デフォルト値: false。 |
false |
| RepeatMode |
string |
任意 |
コマンドの実行モード。有効な値:
デフォルト値:
注:
|
Once |
| Timed |
boolean |
任意 |
説明
このパラメーターは非推奨であり、機能しません。 |
true |
| Frequency |
string |
任意 |
コマンドのスケジュール。レート式、単発実行用の at 式、または cron 式を指定できます。
|
0 */20 * * * ? |
| Parameters |
object |
任意 |
カスタムパラメーターのキーと値のペア。たとえば、 0〜10 個のキーと値のペアを指定できます。以下の点にご注意ください。
デフォルト値は空です。これは、カスタムパラメーターが使用されないことを意味します。 |
{"name":"Jack", "accessKey":"LTAI*************"} |
| KeepCommand |
boolean |
任意 |
実行後にコマンドを保存するかどうかを指定します。有効な値:
デフォルト値: false。 |
false |
| ContentEncoding |
string |
任意 |
コマンド内容 (
デフォルト値: |
Base64 |
| Username |
string |
任意 |
ECS インスタンスでコマンドを実行するユーザーの名前。名前の長さは最大 255 文字です。
インスタンス上の別の既存のユーザーを指定してコマンドを実行できます。Cloud Assistant コマンドを標準ユーザーとして実行する方が安全です。詳細については、「Cloud Assistant コマンドを標準ユーザーとして実行する」をご参照ください。 |
test |
| WindowsPasswordName |
string |
任意 |
Windows インスタンスでコマンドを実行するユーザーのパスワードの名前。名前の長さは最大 255 文字です。 Windows インスタンスでデフォルト以外のユーザーとしてコマンドを実行するには、 説明
Linux インスタンスで |
axtSecretPassword |
| InstanceId |
array |
任意 |
コマンドを実行する ECS インスタンスの ID。1〜100 個のインスタンス ID を指定できます。 指定したいずれかのインスタンスが実行要件を満たしていない場合、操作全体が失敗します。 Quota Center でクォータの引き上げを申請できます。クォータ名は「Maximum number of instances supported per command execution」です。 |
i-bp185dy2o3o6neg**** |
|
string |
任意 |
ECS インスタンスの ID。 |
i-bp185dy2o3o6neg**** |
|
| Tag |
array<object> |
任意 |
タグペアの配列。配列には 0〜20 個のタグを含めることができます。 |
|
|
object |
任意 |
タグペア。 |
||
| Value |
string |
任意 |
コマンド実行のタグ値。値は空の文字列にできます。 値の長さは最大 128 文字で、 |
TestValue |
| Key |
string |
任意 |
コマンド実行のタグキー。キーを空の文字列にすることはできません。 キーの長さは最大 64 文字で、 値は最大 64 文字で、 |
TestKey |
| ContainerId |
string |
任意 |
コンテナの ID。ID は 64 ビットの 16 進文字列でなければなりません。 注:
説明
Linux コンテナでは、Shell スクリプトのみを実行できます。スクリプトの冒頭で |
ab141ddfbacfe02d9dbc25966ed971536124527097398d419a6746873fea**** |
| ContainerName |
string |
任意 |
コンテナの名前。 注:
説明
Linux コンテナでは、Shell スクリプトのみを実行できます。スクリプトの冒頭で |
test-container |
| ClientToken |
string |
任意 |
リクエストのべき等性を確保するために使用される、クライアントが生成するトークン。トークンはリクエストごとに一意である必要があります。 |
123e4567-e89b-12d3-a456-426655440000 |
| OssOutputDelivery |
string |
任意 |
コマンド出力を OSS に配信するための設定です。
|
oss://testBucket/testPrefix |
| ResourceTag |
array<object> |
任意 |
コマンド実行のためにインスタンスを絞り込むために使用されるタグ。これにより、インスタンス ID を指定するかわりに、一致するタグを持つすべてのインスタンスでコマンドを実行できます。配列には 0〜20 個のタグを含めることができます。 |
|
|
object |
任意 |
インスタンスを絞り込むために使用されるタグ。インスタンス ID を指定せずに、同じタグを持つ複数のインスタンスでコマンドを実行できます。 |
||
| 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**** |
例
成功レスポンス
JSONJSON
{
"RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****",
"CommandId": "c-7d2a745b412b4601b2d47f6a768d****",
"InvokeId": "t-7d2a745b412b4601b2d47f6a768d****"
}
エラーコード
|
HTTP ステータスコード |
エラーコード |
エラーメッセージ |
説明 |
|---|---|---|---|
| 400 | RegionId.ApiNotSupported | The api is not supported in this region. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 400 | InvalidParameter.OssOutputDelivery | The specified parameter OssOutputDelivery is not valid. | |
| 400 | InvalidOssOutputDelivery.KeyPrefixMalformed | The prefix of the OSS key specified in the parameter OssOutputDelivery is not valid. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 403 | InvalidParameterCharset.Parameters | The parameter Parameters contains illegal charset. | |
| 403 | CreateServiceLinkedRole.NoPermission | You do not have permission to create ServiceLinkedRole for output delivery. | |
| 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. | |
| 404 | InvalidResourceGroup.NotFound | The ResourceGroup provided does not exist in our records. | |
| 404 | InvalidTerminationMode.NotFound | The specified parameter TerminationMode does not exist. | |
| 404 | InvalidOssOutputDelivery.BucketNotFound | The OSS bucket specified in the parameter OssOutputDelivery does not exist. |
完全なリストについては、「エラーコード」をご参照ください。
変更履歴
完全なリストについては、「変更履歴」をご参照ください。