Type error on SSM Document For each loop

0

Hello,

I am currently trying to create my custom SSM document that aims to create/delete VPC Endpoints when needed. The problem is that I don't understand of to iterate over a MapList with SSM Document.

The sample input that I used is :

[
{
"VpcId": "vpc-*",
"SubnetIds": ["subnet-*"],
"ServiceName": "com.amazonaws.eu-west-3.s3",
"Name": "TestEndpoint"
},
{
"VpcId": "vpc-*",
"SubnetIds": ["subnet-*"],
"ServiceName": "com.amazonaws.eu-west-3.dynamodb",
"Name": "TestEndpoint2"
}
]

With the Document content :

schemaVersion: '0.3'
description: |-
  *Replace this default text with instructions or other information about your runbook.*

parameters:
  VpcEndpoints:
    type: MapList
mainSteps:
  - name: Loop
    action: aws:loop
    isEnd: true
    inputs:
      Iterators: '{{ VpcEndpoints }}'
      IteratorDataType: StringMap
      Steps:
        - name: CreateVpcEndpoint
          action: aws:executeAwsApi
          isEnd: true
          inputs:
            Service: ec2
            Api: CreateVpcEndpoint
            VpcEndpointType: Interface
            VpcId: '{{ Loop.CurrentIteratorValue }}.VcpId'
            SubnetIds: '{{ Loop.CurrentIteratorValue }}.SubnetIds'
            ServiceName: '{{ Loop.CurrentIteratorValue }}.ServiceName'
            TagSpecifications:
              - ResourceType: vpc-endpoint
                Tags:
                  - Key: Name
                    Value: '{{ Loop.CurrentIteratorValue }}.Name'

And I finally received this error :

Step fails when it is validating and resolving the step inputs. Failed to resolve input: VpcEndpoints to type StringList. VpcEndpoints is found to be of type MapList.. Please refer to Automation Service Troubleshooting Guide for more diagnosis details.

I am not sure where is my misunderstanding in the parameters type and searching for someone that already tried to iterate over a MapList within an SSM Document.

1 Answer
0

Hi, As per the AWS documentation currently the Iterators supports only StringList type.
https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-action-loop.html

I tried below SSM document and it worked fine for me. Please try and let me know if any issues.
Note: Need to escape the comma in the input parameter with backslash

SSM document:.

description: Automation to loop over a list of string maps
schemaVersion: '0.3'
assumeRole: '{{ AutomationAssumeRole }}'
parameters:
  AutomationAssumeRole:
    type: String
    description: (Optional) The ARN of the role that allows Automation to perform the actions on your behalf.
    default: ''
  StringMapList:
    type: StringList
    description: List of string maps to iterate over
    default:
      - '{"key1": "value1"\, "key2": "value2"}'
      - '{"key1": "value3"\, "key2": "value4"}'
mainSteps:
  - name: loopOverStringMaps
    action: aws:loop
    isEnd: true
    inputs:
      Iterators:
        - '{{ StringMapList }}'
      Steps:
        - name: printStringMap
          action: aws:executeScript
          isEnd: true
          inputs:
            Runtime: python3.9
            Handler: script_handler
            Script: |-
              import json
              def script_handler(events, context):
                  string_map = events['IteratorValue']
                  print(f"Current string map: {string_map}")
            InputPayload:
              IteratorValue: '{{ loopOverStringMaps.CurrentIteratorValue }}'

AWS
answered 2 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