title: AWS Step Functions - How to ignore "ResultSelector" when error is catched?
body: <p>I have a AWS Step Functions state machine that as first state starts a Lambda function. This function do something then returns a JSON like <code>{ temp_a: &quot;temporary a&quot; }</code>.
  This output should be sent to the second state of this state machine but, I don't want to send <code>temp_a</code> as key, rather I'd like to rename it <code>a</code>, so the result of the first state should be <code>{ a: &quot;temporary a&quot; }</code>.</p>
  <p>This is trivial and can be done using <a href="https://docs.aws.amazon.com/step-functions/latest/dg/input-output-inputpath-params.html#input-output-resultselector" rel="nofollow noreferrer">ResultSelector</a>. For this, the Step Functions will look like this:</p>
  <pre><code>{
    &quot;StartAt&quot;: &quot;State1&quot;,
    &quot;States&quot;: {
      &quot;State1&quot;: {
        &quot;Next&quot;: &quot;State2&quot;,
        &quot;Resource&quot;: &quot;arn:aws:lambda:eu-west-1:XXX:function:sfexample-LambdaFunction&quot;,
        &quot;ResultSelector&quot;: {
          &quot;a.$&quot;: &quot;$.temp_a&quot;
        },
        &quot;Type&quot;: &quot;Task&quot;
      },
      &quot;State2&quot;: {
        &quot;End&quot;: true,
        &quot;Type&quot;: &quot;Pass&quot;
      }
    }
  }
  </code></pre>
  <p>and Lambda will be something as easiest as possible since it contains just a single instruction <code>return { temp_a: &quot;temporary a&quot; };</code>.</p>
  <p>Once the state machine has been started, everything works like a charm since the <code>temp_a</code> is successfully <em>renamed</em> into <code>a</code> (thanks to the <code>ResultSelector</code>) and then it is sent to the <code>State2</code>. Great!</p>
  <p>Occasionally, that Lambda can throw a <code>CustomError</code> exception that I would catch in the state machine. When the error is caught the flow have to be diverted into the state <code>CustomErrorState</code>.</p>
  <p>To make things possible I've added a <code>Catch</code> statement into the <code>State1</code>, and added another state called <code>CustomErrorState</code> of type <code>Fail</code>.</p>
  <pre><code>{
    &quot;StartAt&quot;: &quot;State1&quot;,
    &quot;States&quot;: {
      &quot;CustomErrorState&quot;: {
        &quot;Cause&quot;: &quot;Error happens&quot;,
        &quot;Type&quot;: &quot;Fail&quot;
      },
      &quot;State1&quot;: {
        &quot;Catch&quot;: [
          {
            &quot;ErrorEquals&quot;: [
              &quot;CustomError&quot;
            ],
            &quot;Next&quot;: &quot;CustomErrorState&quot;
          }
        ],
        &quot;Next&quot;: &quot;State2&quot;,
        &quot;Resource&quot;: &quot;arn:aws:lambda:eu-west-1:XXX:function:sfexample-LambdaFunction&quot;,
        &quot;ResultSelector&quot;: {
          &quot;a.$&quot;: &quot;$.temp_a&quot;
        },
        &quot;Type&quot;: &quot;Task&quot;
      },
      &quot;State2&quot;: {
        &quot;End&quot;: true,
        &quot;Type&quot;: &quot;Pass&quot;
      }
    }
  }
  </code></pre>
  <p>This seems reasonable but when Lambda throw the <code>CustomError</code> I get a runtime error because the <code>State1</code> cannot perform what I've specified in the <code>ResultSelector</code> property.</p>
  <p>What's the meaning? If an error is caught how could I handle the result? It is possible to ignore <code>ResultSelector's</code> instructions when I catch en error in a state?</p>
  <p><em>Further detail:</em>
  <a href="https://gist.github.com/marianoc84/a438d9170225ac4b431a1360b7a37cba" rel="nofollow noreferrer">Here</a> you can grab all necessary file to test it into your account.</p>