'AWS Lambda with API Gateway and with "Raw JSON Payload"
I have a Lambda written in C# that is called via API Gateway. The Lambda's Handler() function has the following signature:
public async Task<APIGatewayProxyResponse> Handler(APIGatewayProxyRequest request, ILambdaContext context)
This Lambda works fine when called from an HTTP client.
I have another Lambda with this signature that also works just fine:
public async Task<int> Handler(JObject jasonRequest, ILambdaContext context)
I have only ever called this Lambda from the AWS Console though.
What I need is for the same 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 request.Path and request.Body and return a response.StatusCode) but I also need to be able to call the Lambda by passing it a "raw JSON payload" (not sure of the terminology here), as I do when testing the Lambda in the AWS Console.
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
