title: Lambda execution failed with status 200 due to customer function error
body: <p>I'm creating a simple Lambda function to serve a POST in AWS Gateway:</p>
  <pre><code>import json
  import boto3
  from datetime import datetime
  
  
  def lambda_handler(event,context):
      wf = event['WF']
      
      if wf == 'start1':
              body = 'Suceeded'
              return {
                  &quot;isBase64Encoded&quot;: False,
                  'statusCode': 200,
                  'body': json.dumps(body),
                  'headers': {
                  'Content-Type': 'application/json'
                      }   
                  }
      else:
              body = 'Failed'
              return {
                  &quot;isBase64Encoded&quot;: False,
                  'statusCode': 400,
                  'body': json.dumps(body),
                  'headers': {
                  'Content-Type': 'application/json'
                      }   
               }
  </code></pre>
  <p>If I send a POST with this body is successful:</p>
  <pre><code>{
    &quot;WF&quot;: &quot;start1&quot;,
    &quot;Context&quot;: &quot;OK&quot;
  }
  </code></pre>
  <p>Returns:</p>
  <pre><code>Test Event Name
  test
  
  Response
  {
    &quot;isBase64Encoded&quot;: false,
    &quot;statusCode&quot;: 200,
    &quot;body&quot;: &quot;\&quot;Suceeded\&quot;&quot;,
    &quot;headers&quot;: {
      &quot;Content-Type&quot;: &quot;application/json&quot;
    }
  }
  
  Function Logs
  START RequestId: 91663a9d-d8b6-4aad-b8b6-eb2f15ff0354 Version: $LATEST
  END RequestId: 91663a9d-d8b6-4aad-b8b6-eb2f15ff0354
  REPORT RequestId: 91663a9d-d8b6-4aad-b8b6-eb2f15ff0354  Duration: 1.74 ms   Billed Duration: 2 ms   Memory Size: 128 MB Max Memory Used: 66 MB  Init Duration: 300.73 ms
  
  Request ID
  91663a9d-d8b6-4aad-b8b6-eb2f15ff0354
  </code></pre>
  <p>But if I run a test in the API Gateway service in AWS I get:</p>
  <pre><code>Fri Jun 04 13:45:22 UTC 2021 : Sending request to https://XXXXXXX
  Fri Jun 04 13:45:22 UTC 2021 : Received response. Status: 200, Integration latency: 15 ms
  Fri Jun 04 13:45:22 UTC 2021 : Endpoint response headers: {Date=Fri, 04 Jun 2021 13:45:22 GMT, Content-Type=application/json, Content-Length=159, Connection=keep-alive, x-amzn-RequestId=d479fdac-6737-42fa-96a3-9e991056b48d, X-Amz-Function-Error=Unhandled, x-amzn-Remapped-Content-Length=0, X-Amz-Executed-Version=$LATEST, X-Amzn-Trace-Id=root=1-60ba2e72-ff62f051febbd21d6cc9d114;sampled=0}
  Fri Jun 04 13:45:22 UTC 2021 : Endpoint response body before transformations: {&quot;errorMessage&quot;: &quot;'WF'&quot;, &quot;errorType&quot;: &quot;KeyError&quot;, &quot;stackTrace&quot;: [&quot;  File \&quot;/var/task/lambda_function.py\&quot;, line 7, in lambda_handler\n    wf = event['WF']\n&quot;]}
  Fri Jun 04 13:45:22 UTC 2021 : Lambda execution failed with status 200 due to customer function error: 'WF'. Lambda request id: d479fdac-6737-42fa-96a3-9e991056b48d
  Fri Jun 04 13:45:22 UTC 2021 : Method completed with status: 502
  </code></pre>
  <p>Why line 7 is wrong?
  Is there another way to parse the body of the POST?</p>