Files
aws.ssm.documents/LoopWithCsv.yaml
T
2026-01-29 09:47:49 +08:00

53 lines
1.5 KiB
YAML

schemaVersion: '0.3'
mainSteps:
# ssm parameter supports StringList, which is comma separated strings (i.e. 111111111111,222222222222)
- name: GetParameter
action: aws:executeAwsApi
nextStep: ConvertInputToList
isEnd: false
inputs:
Service: ssm
Api: GetParameter
Name: some-parameter
outputs:
- Name: Accounts
Selector: $.Parameter.Value
Type: String
# The so-called StringList needs to be transformed to a list[str] in order to be used by aws:loop
# There is no native action for that, and I need to use python
- name: ConvertInputToList
action: aws:executeScript
nextStep: Loop
isEnd: false
inputs:
Runtime: python3.11
Handler: script_handler
InputPayload:
accounts: '{{ GetParameter.Accounts }}'
Script: |
def script_handler(events, context):
return events['accounts'].split(',')
outputs:
- Name: AccountList
Selector: $.Payload
Type: StringList
- name: Loop
action: aws:loop
isEnd: true
inputs:
Iterators: '{{ ConvertInputToList.AccountList }}'
IteratorDataType: String
Steps:
- name: PrintInput
action: aws:executeScript
isEnd: true
inputs:
Runtime: python3.11
Handler: script_handler
InputPayload:
accountId: '{{Loop.CurrentIteratorValue}}'
Script: |
def script_handler(events,context):
return {"accountId": events.get('accountId')}