execute_command
async
¶
execute_command(
command: String,
interactive: Boolean,
task: String,
*,
config_overrides: Optional[AsyncECSClientConfig] = None,
cluster: Optional[String] = None,
container: Optional[String] = None,
) -> ExecuteCommandResponse
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.
Parameters:
-
cluster(Optional[String], default:None) –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.
-
container(Optional[String], default:None) –The name of the container to execute the command on. A container name only needs to be specified for tasks containing multiple containers.
-
command(String) –The command to run on the container.
-
interactive(Boolean) –Use this flag to run your command in interactive mode.
-
task(String) –The Amazon Resource Name (ARN) or ID of the task the container is part of.
Raises:
-
AccessDeniedException–You don't have authorization to perform the requested action.
-
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.
-
ClusterNotFoundException–The specified cluster wasn't found. You can view your available clusters with ListClusters. Amazon ECS clusters are Region specific.
-
InvalidParameterException–The specified parameter isn't valid. Review the available parameters for the API request.
For more information about service event errors, see Amazon ECS service event messages.
-
ServerException–These errors are usually caused by a server issue.
-
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.
-
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To run a command remotely on a container in a task This example runs an interactive /bin/sh command on a container MyContainer.
>>> await client.execute_command(cluster='MyCluster', container='MyContainer', command='/bin/sh', interactive=True, task='arn:aws:ecs:us-east-1:123456789012:task/MyCluster/d789e94343414c25b9f6bd59eEXAMPLE')
Source code in docs_src/capo_ecs/_services/async_ecs.py
2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 | |