最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

amazon web services - AWS state function: remember which steps succeeded in a map - Stack Overflow

programmeradmin1浏览0评论

I want to have a state machine, with a loop over an array. A loop is just a sequential map state (concurrency = 1). If one item of the array fails being processed, the map stops, and somehow I want to know which items were successful and which one failed.

This is this remembering of success/failures which I cannot manage to do.

  1. If I create an array variable in the outer scope before the map state, I am not able to update it during the map runs (The variable name was already defined in a parent scope)
  2. Every success can add an output to the map step, but failure cannot.
  3. If I do not use an actual failure, but try and remember the successes/failure with a boolean flag, I get the same issue as 1.
  4. Trying to use $states.context.Map.Item.Name anywhere inside the map fails (variable does not exist)

As an example, this is the simplified machine. The payload is hardcoded ([1, 2, 1]), and the map only checks if an element is <2. If yes: success, if not: failure. As output (or in a variable, or...) I would like something like [{"Success":1}, {"Failure": 2}] where the second 1 has not been processed. The actual structure of the output does not matter much.

{
  "QueryLanguage": "JSONata",
  "Comment": "A description of my state machine",
  "StartAt": "Map",
  "States": {
    "Map": {
      "Type": "Map",
      "ItemProcessor": {
        "ProcessorConfig": {
          "Mode": "INLINE"
        },
        "StartAt": "Choice",
        "States": {
          "Choice": {
            "Type": "Choice",
            "Choices": [
              {
                "Next": "Store success",
                "Condition": "{% $states.input < 2 %}",
                "Output": {
                  "Success": "{% $states.input %}"
                }
              }
            ],
            "Default": "Fail"
          },
          "Store success": {
            "Type": "Pass",
            "End": true
          },
          "Fail": {
            "Type": "Fail"
          }
        }
      },
      "Next": "Pass",
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "Next": "Pass"
        }
      ],
      "Items": [
        1,
        2,
        1
      ],
      "MaxConcurrency": 1,
      "Output": {
        "o": "{% $states.input %}"
      }
    },
    "Pass": {
      "Type": "Pass",
      "End": true
    }
  }
}

发布评论

评论列表(0)

  1. 暂无评论