registerTaskWithMaintenanceWindow method

Future<RegisterTaskWithMaintenanceWindowResult> registerTaskWithMaintenanceWindow({
  1. required String taskArn,
  2. required MaintenanceWindowTaskType taskType,
  3. required String windowId,
  4. String? clientToken,
  5. String? description,
  6. LoggingInfo? loggingInfo,
  7. String? maxConcurrency,
  8. String? maxErrors,
  9. String? name,
  10. int? priority,
  11. String? serviceRoleArn,
  12. List<Target>? targets,
  13. MaintenanceWindowTaskInvocationParameters? taskInvocationParameters,
  14. Map<String, MaintenanceWindowTaskParameterValueExpression>? taskParameters,
})

Adds a new task to a maintenance window.

May throw IdempotentParameterMismatch. May throw DoesNotExistException. May throw ResourceLimitExceededException. May throw FeatureNotAvailableException. May throw InternalServerError.

Parameter taskArn : The ARN of the task to run.

Parameter taskType : The type of task being registered.

Parameter windowId : The ID of the maintenance window the task should be added to.

Parameter clientToken : User-provided idempotency token.

Parameter description : An optional description for the task.

Parameter loggingInfo : A structure containing information about an S3 bucket to write instance-level logs to.

Parameter maxConcurrency : The maximum number of targets this task can be run for in parallel.

Parameter maxErrors : The maximum number of errors allowed before this task stops being scheduled.

Parameter name : An optional name for the task.

Parameter priority : The priority of the task in the maintenance window, the lower the number the higher the priority. Tasks in a maintenance window are scheduled in priority order with tasks that have the same priority scheduled in parallel.

Parameter serviceRoleArn : The ARN of the IAM service role for Systems Manager to assume when running a maintenance window task. If you do not specify a service role ARN, Systems Manager uses your account's service-linked role. If no service-linked role for Systems Manager exists in your account, it is created when you run RegisterTaskWithMaintenanceWindow.

For more information, see the following topics in the in the AWS Systems Manager User Guide:

Parameter targets : The targets (either instances or maintenance window targets). Specify instances using the following format:

Key=InstanceIds,Values=<instance-id-1>,<instance-id-2>

Specify maintenance window targets using the following format:

Key=WindowTargetIds,Values=<window-target-id-1>,<window-target-id-2>

Parameter taskInvocationParameters : The parameters that the task should use during execution. Populate only the fields that match the task type. All other fields should be empty.

Parameter taskParameters : The parameters that should be passed to the task when it is run.

Implementation

Future<RegisterTaskWithMaintenanceWindowResult>
    registerTaskWithMaintenanceWindow({
  required String taskArn,
  required MaintenanceWindowTaskType taskType,
  required String windowId,
  String? clientToken,
  String? description,
  LoggingInfo? loggingInfo,
  String? maxConcurrency,
  String? maxErrors,
  String? name,
  int? priority,
  String? serviceRoleArn,
  List<Target>? targets,
  MaintenanceWindowTaskInvocationParameters? taskInvocationParameters,
  Map<String, MaintenanceWindowTaskParameterValueExpression>? taskParameters,
}) async {
  ArgumentError.checkNotNull(taskArn, 'taskArn');
  _s.validateStringLength(
    'taskArn',
    taskArn,
    1,
    1600,
    isRequired: true,
  );
  ArgumentError.checkNotNull(taskType, 'taskType');
  ArgumentError.checkNotNull(windowId, 'windowId');
  _s.validateStringLength(
    'windowId',
    windowId,
    20,
    20,
    isRequired: true,
  );
  _s.validateStringLength(
    'clientToken',
    clientToken,
    1,
    64,
  );
  _s.validateStringLength(
    'description',
    description,
    1,
    128,
  );
  _s.validateStringLength(
    'maxConcurrency',
    maxConcurrency,
    1,
    7,
  );
  _s.validateStringLength(
    'maxErrors',
    maxErrors,
    1,
    7,
  );
  _s.validateStringLength(
    'name',
    name,
    3,
    128,
  );
  _s.validateNumRange(
    'priority',
    priority,
    0,
    1152921504606846976,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AmazonSSM.RegisterTaskWithMaintenanceWindow'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'TaskArn': taskArn,
      'TaskType': taskType.toValue(),
      'WindowId': windowId,
      'ClientToken': clientToken ?? _s.generateIdempotencyToken(),
      if (description != null) 'Description': description,
      if (loggingInfo != null) 'LoggingInfo': loggingInfo,
      if (maxConcurrency != null) 'MaxConcurrency': maxConcurrency,
      if (maxErrors != null) 'MaxErrors': maxErrors,
      if (name != null) 'Name': name,
      if (priority != null) 'Priority': priority,
      if (serviceRoleArn != null) 'ServiceRoleArn': serviceRoleArn,
      if (targets != null) 'Targets': targets,
      if (taskInvocationParameters != null)
        'TaskInvocationParameters': taskInvocationParameters,
      if (taskParameters != null) 'TaskParameters': taskParameters,
    },
  );

  return RegisterTaskWithMaintenanceWindowResult.fromJson(jsonResponse.body);
}