registerTaskWithMaintenanceWindow method

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

Adds a new task to a maintenance window.

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

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 alarmConfiguration : The CloudWatch alarm you want to apply to your maintenance window task.

Parameter clientToken : User-provided idempotency token.

Parameter cutoffBehavior : Indicates whether tasks should continue to run after the cutoff time specified in the maintenance windows is reached.

  • CONTINUE_TASK: When the cutoff time is reached, any tasks that are running continue. The default value.
  • CANCEL_TASK:
    • For Automation, Lambda, Step Functions tasks: When the cutoff time is reached, any task invocations that are already running continue, but no new task invocations are started.
    • For Run Command tasks: When the cutoff time is reached, the system sends a CancelCommand operation that attempts to cancel the command associated with the task. However, there is no guarantee that the command will be terminated and the underlying process stopped.
    The status for tasks that are not completed is TIMED_OUT.

Parameter description : An optional description for the task.

Parameter loggingInfo : A structure containing information about an Amazon Simple Storage Service (Amazon S3) bucket to write managed node-level logs to.

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

For maintenance window tasks without a target specified, you can't supply a value for this option. Instead, the system inserts a placeholder value of 1. This value doesn't affect the running of your task.

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

For maintenance window tasks without a target specified, you can't supply a value for this option. Instead, the system inserts a placeholder value of 1. This value doesn't affect the running of your task.

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 Amazon Resource Name (ARN) of the IAM service role for Amazon Web Services Systems Manager to assume when running a maintenance window task. If you do not specify a service role ARN, Systems Manager uses a service-linked role in your account. If no appropriate service-linked role for Systems Manager exists in your account, it is created when you run RegisterTaskWithMaintenanceWindow.

However, for an improved security posture, we strongly recommend creating a custom policy and custom service role for running your maintenance window tasks. The policy can be crafted to provide only the permissions needed for your particular maintenance window tasks. For more information, see Setting up Maintenance Windows in the in the Amazon Web Services Systems Manager User Guide.

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

Key=InstanceIds,Values=

Specify maintenance window targets using the following format:

Key=WindowTargetIds,Values=

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,
  AlarmConfiguration? alarmConfiguration,
  String? clientToken,
  MaintenanceWindowTaskCutoffBehavior? cutoffBehavior,
  String? description,
  LoggingInfo? loggingInfo,
  String? maxConcurrency,
  String? maxErrors,
  String? name,
  int? priority,
  String? serviceRoleArn,
  List<Target>? targets,
  MaintenanceWindowTaskInvocationParameters? taskInvocationParameters,
  Map<String, MaintenanceWindowTaskParameterValueExpression>? taskParameters,
}) async {
  _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.value,
      'WindowId': windowId,
      if (alarmConfiguration != null)
        'AlarmConfiguration': alarmConfiguration,
      'ClientToken': clientToken ?? _s.generateIdempotencyToken(),
      if (cutoffBehavior != null) 'CutoffBehavior': cutoffBehavior.value,
      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);
}