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 in AwsProxyHttpServletRequest.getRemoteAddr #182

Closed
peter-gergely-horvath opened this issue Aug 13, 2018 · 17 comments
Closed

NPE in AwsProxyHttpServletRequest.getRemoteAddr #182

peter-gergely-horvath opened this issue Aug 13, 2018 · 17 comments
Assignees
Milestone

Comments

@peter-gergely-horvath
Copy link

peter-gergely-horvath commented Aug 13, 2018

  • Framework version: 1.1.4
  • Implementations: Spring

Scenario

I have a Lambda function that should export a Spring service. Unfortunately this keeps failing due to a NPE in AwsProxyHttpServletRequest.getRemoteAddr. I believe this due to the face this service does NOT use Cognito at all. I believe the NPE originates from the following piece of code:

    @Override
    public String getRemoteAddr() {
        return request.getRequestContext().getIdentity().getSourceIp();
    }

I suspect either requestContext or requestContext.identity is going to be null.

Expected behavior

AwsProxyHttpServletRequest should properly return the remote address.

Actual behavior

AwsProxyHttpServletRequest.getRemoteAddr throws a NullPointerException

Steps to reproduce

See project in https://github.com/peter-gergely-horvath/aws-sdk-bugreport

Full log output

xy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:168) [task/:?]
	at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:200) [task/:?]
	at com.github.sq4lambda.QueryHandler.handleRequest(QueryHandler.java:49) [task/:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_141]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_141]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_141]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_141]
	at lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:350) [LambdaSandboxJava-1.0.jar:?]
	at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:888) [LambdaSandboxJava-1.0.jar:?]
	at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:286) [LambdaSandboxJava-1.0.jar:?]
	at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64) [LambdaSandboxJava-1.0.jar:?]
	at java.lang.Class.forName0(Native Method) ~[?:1.8.0_141]
	at java.lang.Class.forName(Class.java:348) [?:1.8.0_141]
	at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:94) [LambdaJavaRTEntry-1.0.jar:?]
java.lang.NullPointerException
	at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequest.getRemoteAddr(AwsProxyHttpServletRequest.java:575)
	at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1080)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1009)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:852)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer.dispatch(LambdaSpringApplicationInitializer.java:114)
	at com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer.service(LambdaSpringApplicationInitializer.java:205)
	at com.amazonaws.serverless.proxy.internal.servlet.FilterChainManager$ServletExecutionFilter.doFilter(FilterChainManager.java:351)
	at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84)
	at com.github.sq4lambda.filter.CognitoIdentityFilter.doFilter(CognitoIdentityFilter.java:44)
	at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84)
	at com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler.doFilter(AwsLambdaServletContainerHandler.java:207)
	at com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler.handleRequest(SpringLambdaContainerHandler.java:182)
	at com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler.handleRequest(SpringLambdaContainerHandler.java:42)
	at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:168)
	at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:200)
	at com.github.sq4lambda.QueryHandler.handleRequest(QueryHandler.java:49)
	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:286)
	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:94)
END RequestId: f8ae68c8-9f11-11e8-8ec3-3f33f66e69a5
REPORT RequestId: f8ae68c8-9f11-11e8-8ec3-3f33f66e69a5	Duration: 369.68 ms	Billed Duration: 400 ms 	Memory Size: 512 MB	Max Memory Used: 89 MB	
@sapessi
Copy link
Collaborator

sapessi commented Aug 13, 2018

Hi @peter-gergely-horvath, that field should always be populated by API Gateway. Regardless of how you authorize. Are you testing from the Lambda console or sending requests via API Gateway? If you are using API Gateway, is it through the test functionality in the console or via a deployed endpoint?

Regardless, we should not be throwing an NPE there. I'll fix this to just return null if the field is not available.

@sapessi sapessi self-assigned this Aug 13, 2018
@sapessi sapessi added the bug label Aug 13, 2018
@sapessi sapessi added this to the Release 1.2 milestone Aug 13, 2018
@peter-gergely-horvath
Copy link
Author

