ExecuteCommand
Runs a command remotely on a container within a task.
If you use a condition key in your IAM policy to refine the conditions for the
policy statement, for example limit the actions to a specific cluster, you receive an
AccessDeniedException
when there is a mismatch between the condition
key value and the corresponding parameter value.
For information about required permissions and considerations, see Using Amazon ECS Exec for debugging in the Amazon ECS Developer Guide.
Request Syntax
{
"cluster": "string
",
"command": "string
",
"container": "string
",
"interactive": boolean
,
"task": "string
"
}
Request Parameters
For information about the parameters that are common to all actions, see Common Parameters.
The request accepts the following data in JSON format.
- cluster
-
The Amazon Resource Name (ARN) or short name of the cluster the task is running in. If you do not specify a cluster, the default cluster is assumed.
Type: String
Required: No
- command
-
The command to run on the container.
Type: String
Required: Yes
- container
-
The name of the container to execute the command on. A container name only needs to be specified for tasks containing multiple containers.
Type: String
Required: No
- interactive
-
Use this flag to run your command in interactive mode.
Type: Boolean
Required: Yes
- task
-
The Amazon Resource Name (ARN) or ID of the task the container is part of.
Type: String
Required: Yes
Response Syntax
{
"clusterArn": "string",
"containerArn": "string",
"containerName": "string",
"interactive": boolean,
"session": {
"sessionId": "string",
"streamUrl": "string",
"tokenValue": "string"
},
"taskArn": "string"
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- clusterArn
-
The Amazon Resource Name (ARN) of the cluster.
Type: String
- containerArn
-
The Amazon Resource Name (ARN) of the container.
Type: String
- containerName
-
The name of the container.
Type: String
- interactive
-
Determines whether the execute command session is running in interactive mode. Amazon ECS only supports initiating interactive sessions, so you must specify
true
for this value.Type: Boolean
- session
-
The details of the SSM session that was created for this instance of execute-command.
Type: Session object
- taskArn
-
The Amazon Resource Name (ARN) of the task.
Type: String
Errors
For information about the errors that are common to all actions, see Common Errors.
- AccessDeniedException
-
You don't have authorization to perform the requested action.
HTTP Status Code: 400
- ClientException
-
These errors are usually caused by a client action. This client action might be using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Or, it might be specifying an identifier that isn't valid.
The following list includes additional causes for the error:
-
The
RunTask
could not be processed because you use managed scaling and there is a capacity error because the quota of tasks in thePROVISIONING
per cluster has been reached. For information about the service quotas, see Amazon ECS service quotas.
HTTP Status Code: 400
-
- ClusterNotFoundException
-
The specified cluster wasn't found. You can view your available clusters with ListClusters. Amazon ECS clusters are Region specific.
HTTP Status Code: 400
- InvalidParameterException
-
The specified parameter isn't valid. Review the available parameters for the API request.
HTTP Status Code: 400
- ServerException
-
These errors are usually caused by a server issue.
HTTP Status Code: 500
- TargetNotConnectedException
-
The execute command cannot run. This error can be caused by any of the following configuration issues:
-
Incorrect IAM permissions
-
The SSM agent is not installed or is not running
-
There is an interface Amazon VPC endpoint for Amazon ECS, but there is not one for Systems Manager Session Manager
For information about how to troubleshoot the issues, see Troubleshooting issues with ECS Exec in the Amazon Elastic Container Service Developer Guide.
HTTP Status Code: 400
-
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: