How do I add parameters when registering an Automation task with Systems Manager maintenance windows?

3 minute read
0

I want to register an Automation document task for an AWS Systems Manager maintenance window that targets multiple Amazon Elastic Compute Cloud (Amazon EC2) instances. How can I do that?

Short description

When you register a maintenance window Automation task, you must provide input parameter values that pass to the task when the task runs. The required input parameters are the same as the parameters defined in the Automation document content. You can use pseudo parameter values in the required input parameter fields to dynamically reference the resource IDs that the maintenance window targets. Pseudo parameters, such as {{RESOURCE_ID}}, allow you to target multiple resources without entering each resource ID individually.

For example, the Amazon-provided AWS-StopEC2Instance document requires that you enter the instance ID as a parameter. If you want the maintenance window to target multiple instances, or if you don’t know the instance ID, you can use a pseudo parameter.

Note: For target type INSTANCE, both the {{TARGET_ID}} and {{RESOURCE_ID}} pseudo parameters yield only the instance ID. However, for target type RESOURCE_GROUP, {{TARGET_ID}} and {{RESOURCE_ID}} return the ID in different formats. For more information, and for a list of available pseudo parameters, see About pseudo parameters.

You can use either the Systems Manager console or the AWS Command Line Interface (AWS CLI) to register maintenance window Automation tasks with pseudo parameters.

Resolution

Using the console

To register a maintenance window Automation task using dynamic pseudo parameters, follow these steps:

  1. Open the Systems Manager console, and then choose Maintenance Windows from the navigation pane.
  2. Select your maintenance window, and then choose View details.
  3. From the Tasks tab, choose Register tasks, Register Automation task.
  4. For Automation document, select the document that you want the task to run.
  5. Specify your Targets, Rate control, and IAM service role.
  6. For Input parameters, enter a pseudo parameter value (for example, {{TARGET_ID}} or {{RESOURCE_ID}}) for the parameter that requires a resource ID.
  7. Choose Register Automation task.

Using the AWS CLI

Note: If you receive errors when running AWS CLI commands, make sure that you’re using the most recent version of the AWS CLI.

The following example uses the AWS CLI to register an Automation task including the {{RESOURCE_ID}} parameter:

aws ssm register-task-with-maintenance-window --window-id mw-1234567890EXAMPLE --targets Key=WindowTargetIds,Values=6c226ea3-463a-4533-8a2d-EXAMPLE --task-arn AWS-StopEC2Instance --task-type AUTOMATION --name MyMaintenanceWindowTask --max-concurrency 10 --max-errors 5 --task-invocation-parameters={\"Automation\":{\"Parameters\":{\"InstanceId\":[\"{{RESOURCE_ID}}\"]}}} --service-role-arn YOUR_SERVICE_ROLE_ARN

When the maintenance window task runs, the corresponding Resource ID for each target passes to the system. In the preceding example, the InstanceId parameter receives the corresponding instance ID for each target in the target group.


Related information

Supported pseudo parameters

About register-task-with-maintenance-windows options

AWS OFFICIAL
AWS OFFICIALUpdated 3 years ago