Get rawQueryString from ALB

0

API Gateway is able to provide the rawQueryString from a request going to the API Gateway and then to the lambda, but I cannot find this attribute in the load balancer. For example, same request to API Gateway and ALB

API Gateway proxy event
{  
rawQueryString: 'filters[siteId][$in]=85ff70e0-2870-4cf7-a693-f62f4367daa&filters[siteId][$in]=321',  
queryStringParameters: {    'filters[siteId][$in]': '85ff70e0-2870-4cf7-a693-f62f4367daa,321'  }
}

ALB event forwarding to Lambda:
{  
queryStringParameters: { 'filters[siteId][$in]': '321' }
}

I am not able to find this in the documentation in the load balancer: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers

Why is ALB modifying the request and the query string? I would expect to get the same request passed to the lambda and have the same raw query parameters.

2 Antworten
0

Are you sure your API gateway is not doing some mapping for the response? ALBs does not modify the HTTP Requests received from clients - it adds additional headers to the existing request (e.g. X-Forwarded-For, X-Forwarded-Port, X-Forwarded-Proto, X-Amzn-Trace-Id ), and it can make forwarding decision based on the HTTP Request method, HTTP Header, Path, Query String or Source IP address values . But it does not modify any of the existing headers or the body of the request. Even while using "forward to" rule the parameters should be passed just like the redirection rule. However using a mapping template to override an API's request and response parameters and status codes, so check your API Gateway configuration and specifically the response from API gateway.

https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-override-request-response-parameters.html

profile pictureAWS
beantwortet vor einem Jahr
  • We are not modifying anything in the API gateway request. The property rawQueryString is given to the lambda from the API Gateway. This doesn't happen in the ALB. The lambda does not get the raw query parameters.

0

Looking at the query, I would like you to share some more information on the setup and the use case you are trying to achieve.

I understand that, you were able to successfully pass the query string parameters from the API to the Lambda function when you tried the setup as below.

API gateway -> Lambda. Am I right?

And Is your current setup or the setup you are trying to achieve is as below: API gateway -> ALB -> Lambda? If yes, please confirm.

If your setup is something different than the above one's, please share more information on the same.

Meantime, you can also have at some of the discussions below related to the Client -> ALB -> Lambda in the documentation:

"If requests from a client contain headers with multiple values or contains the same header multiple times, or query parameters with multiple values for the same key, you can enable support for multi-value header syntax. After you enable multi-value headers, the headers and query parameters exchanged between the load balancer and the Lambda function use arrays instead of strings. If you do not enable multi-value header syntax and a header or query parameter has multiple values, the load balancer uses the last value that it receives." [+]https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers [+]https://stackoverflow.com/questions/60997930/serverless-alb-event-does-not-have-query-params-as-a-list-with-multivaluequeryst

profile pictureAWS
SUPPORT-TECHNIKER
beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen