amazon-web-servicesaws-lambdaaws-step-functions

Remove fields from previous step


I am trying to remove a field from the previous step used only in the choice task. I have this StepFunction

{
  "StartAt": "ConversionStep",
  "States": {
    "ConversionStep": {
      "Type": "Task",
      "TimeoutSeconds": 30,
      "Resource": "arn:aws:lambda:region:account-id:function:conversion-step",
      "Retry": [
        {
          "ErrorEquals": [
            "RetryError",
            "States.Timeout"
          ],
          "IntervalSeconds": 30,
          "MaxAttempts": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.TaskFailed"
          ],
          "Next": "Failure"
        }
      ],
      "Next": "ChoiceStep"
    },
    "ChoiceStep": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.processEvent",
          "BooleanEquals": true,
          "Next": "PublishStep"
        }
      ],
      "Default": "Failure"
    },
    "PublishStep": {
      "Type": "Task",
      "Resource": "arn:aws:states:::events:putEvents",
      "Parameters": {
        "Entries": [
          {
            "Detail.$": "$",
            "EventBusName": "example-event-bus",
            "DetailType": "example-detail-type",
            "Source": "EXAMPLE_SOURCE"
          }
        ]
      },
      "Retry": [
        {
          "ErrorEquals": [
            "RetryError",
            "States.Timeout"
          ],
          "IntervalSeconds": 30,
          "MaxAttempts": 3
        }
      ],
      "Catch": [
        {
          "ErrorEquals": [
            "States.TaskFailed"
          ],
          "Next": "Failure"
        }
      ],
      "Next": "Success"
    },
    "Success": {
      "Type": "Succeed"
    },
    "Failure": {
      "Type": "Fail"
    }
  }
}

In the Conversion step add the processEvent in the event. I need to send the conversion step result without this field in the publish step "Detail.$": "$",

Is there a way I can do it without creating another Lambda Step? The choice step does not have the Result Filter feature.


Solution

  • This is now possible with the recently launched support for JSONata using the Transform Operator.

    You would need to update the state to use "QueryLanguage": "JSONata" (you can do this for your whole state machine or just for this state if you don't want to change the rest and replace the "$" (JSONPath input reference) to something like:

    "{% $states.input ~> | ** | {}, ['processEvent'] | %}"