How do I add parameters when I register 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.

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 that are 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 so that you don't need to individually enter each resource ID.

For example, the Amazon provided AWS-StopEC2Instance document requires that you enter the instance ID as a parameter. Use a pseudo parameter to have the maintenance window target multiple instances or when you don't know the instance ID.

Note: For the INSTANCE target type, both the {{TARGET_ID}} and {{RESOURCE_ID}} pseudo parameters provide only the instance ID. However, for the RESOURCE_GROUP target type, {{TARGET_ID}} and {{RESOURCE_ID}} return the ID in different formats. For more information and a list of available pseudo parameters, see Using pseudo parameters when registering maintenance window tasks.

Resolution

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.

Use the Systems Manager console

Complete the following steps:

  1. Open the Systems Manager console.
  2. In the navigation pane, choose Maintenance Windows, and then select your maintenance window.
  3. On the Tasks page, choose Register tasks, and then choose Register Automation task.
  4. On the Register Automation task page, enter the following information:
    Under Automation document, select the document that you want the task to run.
    For Targets, specify your target information.
    For Input parameters, enter a pseudo parameter value. For example, enter TARGET_ID or RESOURCE_ID for the parameter that requires a resource ID.
    For Rate control, specify your rate information.
    For IAM service role, select an AWS Identity and Access Management (IAM) role.
  5. Choose Register Automation task.

Use the AWS CLI

Note: If you receive errors when you run AWS CLI commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.

Run the register-task-with-maintenance-window command.

The following example command registers an Automation task that includes 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 Resource ID for each target passes to the system. In the preceding example, the InstanceId parameter receives the instance ID for each target in the target group.

Related information

Supported pseudo parameters

Parameter options for the register-task-with-maintenance-windows command

AWS OFFICIAL
AWS OFFICIALUpdated 5 months ago