Hi @sapessi: I tried this from the Lambda console and API Gateway through the test functionality: both of them keep failing.

@sapessi
Copy link
Collaborator

sapessi commented Aug 13, 2018

Is the field populated in the Lambda test event? I suspect API Gateway does not populate it from its test functionality. Could you try deploying the API and sending a request to the endpoint - I would expect the field to be populated then.

As far as correcting this, what would you like the method to return if the field is not populated? null, 127.0.0.1?

@peter-gergely-horvath
Copy link
Author

peter-gergely-horvath commented Aug 13, 2018

Hi @sapessi, I tried deploying the API and it seems to fail with the very same error.
On the client side it's

{"statusCode":502,"headers":{"Content-Type":"application/json"},"body":"{\"message\":\"Gateway timeout\"}","base64Encoded":false}

but I was able to correlate the call with the CloudWatch log, which complains about the NPE:

START RequestId: 8a55598e-9f1c-11e8-83d5-f11a3a4b62fc Version: $LATEST
-- handling request in controller --
17:16:11.504 [main] ERROR com.amazonaws.serverless.proxy.internal.LambdaContainerHandler - Error while handling request
java.lang.NullPointerException: null
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequest.getRemoteAddr(AwsProxyHttpServletRequest.java:575) ~[task/:?]
at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1080) ~[task/:?]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1009) ~[task/:?]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:852) ~[task/:?]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[task/:?]
at com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer.dispatch(LambdaSpringApplicationInitializer.java:114) ~[task/:?]
at com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer.service(LambdaSpringApplicationInitializer.java:205) ~[task/:?]
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainManager$ServletExecutionFilter.doFilter(FilterChainManager.java:351) ~[task/:?]
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84) ~[task/:?]
at com.github.sq4lambda.filter.CognitoIdentityFilter.doFilter(CognitoIdentityFilter.java:44) ~[task/:?]
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84) ~[task/:?]
at com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler.doFilter(AwsLambdaServletContainerHandler.java:207) ~[task/:?]
at com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler.handleRequest(SpringLambdaContainerHandler.java:182) ~[task/:?]
at com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler.handleRequest(SpringLambdaContainerHandler.java:42) ~[task/:?]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:168) [task/:?]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:200) [task/:?]
at com.github.sq4lambda.QueryHandler.handleRequest(QueryHandler.java:49) [task/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_141]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_141]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_141]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_141]
at lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:350) [LambdaSandboxJava-1.0.jar:?]
at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:888) [LambdaSandboxJava-1.0.jar:?]
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:286) [LambdaSandboxJava-1.0.jar:?]
at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64) [LambdaSandboxJava-1.0.jar:?]
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_141]
at java.lang.Class.forName(Class.java:348) [?:1.8.0_141]
at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:94) [LambdaJavaRTEntry-1.0.jar:?]
17:16:11.545 [main] ERROR com.amazonaws.serverless.proxy.AwsProxyExceptionHandler - Called exception handler for:
java.lang.NullPointerException: null
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequest.getRemoteAddr(AwsProxyHttpServletRequest.java:575) ~[task/:?]
at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1080) ~[task/:?]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1009) ~[task/:?]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:852) ~[task/:?]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[task/:?]
at com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer.dispatch(LambdaSpringApplicationInitializer.java:114) ~[task/:?]
at com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer.service(LambdaSpringApplicationInitializer.java:205) ~[task/:?]
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainManager$ServletExecutionFilter.doFilter(FilterChainManager.java:351) ~[task/:?]
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84) ~[task/:?]
at com.github.sq4lambda.filter.CognitoIdentityFilter.doFilter(CognitoIdentityFilter.java:44) ~[task/:?]
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84) ~[task/:?]
at com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler.doFilter(AwsLambdaServletContainerHandler.java:207) ~[task/:?]
at com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler.handleRequest(SpringLambdaContainerHandler.java:182) ~[task/:?]
at com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler.handleRequest(SpringLambdaContainerHandler.java:42) ~[task/:?]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:168) [task/:?]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:200) [task/:?]
at com.github.sq4lambda.QueryHandler.handleRequest(QueryHandler.java:49) [task/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_141]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_141]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_141]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_141]
at lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:350) [LambdaSandboxJava-1.0.jar:?]
at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:888) [LambdaSandboxJava-1.0.jar:?]
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:286) [LambdaSandboxJava-1.0.jar:?]
at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64) [LambdaSandboxJava-1.0.jar:?]
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_141]
at java.lang.Class.forName(Class.java:348) [?:1.8.0_141]
at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:94) [LambdaJavaRTEntry-1.0.jar:?]
java.lang.NullPointerException
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequest.getRemoteAddr(AwsProxyHttpServletRequest.java:575)
at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1080)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1009)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer.dispatch(LambdaSpringApplicationInitializer.java:114)
at com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer.service(LambdaSpringApplicationInitializer.java:205)
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainManager$ServletExecutionFilter.doFilter(FilterChainManager.java:351)
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84)
at com.github.sq4lambda.filter.CognitoIdentityFilter.doFilter(CognitoIdentityFilter.java:44)
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84)
at com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler.doFilter(AwsLambdaServletContainerHandler.java:207)
at com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler.handleRequest(SpringLambdaContainerHandler.java:182)
at com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler.handleRequest(SpringLambdaContainerHandler.java:42)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:168)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:200)
at com.github.sq4lambda.QueryHandler.handleRequest(QueryHandler.java:49)
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:286)
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:94)
END RequestId: 8a55598e-9f1c-11e8-83d5-f11a3a4b62fc
REPORT RequestId: 8a55598e-9f1c-11e8-83d5-f11a3a4b62fc	Duration: 403.67 ms	Billed Duration: 500 ms Memory Size: 512 MB	Max Memory Used: 91 MB	

