ALB to Lambda query parameters problem

0

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:

{"requestContext":{"elb":{"targetGroupArn":"arn:aws:elasticloadbalancing:eu-west-1:somewhere:targetgroup/blue/something"}},"httpMethod":"POST","path":"/timereg/employee/","queryStringParameters":{"cert":"1","company":"1","date":"1","eid":"17","id":"1"},"headers":{"accept":"*/*","host":"api-gateway-lb-somethingelse:9999","user-agent":"curl/7.64.0","x-amzn-trace-id":"Root=1-5d8b7c0e-f2ab4da860b54450ce8a2234","x-forwarded-for":"33.44.55.66","x-forwarded-port":"9999","x-forwarded-proto":"http"},"body":"","isBase64Encoded":false}

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

@Path( "/timereg" ) 
public class TimeRegistration {
    @GET
    @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 )  
{
        logger.info(uriInfo.getPath()); 
        logger.info(String.format( "queryparams: %s", uriInfo.getQueryParameters())); 
        logger.info(String.format( "pathparams : %s", uriInfo.getPathParameters()));

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

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.

preguntada hace 5 años1220 visualizaciones
2 Respuestas
0
Respuesta aceptada

Hi,
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'

-randy

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

respondido hace 5 años
0

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

respondido hace 5 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas