executeCommand method

Future<ExecuteCommandResponse> executeCommand({
  1. required String command,
  2. required bool interactive,
  3. required String task,
  4. String? cluster,
  5. String? container,
})

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.

May throw AccessDeniedException. May throw ClientException. May throw ClusterNotFoundException. May throw InvalidParameterException. May throw ServerException. May throw TargetNotConnectedException.

Parameter command : The command to run on the container.

Parameter interactive : Use this flag to run your command in interactive mode.

Parameter task : The Amazon Resource Name (ARN) or ID of the task the container is part of.

Parameter 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.

Parameter container : The name of the container to execute the command on. A container name only needs to be specified for tasks containing multiple containers.

Implementation

Future<ExecuteCommandResponse> executeCommand({
  required String command,
  required bool interactive,
  required String task,
  String? cluster,
  String? container,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AmazonEC2ContainerServiceV20141113.ExecuteCommand'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'command': command,
      'interactive': interactive,
      'task': task,
      if (cluster != null) 'cluster': cluster,
      if (container != null) 'container': container,
    },
  );

  return ExecuteCommandResponse.fromJson(jsonResponse.body);
}