As for the preference regarding the behaviour: if you check the stack trace, you see that this is actually Spring FrameworkServlet org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1080) calling the javax.servlet.ServletRequest#getRemoteAddr: as long as this works, I am happy. However, I would encourage you do a little bit of further review of the implementation as we should have proper access to the request details.

@sapessi
Copy link
Collaborator

sapessi commented Aug 13, 2018

Oh, the fact that you get the JSON output as the error body tells me that API Gateway is not parsing the Lambda proxy response into an HTTP response. Check your API Gateway configuration to make sure that the integration settings for the method are set to Lambda proxy integration.

screen shot 2018-08-13 at 10 36 09 am

@peter-gergely-horvath
Copy link
Author

This would not really work with the current setup I have: I am experimenting with an approach where the Lambda function would merely act as a gateway to an RDS database: the query would be hard-coded in each Integration Request's Mapping template as a literal while the query parameters would be extracted from the incoming request using expressions.

@sapessi
Copy link
Collaborator

sapessi commented Aug 14, 2018

What does the API look like? You could always write your own custom RequestReader and ResponseWriter. You can pass them in directly to the constructor of the SpringLambdaContainerHandler.

Out of curiosity, why embed the query in the API Gateway configuration instead of the Lambda function code?

@peter-gergely-horvath
Copy link
Author

Hi @sapessi, originally this would be a simple Java method that expects a Map of parameters and returns the result.

The purpose would be to have a fully self-contained, general Lambda function that simply executes the specified SQL statement and parameters coming from API Gateway, allowing the user to configure the lambda once and then build arbitrary REST APIs driven by API Gateway configuration only.

Imagine a similar API Gateway Integration Request:

{
    "_queryForSingleSql" : "select * from person where id = :pId",
    "pId" : "$input.params('personId')"
}

