-
Notifications
You must be signed in to change notification settings - Fork 559
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
Comments
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. |
Hi @sapessi: I tried this from the Lambda console and API Gateway through the test functionality: both of them keep failing. |
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? |
Hi @sapessi, I tried deploying the API and it seems to fail with the very same error.
but I was able to correlate the call with the CloudWatch log, which complains about the NPE:
As for the preference regarding the behaviour: if you check the stack trace, you see that this is actually Spring FrameworkServlet |
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. |
What does the API look like? You could always write your own custom Out of curiosity, why embed the query in the API Gateway configuration instead of the Lambda function code? |
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:
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 If you have any recommendation on how this could be done, I would love to hear it. |
Off the top of my head. You could do this:
This would allow you to use proxy integration and write your code as a normal webapp. |
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 :( |
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. |
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 |
Hi @clarabridges, can you share the stack trace? I'll look into it right away |
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 Here is the NPE:
|
Thanks @clarabridges. I would recommend using the 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? |
@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. |
@clarabridges The primary difference between the two methods is that using the |
…he getRemoteAddr method return the localhost address (#182)
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:I suspect either
requestContext
orrequestContext.identity
is going to benull
.Expected behavior
AwsProxyHttpServletRequest
should properly return the remote address.Actual behavior
AwsProxyHttpServletRequest.getRemoteAddr
throws aNullPointerException
Steps to reproduce
See project in https://github.com/peter-gergely-horvath/aws-sdk-bugreport
Full log output
The text was updated successfully, but these errors were encountered: