Invoking SSM Automations from EventBridge - can't pass strings

0

I am trying to invoke an SSM Automation from EventBridge. However, I can't seem to successfully pass a string to EventBridge.

If I have the following input transformer,

{
  "InstanceId": "<InstanceId>",
  "Role": "<Role>"
}

the event ends up in the dead letter queue with the Error Message Invalid input for target.

If I try to create the input transformer in the Console, the placeholder text suggests:

{
  "InstanceId": ["<InstanceId>"],
  "Role": ["<Role>"]
}

If I do that, the event gets through EventBridge, but fails at Automation with Failed to resolve input: InstanceId to type StringList. InstanceId is found to be of type String. (which isn't surprising).

The SSM Automation is as follows:

schemaVersion: '0.3'
parameters:
  InstanceId:
    type: String
  Role:
    type: String
assumeRole: '{{ Role }}'
mainSteps:
  - name: RunCommandOnInstances
    action: aws:runCommand
    isEnd: true
    inputs:
      DocumentName: AWS-RunPowerShellScript
      Parameters:
        commands: 
          - echo "hi"
      InstanceIds: '{{ InstanceId }}'

Any thoughts as to what's going wrong here? Unfortunately I can't find examples of anyone doing this.

  • For the avoidance of doubt, the JSON input passed through to the DLQ is always valid JSON - neither InstanceId nor Role contain any quotes. And interestingly, if I use constants instead of an input transformer in the Console, it ends up wrapping whatever I put in in a JSON array...

1 Answer
0
Accepted Answer

It turns out that:

  1. SSM Automation does expect Strings to be passed in inside brackets, as if it were an array
  2. The error Failed to resolve input: InstanceId to type StringList. InstanceId is found to be of type String. relates to the InstanceIds parameter on RunCommandOnInstances, not an issue when invoking the Automation with that parameter.

The fix was thus:

{
  "InstanceId": ["<InstanceId>"],
  "Role": ["<Role>"]
}
schemaVersion: '0.3'
parameters:
  InstanceId:
    type: StringList
  Role:
    type: String
assumeRole: '{{ Role }}'
mainSteps:
  - name: RunCommandOnInstances
    action: aws:runCommand
    isEnd: true
    inputs:
      DocumentName: AWS-RunPowerShellScript
      Parameters:
        commands: 
          - echo "hi"
      InstanceIds: '{{ InstanceId }}'
or-wwn
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions