Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE: While trying to integrate RESTAPI from Springboot app using API gateway lambda proxy #227

Closed
sandeeppilania opened this issue Jan 15, 2019 · 17 comments

Comments

@sandeeppilania
Copy link

  • Framework version: 1.3
  • Implementations: Spring Boot

Scenario

NPE with Spring Boot Example and calling default URL:
curl -X GET https://xxx.execute-api.eu-west-1.amazonaws.com/Prod/greeting

Expected behavior

Hello World

Actual behavior

Error - HTTP Code 500

Steps to reproduce

I am trying stepup a simple helloworld application using api gateway and lambda proxy, i am using
handler.proxyStream exactly simliar to the samples. And i have stood up a API gateway with Lamdba function proxy manually through console and i am trying to test through the console Api gateway Test itself. I am not sure what i am missing majorly over here. I did try with handle.proxy option as well but no success. Can you please advice me where i am missing on this. Looking for help

Full log output

START RequestId: 4bfef8c4-d015-4500-ad68-e85130c1f173 Version: $LATEST
2019-01-15 19:58:24.522 INFO 1 --- [ main] c.e.LambdaHandler.StreamLambdaHandler : HI there
2019-01-15 19:58:24.556 ERROR 1 --- [ main] c.a.s.p.internal.LambdaContainerHandler : Error while handling request

java.lang.NullPointerException: null
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:39) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:29) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:174) ~[task/:na]
at com.example.LambdaHandler.StreamLambdaHandler.handleRequest(StreamLambdaHandler.java:51) [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$PojoMethodRequestHandler.handleRequest(EventHandlerLoader.java:259) [LambdaSandboxJava-1.0.jar:na]
at lambdainternal.EventHandlerLoader$PojoHandlerAsStreamHandler.handleRequest(EventHandlerLoader.java:178) [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.(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-01-15 19:58:24.557 ERROR 1 --- [ main] c.a.s.proxy.AwsProxyExceptionHandler : Called exception handler for:

java.lang.NullPointerException: null

@sapessi
Copy link
Collaborator

sapessi commented Jan 16, 2019

Based on the exception location, I'm guessing you don't have the multi-value headers enabled. Are you running via API Gateway, ALB, or testing locally?

@sandeeppilania
Copy link
Author

i was trying to run it through API gateway. i am able to get a fix for this if i create the stack using Cloudformation template or SAM. But i still dont know what i was missing when i was trying to set it up manually piece by piece in the console.

But with CFT stack I am able to use API endpoint without any issues. It's working all good but when I checked the logs I did some error in the logs, in spite of the error I am able to run my application via API gateway. Can you help me with what the potential reason for the error in the logs

2019-01-17 19:13:38.034 INFO 1 --- [ main] com.redis.Lambda.LambdaApplication : Starting LambdaApplication on ip-10-146-246-20.ec2.internal with PID 1 (/var/task started by sbx_user1080 in /)
2019-01-17 19:13:38.037 INFO 1 --- [ main] com.redis.Lambda.LambdaApplication : No active profile set, falling back to default profiles: default
2019-01-17 19:13:40.845 INFO 1 --- [ main] c.a.s.p.i.servlet.AwsServletContext : Initializing Spring embedded WebApplicationContext
2019-01-17 19:13:40.845 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2626 ms
2019-01-17 19:13:41.496 INFO 1 --- [ main] c.a.s.p.i.servlet.AwsServletContext : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-01-17 19:13:41.496 INFO 1 --- [ main] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-01-17 19:13:42.659 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-01-17 19:13:43.155 INFO 1 --- [ main] o.s.web.servlet.DispatcherServlet : Completed initialization in 1659 ms
2019-01-17 19:13:43.901 INFO 1 --- [ main] com.redis.Lambda.LambdaApplication : Started LambdaApplication in 7.289 seconds (JVM running for 8.874)
START RequestId: 52787d32-d9d4-4a74-b7fc-b2a0064b590a Version: $LATEST
lambda handler in play
2019-01-17 19:13:44.195 ERROR 1 --- [ main] c.a.s.p.i.s.AwsProxyHttpServletRequest : Called set character encoding to UTF-8 on a request without a content type. Character encoding will not be set
In the api
2019-01-17 19:13:44.837 INFO 1 --- [ main] c.a.s.p.internal.LambdaContainerHandler : 198.176.81.34 - [17/01/2019:19:13:34Z] "GET /greeting HTTP/1.1" 200 143 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" combined
END RequestId: 52787d32-d9d4-4a74-b7fc-b2a0064b590a

@sapessi
Copy link
Collaborator

sapessi commented Feb 12, 2019

Hey @sandeeppilania, if it works fine when you go through SAM this is likely a setup issue in API Gateway. Have you configured the integration settings for the API Gateway method to use a proxy integration?

screen shot 2019-02-12 at 10 16 11 am

@kart2018
Copy link

i am also getting the same issue and trying to call from apigee.

{
"statusCode": 502,
"multiValueHeaders": {
"Content-Type": [
"application/json"
]
},
"body": "{"message":"Gateway timeout"}",
"isBase64Encoded": false
}

And errors also same


18:19:08
START RequestId: b91ee6ea-4645-448a-aab1-3cb6638293e0 Version: $LATEST

18:19:08
2019-02-14 18:19:08.762 ERROR 1 --- [ main] c.a.s.p.internal.LambdaContainerHandler : Error while handling request

18:19:08
java.lang.NullPointerException: null

18:19:08
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:48) ~[task/:na]

18:19:08
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:28) ~[task/:na]

18:19:08
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:174) [task/:na]

18:19:08
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:209) [task/:na]

18:19:08
at com.vzw.billing.lambda.approval.BuildApprovalL

@sapessi
Copy link
Collaborator

sapessi commented Feb 21, 2019

Your issue is different @kart2018 - it will be addressed over the next couple of days (from #237)

@kart2018
Copy link

@sapessi Thanks for your comments, will wait for your update.

@kart2018
Copy link

@sapessi do you have any update on this issue.

@sapessi
Copy link
Collaborator

sapessi commented Feb 28, 2019

Hey @kart2018, we published version 1.3.1 of the framework on maven. It should resolve your issue.

@kart2018
Copy link

kart2018 commented Mar 4, 2019

@sapessi Really Appreciated to get the new version. I have tried with 1.3.1 and getting the same error and don't see any difference. My Lambda Handler Code is below

package com.java.test.lambda.demo;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.amazonaws.serverless.exceptions.ContainerInitializationException;
import com.amazonaws.serverless.proxy.internal.testutils.Timer;
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
import com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;

public class DemoBuildLambdaHandler implements RequestStreamHandler {

private static  Logger log = LoggerFactory.getLogger(DemoBuildLambdaHandler .class);     

private static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
static {
    try {
 	   log.info("Starting AWS Lambda");
        handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(DemoAppl.class);
 	   log.info("Created AWS Handler, {}", handler);
    } catch (ContainerInitializationException e) {
        // Re-throw the exception to force another cold start
        e.printStackTrace();
        throw new RuntimeException("Could not initialize Spring Boot application", e);
    }
}
public BuildApprovalLambdaHandler() {
	Timer.enable();
}

@OverRide
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
log.info("Handle request {}, {}, {}, {}", context, context.getFunctionName(), context.getInvokedFunctionArn(),
context.getLogStreamName());
handler.proxyStream(inputStream, outputStream, context);
// just in case it wasn't closed by the mapper
outputStream.close();
}
}

Do i have to use custom handler for APIGEE ? Will it above code would work with only API Gateway ? Please confirm and need your help again on this issue.

Need your inputs also.

@sapessi
Copy link
Collaborator

sapessi commented Mar 4, 2019

I can guarantee that the above code would work via API Gateway. I cannot test against Apigee so I have no way of knowing. Are you sure the exception is exactly the same? Same line of code?

@kart2018
Copy link

kart2018 commented Mar 5, 2019

Yes, exactly the same error. Why this code is not working with APIGEE ...I am really not sure why is there difference using API Gateway and APIGEE both functionality are same.

2019-03-05 15:05:22.291 INFO 1 --- [ main] c.v.b.l.a.BuildApprovalLambdaHandler : Created AWS Handler, com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler@e70f13a
2019-03-05 15:05:22.303 INFO 1 --- [ main] c.v.b.l.a.BuildApprovalLambdaHandler : Handle request lambdainternal.api.LambdaContext@29ca3d04, 2019/03/05/[$LATEST]5a632f32297c435a831d3cbdca313b62
2019-03-05 15:05:22.327 ERROR 1 --- [ main] c.a.s.p.internal.LambdaContainerHandler : Error while handling request

java.lang.NullPointerException: null
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:48) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:28) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:174) [task/:na]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:209) [task/:na]
at com.vzw.billing.lambda.approval.BuildApprovalLambdaHandler.handleRequest(BuildApprovalLambdaHandler.java:43) [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.(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-05 15:05:22.328 ERROR 1 --- [ main] c.a.s.proxy.AwsProxyExceptionHandler : Called exception handler for:

java.lang.NullPointerException: null
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:48) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:28) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:174) [task/:na]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:209) [task/:na]
at com.vzw.billing.lambda.approval.BuildApprovalLambdaHandler.handleRequest(BuildApprovalLambdaHandler.java:43) [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.(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]
java.lang.NullPointerException
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:48)
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 com.vzw.billing.lambda.approval.BuildApprovalLambdaHandler.handleRequest(BuildApprovalLambdaHandler.java:43)
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.(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: e1426aed-5a4d-42a3-ae28-e100006bec4f

@kart2018
Copy link

kart2018 commented Mar 5, 2019

@sapessi
Yes, exactly the same error. Why this code is not working with APIGEE ...I am really not sure why is there difference using API Gateway and APIGEE both functionality are same.

2019-03-05 15:05:22.291 INFO 1 --- [ main] c.v.b.l.a.BuildApprovalLambdaHandler : Created AWS Handler, com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler@e70f13a
2019-03-05 15:05:22.303 INFO 1 --- [ main] c.v.b.l.a.BuildApprovalLambdaHandler : Handle request lambdainternal.api.LambdaContext@29ca3d04, 2019/03/05/[$LATEST]5a632f32297c435a831d3cbdca313b62
2019-03-05 15:05:22.327 ERROR 1 --- [ main] c.a.s.p.internal.LambdaContainerHandler : Error while handling request

java.lang.NullPointerException: null
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:48) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:28) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:174) [task/:na]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:209) [task/:na]
at com.vzw.billing.lambda.approval.BuildApprovalLambdaHandler.handleRequest(BuildApprovalLambdaHandler.java:43) [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.(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-05 15:05:22.328 ERROR 1 --- [ main] c.a.s.proxy.AwsProxyExceptionHandler : Called exception handler for:

java.lang.NullPointerException: null
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:48) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:28) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:174) [task/:na]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:209) [task/:na]
at com.vzw.billing.lambda.approval.BuildApprovalLambdaHandler.handleRequest(BuildApprovalLambdaHandler.java:43) [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.(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]
java.lang.NullPointerException
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:48)
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 com.vzw.billing.lambda.approval.BuildApprovalLambdaHandler.handleRequest(BuildApprovalLambdaHandler.java:43)
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.(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: e1426aed-5a4d-42a3-ae28-e100006bec4f

@sapessi
Copy link
Collaborator

sapessi commented Mar 5, 2019

I'm staring at the NPE line of code and I cannot figure out what null would escape from the checks around it. Any chance you could share a dump of the incoming event so that I can built a unit test around it?

The difference must be in the event model. We expect an API Gateway-style proxy event. I do not know what type of event Apigee generates.

@kart2018
Copy link

@sapessi The below is the input event we are passing and not sure where to find the type of event Apigee generates.
{
"buildId": 27,
"projectId": "HelloWorld",
"requestedBy": "xxxxx,
"deployTime": "2019-07-03 13:25:00",
"cycleRunStatus": true,
"approvedBy": "xxxxx",
"approvalResponse": "{"Comments": "Approved "}",
"requestCreated": "2019-07-03 13:23:00"
}

In this case, since i am using APIGee, this would be sending a payload which is much different to API GW proxy or ALB proxy, which would result in null pointer errors.
For example, if we compare the below payload which API Gateway proxy type integration passes to Lambda, it's much different to your own. I suspect the Lambda code to be looking for something inside a payload formatted like this, and this is the issue:

{
"body": "eyJ0ZXN0IjoiYm9keSJ9",
"resource": "/{proxy+}",
"path": "/path/to/resource",
"httpMethod": "POST",
"isBase64Encoded": true,
"queryStringParameters": {
"foo": "bar"
},
"pathParameters": {
"proxy": "/path/to/resource"
},
"stageVariables": {
"baz": "qux"
},
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8",
"Accept-Encoding": "gzip, deflate, sdch",
"Accept-Language": "en-US,en;q=0.8",
"Cache-Control": "max-age=0",
"CloudFront-Forwarded-Proto": "https",
"CloudFront-Is-Desktop-Viewer": "true",
"CloudFront-Is-Mobile-Viewer": "false",
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Tablet-Viewer": "false",
"CloudFront-Viewer-Country": "US",
"Host": "1234567890.execute-api.us-east-1.amazonaws.com ",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Custom User Agent String",
"Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
"X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
"X-Forwarded-For": "127.0.0.1, 127.0.0.2",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
},
"requestContext": {
"accountId": "123456789012",
"resourceId": "123456",
"stage": "prod",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
"requestTime": "09/Apr/2015:12:34:56 +0000",
"requestTimeEpoch": 1428582896000,
"identity": {
"cognitoIdentityPoolId": null,
"accountId": null,
"cognitoIdentityId": null,
"caller": null,
"accessKey": null,
"sourceIp": "127.0.0.1",
"cognitoAuthenticationType": null,
"cognitoAuthenticationProvider": null,
"userArn": null,
"userAgent": "Custom User Agent String",
"user": null
},
"path": "/prod/path/to/resource",
"resourcePath": "/{proxy+}",
"httpMethod": "POST",
"apiId": "1234567890",
"protocol": "HTTP/1.1"
}
}

@sapessi
Copy link
Collaborator

sapessi commented Mar 11, 2019

This framework will not be able to support that event out of the box. You'll need to either add support for a custom event type yourself - I've written a wiki guide for it - or transform it yourself to an AwsProxyRequest from the incoming input stream.

@hksfho
Copy link

hksfho commented Feb 10, 2020

Hey @sandeeppilania, if it works fine when you go through SAM this is likely a setup issue in API Gateway. Have you configured the integration settings for the API Gateway method to use a proxy integration?

screen shot 2019-02-12 at 10 16 11 am

It works for me!

@hopewise
Copy link

I confirm, it worked when using Lambda Proxy Integration.
Screen Shot 2022-12-13 at 11 21 36 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants