aws-serverless-java-container: The incoming event is not a valid request from Amazon API Gateway or an Application Load Balancer

  • Framework version: latest
  • Implementations: Spring Boot

Scenario

I’m trying to create two Spring Boot function. One supposed to call the other, I can call both from outside (Api Gateway), but if I try to do it directly with lambda invoke I get this: The incoming event is not a valid request from Amazon API Gateway or an Application Load Balancer either from code or from the lambda console. What am I missing?

Expected behavior

Works the same way with invoker as through api gateway.

Actual behavior

Only works with api gateway.

Steps to reproduce

The code is here: https://github.com/balihb/fifi

./gradlew :aws:buildFibZip :aws:buildFibtimerZip
cd aws
./deploy.sh

Full log output

93) [LambdaSandboxJava-1.0.jar:na]
	at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64) [LambdaSandboxJava-1.0.jar:na]
	at java.lang.Class.forName0(Native Method) [na:1.8.0_181]
	at java.lang.Class.forName(Class.java:348) [na:1.8.0_181]
	at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:104) [LambdaJavaRTEntry-1.0.jar:na]

2019-03-04 15:43:35.920 ERROR 1 --- [           main] c.a.s.proxy.AwsProxyExceptionHandler     : Called exception handler for:

com.amazonaws.serverless.exceptions.InvalidRequestEventException: The incoming event is not a valid request from Amazon API Gateway or an Application Load Balancer
	at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:41) ~[aws-serverless-java-container-core-1.3.1.jar:na]
	at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:28) ~[aws-serverless-java-container-core-1.3.1.jar:na]
	at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:174) [aws-serverless-java-container-core-1.3.1.jar:na]
	at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:209) [aws-serverless-java-container-core-1.3.1.jar:na]
	at balihb.fifi.fib.aws.StreamLambdaHandler.handleRequest(StreamLambdaHandler.java:33) [task/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
	at lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:350) [LambdaSandboxJava-1.0.jar:na]
	at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:888) [LambdaSandboxJava-1.0.jar:na]
	at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:293) [LambdaSandboxJava-1.0.jar:na]
	at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64) [LambdaSandboxJava-1.0.jar:na]
	at java.lang.Class.forName0(Native Method) [na:1.8.0_181]
	at java.lang.Class.forName(Class.java:348) [na:1.8.0_181]
	at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:104) [LambdaJavaRTEntry-1.0.jar:na]

com.amazonaws.serverless.exceptions.InvalidRequestEventException: The incoming event is not a valid request from Amazon API Gateway or an Application Load Balancer
	at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:41)
	at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:28)
	at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:174)
	at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:209)
	at balihb.fifi.fib.aws.StreamLambdaHandler.handleRequest(StreamLambdaHandler.java:33)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:350)
	at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:888)
	at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:293)
	at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:104)
END RequestId: 4aea4f27-70f1-458a-90fb-f5358a5e8f0f
REPORT RequestId: 4aea4f27-70f1-458a-90fb-f5358a5e8f0f	Duration: 5.94 ms	Billed Duration: 100 ms 	Memory Size: 1512 MB	Max Memory Used: 193 MB

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16

Most upvoted comments

I’m getting the same error: The incoming event is not a valid request from Amazon API Gateway or an Application Load Balancer I have the following configuration:

  SomeEndpoint:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: SomeCodeUri
      Handler: LambdaHandler::handleRequest
        Warmup:
          Type: Schedule
          Properties:
            Schedule: cron(0/5 8-17 ? * MON-FRI *)

I think a http method is expected on the request judging by what I see here:

if (request.getHttpMethod() == null || request.getHttpMethod().equals("") || request.getRequestContext() == null) {
            throw new InvalidRequestEventException(INVALID_REQUEST_ERROR);
        }

Do we have a sample handler class for this error? This is happening because the warmup plugin sends an event but it is not a gateway event. We should have a condition to return directly if the request is coming from warmup plugin.

It’s been a while since I’ve played with this and I don’t have the sample to provide it. Meanwhile we’ve dropped the warmup part.

I am trying to deploy the spring boot project generated by Maven archetype for Spring Boot 2.x on AWS lambda and calling its /ping endpoint with the help of AWS API gateway but I am getting the same error reported here i.e The incoming event is not a valid request from Amazon API Gateway or an Application Load Balancer

Here is my code:

https://my-lambda-code-bucket.s3.us-east-2.amazonaws.com/my-service-1.0-SNAPSHOT-lambda-package.zip

Here is my api endpoint: https://gpvvq6g3i1.execute-api.us-east-2.amazonaws.com/Prod/ping

Hey @balihb - the framework expects an event that is shaped like an API Gateway or ALB proxy event. That doesn’t mean that the call must come from API Gateway or ALB, just that the event should have the same model. If you wanted to, you could use the AwsProxyRequest object from the model package to generate the event.

If these two Lambda functions are meant to be separate services - meaning they have different scaling factors and will eventually be managed by separate teams - I’d recommend putting an actual API in-between them.