ALB to Lambda query parameters problem


Hi, new guy here. Having a problem reading query parameters in a java lambda function behind a load balancer.

The question is "where are the query parameter values?"

The setup is this: we created a stream/jersey based lambda from a template which got us a StreamLambdaHandler class implementing RequestStreamHandler and specifically a handleRequest(InputStream, OutputStream, Context) method. This method sends the inputStream to a JerseyLambdaContainerHandler member which handles parsing of the stream and calls the http handler methods we created and annotated, code follows below. The load balancer just forwards calls to the lambda function.

The problem is that query parameters are not received in the http handler methods. But they do reach the RequestStreamHandler - we saw this by logging the inputStream; this is what we saw:


But once the call reaches our GET handler the parameters are gone. Code:

@Path( "/timereg" ) 
public class TimeRegistration {
    @Produces( MediaType.APPLICATION_JSON )
    @Consumes( MediaType.WILDCARD )
    @Path( "/employee" )
    public Response get( @QueryParam("id") String id, @QueryParam("eid") String eid, @QueryParam("company") String company, @QueryParam("date") String date, @QueryParam("cert") String cert, @Context UriInfo uriInfo )  
{; "queryparams: %s", uriInfo.getQueryParameters())); "pathparams : %s", uriInfo.getPathParameters()));

        long empId = Long.parseLong( eid );  // NumberFormatException: null

The log output from the code above is:
"timereg/employee" (as expected)
"queryparams: {}" ( why? )
"pathparams : {}" ( why? )

We call it with curl:
curl -v 'http://api-gateway-lb-somethingelse:9999/timereg/employee/?eid=17&company=1&id=1&cert=1&date=1'

We would be very happy if anyone could point us in the right direction. Thank you for reading.

asked 5 years ago1209 views
2 Answers
Accepted Answer

I think I figured out how to get your "getQueryParameters()" call to return values.

1. Go to Services-> EC2
2. Click on Target Groups
3. Click on your Target group
4. Under Attributes->Multi value headers, click Edit attributes
5. Put checkmark on Enable
6. click Save
You should now (hopefully) be able to run your curl command and the results should come back:
 curl -v 'http://api-gateway-lb-somethingelse:9999/timereg/employee/?eid=17&company=1&id=1&cert=1&date=1'


Edited by: RandyTakeshita on Sep 25, 2019 6:02 PM

answered 5 years ago

Tried your suggestion and it worked! Thank you.
Query parameters now contain the values from the curl command:
queryparams: {date=[1], eid=[17], cert=[1], company=[1], id=[1]}

answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions