1

I am trying to attach automation task with maintenancewindow using AWS powershell. I am trying to pass input parameters to the automation document. But its not working. When I see the document after attaching the input parameter value is empty. Not seeing any good documents also for the AUTOMATION type.

  • 1
    Can you provide a [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve) for the problem you're having? It's hard to help you without more information the data you're specifically working with. – Sean Pianka Jul 30 '18 at 15:48
  • I am trying to write similar to AWS cloud command in AWS powershell  ssm register-task-with-maintenance-window –window-id “mw-abc1234e3ddc9e286” –targets “Key=WindowTargetIds,Values=2ecce06f-130c-41a3-870c-d36deff6cbba” –task-arn “CreateVolumeSnapshots” –service-role-arn “arn:aws:iam::111111111111:role/MaintenanceWindowRole” –task-type “AUTOMATION” –task-invocation-parameters “Automation={Parameters={instanceId=i-000a0a0ca4caf9861,AutomationAssumeRole=arn:aws:iam::111111111111:role/AutomationRole,SnapshotTimeout=PT20M}}” –priority 1 –max-concurrency 1 –max-errors 1 –name “Automation_Task1” –de – Arivoli Ram Jul 30 '18 at 22:46
  • But stuck with passing automation parameters to this command in AWS powershell – Arivoli Ram Jul 30 '18 at 22:48

1 Answers1

2

Something like this should work:

PS > $automationParameters = @{}
PS > $automationParameters.Add( "instanceId", @("{{ TARGET_ID }}") )
PS > $automationParameters.Add( "AutomationAssumeRole", @("arn:aws:iam
::111111111111:role/AutomationRole") )
PS > $automationParameters.Add( "SnapshotTimeout", @("PT20M") )
PS > Register-SSMTaskWithMaintenanceWindow -WindowId mw-123EXAMPLE456 -ServiceRoleArn "arn:aws:iam::123456789012:role/MW-Role" -MaxConcurrency 1 -MaxError 1 -TaskArn "CreateVolumeSnapshots" -Target @{ Key="WindowTargetIds";Values="4b5acdf4-946c-4355-bd68-4329a43a5fd1" } -TaskType "AUTOMATION" -Priority 4 -Automation_Docum
entVersion '$DEFAULT' -Automation_Parameter $automationParameters -Name "Create-Snapshots"

Note that I use the {{TARGET_ID}} syntax so the Automation task will run properly for each instance in the maintenance window target (see https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-mw-walk-cli.html for more details on this). Hope that helps.

You can find more information here: https://docs.aws.amazon.com/powershell/latest/reference/items/AWS_Systems_Manager_cmdlets.html

/Mats

Mats Lannér
  • 1,236
  • 7
  • 6
  • Thanks Mate. It works thanks :) But I removed {} in below line and it worked. ( "AutomationAssumeRole", @("{arn:aws:iam ::111111111111:role/AutomationRole}") ) – Arivoli Ram Aug 01 '18 at 14:20
  • Good catch, that was a typo on my behalf – Mats Lannér Aug 01 '18 at 17:24
  • @MatsLannér Thanks for sharing the use of the pseudo parameter `{{TARGET_ID}}` - for completion, here is a link to the psedo parameters currently available to SSM Maintenance Window Tasks: https://docs.aws.amazon.com/systems-manager/latest/userguide/mw-cli-register-tasks-parameters.html – Lasse Christiansen Jun 07 '19 at 11:25