简体   繁体   中英

How to invoke AWS Lambda functiuon which handles APIGatewayProxyRequestEvent?

I have an AWS Lambda function, implemented in Java, which is behind APIGateway. It works fine with:

.
.
.
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) 
.
.
.

I want to invoke the function from a Java app with:

.
.
APIGatewayProxyRequestEvent event = new APIGatewayProxyRequestEvent();
// tried to use almost all setters
InvokeRequest req = new InvokeRequest()
       .withFunctionName("<Lambda arn>")
       .withPayload(event.toString());
// here, I also tried many options

The Lambda is invoked, but checking thru CloudWatch, I see nothing as an input APIGatewayProxyRequestEvent. And, with various event setters I experience something like:

om.amazonaws.services.lambda.model.InvalidRequestContentException: Could not parse request body into json: Could not parse payload into json: Unexpected character ('r' (code 114)): was expecting double-quote to start field name
 at [Source: (byte[]); line: 1, column: 3] (Service: AWSLambda; Status Code: 400; Error Code: InvalidRequestContentException; Request ID: ..........

How can I specify that the invoked lambda function expects APIGatewayProxyRequestEven as an input argument? I've got a feeling that I miss something very simple, but can not find it. Thanks.

You've created your Lambda function to be invoked by Amazon API Gateway. In your code example it looks like you're trying to invoke the function directly.

Instead make a suitable http call to the API Gateway endpoint url.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM