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.

질문됨 5년 전1209회 조회
2개 답변
0
수락된 답변

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

답변함 5년 전
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}

답변함 5년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