how to loop through json input - aws step function / state machine

Viewed 3197

Is it possible to create a loop in aws step function and loop through json input array?

I have a function generateEmails that creates array with n number of objects:

{
  "emails": [
    {
      "to": [
        "willow1@aaa.co.uk"
      ]
    },
    {
      "to": [
        "willow2@aaa.co.uk"
      ]
    },    {
      "to": [
        "willow3@aaa.co.uk"
      ]
    }
  ]
}

and now I want to call next function sendEmail for each object in emails array with something like this:

{
  "email": {
    "to": [
      "willow@aaa.co.uk"
    ]
  }
}

enter image description here

step function code:

{
  "Comment": "A state machine that prepares and sends confirmation email ",
  "StartAt": "generateEmails",
  "States": {
    "generateEmails": {
      "Type": "Task",
      "Resource": "arn:aws:lambda::prepare-confirmation-email",
      "Next": "sendEmail"
    },
    "sendEmail": {
      "Type": "Task",
      "Resource": "arn:aws:lambda::function:template-service",
      "End" : true
    }
  }
}

Is that possible to achieve?

Thanks!

0 Answers
Related