title: AWS Lambda with API Gateway and with "Raw JSON Payload"
body: <p>I have a Lambda written in C# that is called via API Gateway. The Lambda's <code>Handler()</code> function has the following signature:</p>
  <pre><code>public async Task&lt;APIGatewayProxyResponse&gt; Handler(APIGatewayProxyRequest request, ILambdaContext context)
  </code></pre>
  <p>This Lambda works fine when called from an HTTP client.</p>
  <p>I have another Lambda with this signature that also works just fine:</p>
  <pre><code>public async Task&lt;int&gt; Handler(JObject jasonRequest, ILambdaContext context)
  </code></pre>
  <p>I have only ever called this Lambda from the AWS Console though.</p>
  <p>What I need is for the <em>same</em> Lambda to be able to be called either way. I need to be able to identify an incoming API Gateway request (so that I can retrieve the <code>request.Path</code> and <code>request.Body</code> and return a <code>response.StatusCode</code>) but I also need to be able to call the Lambda by passing it a &quot;raw JSON payload&quot; (not sure of the terminology here), as I do when testing the Lambda in the AWS Console.</p>
  <p>So, is there a way to set up my Lambda's signature and return type so that I can respond to both API Gateway requests as well raw JSON payloads? I am not asking this just to be able to test via the AWS Console. Another team at our company will call the Lambda via EventBridge and I think it will send a raw JSON payload.</p>