This is were it is getting funny: I tried implementing HTTP status code management according to an AWS blog post, but it did not work (I don't know why), I always got back the default HTTP 200 status, even when I tried signalling not found. After that I tried using aws-serverless-java-container to see if a Spring app is any better, but then we have the NPE issue.

If you have any recommendation on how this could be done, I would love to hear it.

@sapessi
Copy link
Collaborator

sapessi commented Aug 14, 2018

Off the top of my head. You could do this:

  • Store the queries in configuration parameters - perhaps a file in S3. A simple map of queryName => queryString
  • Clients make requests to /query/{queryName}
  • Clients can only make POST requests to this address and in the request body they include a map of parameter values
  • In your app, you can create a controller for /query/{queryName}
  • When you receive the request load the configuration and cache it, then load the parameter from the body, prepare the query and execute

This would allow you to use proxy integration and write your code as a normal webapp.

@peter-gergely-horvath
Copy link
Author

my problem with that is you no longer have a RESTful interface: API Gateway seems to be a perfect place to do this kind of mapping, but apparently it just does not work :(

@sapessi
Copy link
Collaborator

sapessi commented Aug 14, 2018

You could do it by building your own router instead of using this library or building custom RequestReader/ResponseWriter. Out of the box, this library is meant to make it super easy to get going with proxy integrations - which is the majority of use-cases. Custom event and response contracts are possible but require more work.

@clarabridges
Copy link

I am using a proxy integration and am testing through a call to the API gateway endpoint using a browser (vs in-console test) and I am also getting this NPE. I am using version 1.1.4

@sapessi
Copy link
Collaborator

sapessi commented Aug 24, 2018

Hi @clarabridges, can you share the stack trace? I'll look into it right away

@clarabridges
Copy link

clarabridges commented Aug 24, 2018

Thank you so much! This code is running as part of a prototype for our customer.

Line 39 in our code referenced in the stacktrace is AwsProxyResponse resp = handler.proxy(request, context);
The request comes from LambdaContainerHandler.getObjectMapper().readValue(inputStream, AwsProxyRequest.class);

Here is the NPE:

java.lang.NullPointerException
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequest.getRemoteAddr(AwsProxyHttpServletRequest.java:575)
at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1076)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:848)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer.dispatch(LambdaSpringApplicationInitializer.java:114)
at com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer.service(LambdaSpringApplicationInitializer.java:205)
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainManager$ServletExecutionFilter.doFilter(FilterChainManager.java:351)
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:84)
at com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler.doFilter(AwsLambdaServletContainerHandler.java:207)
at com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler.handleRequest(SpringLambdaContainerHandler.java:182)
at com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler.handleRequest(SpringLambdaContainerHandler.java:42)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:168)
at org.test.lambda.LambdaHandler.handleRequest(LambdaHandler.java:39)
at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
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:286)
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:94)

@sapessi
Copy link
Collaborator

sapessi commented Aug 24, 2018

Thanks @clarabridges. I would recommend using the proxyStream method instead of the proxy one. It uses the pre-initialized ObjectReader for the input request type - should be faster.

As for the NPE, I'll test and get to the bottom of it this weekend - I would expect that parameter to be always populated. Regardless, I'll add the necessary null checking around it. Do you have any preference as to what IP address the framework should return if the value is not populated?

In the meanwhile, could you test with an older version of the framework - for example 1.0 or 1.1 - to see if the error exists there too?

@clarabridges
Copy link

@sapessi I switched to proxyStream as suggested but made no other changes and the issue seems to have been resolved. I haven't had a chance to look into the implementation yet to see if/how that resolved it.

@sapessi
Copy link
Collaborator

sapessi commented Sep 5, 2018

@clarabridges The primary difference between the two methods is that using the prox() call you rely on Lambda's built-in marshaling of the JSON event. With the proxyStream method we use our ObjectMapper. Lambda's builtin marshaller does not support the annotations we use in our model classes, the library's ObjectMapper does.

sapessi added a commit that referenced this issue Oct 19, 2018
…he getRemoteAddr method return the localhost address (#182)
@sapessi sapessi closed this as completed Oct 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants