8

Is it possible to access the raw url using AWS API Gateway (and Lambda)?

Alternatively, is it possible to access the original, undecoded query string paramters?

We are integrating against a third party service, that calls our API and encodes the query string params from Windows-1252. (E.g. the finnish letter Ä is encoded as %C4 instead of %C3%84). API Gateway seems to automatically decode the query string parameters and assume UTF-8, which means, that Ä (and Ö and Å) result in \ufffd.

For reference: https://www.w3schools.com/tags/ref_urlencode.asp

skoll
  • 2,272
  • 4
  • 30
  • 33
  • I think not. ApiGateway by default decode all query parameters. But you can alway encode them back if you like – Vishal Oct 17 '18 at 01:50
  • 2
    The problem is, I can not encode them back, because all non-ascii characters result in \ufffd (replacement character used when the decoding fails.) – skoll Oct 17 '18 at 06:42
  • Did you try adjusting your template mapping like this? https://stackoverflow.com/a/33143297/383839 – adamkonrad Oct 25 '18 at 15:38
  • Is there something special about that approach? I did try creating the mapping myself, but when iterating `$input.params().querystring` the values are already decoded. – skoll Oct 26 '18 at 11:48
  • Similar question: https://stackoverflow.com/questions/49372722/how-to-get-aws-api-gateway-invoke-url-in-an-aws-lambda-function – turtlemonvh Sep 06 '19 at 18:01

1 Answers1

5

Damn, it really doesn't look possible...

I started off writing how you can use Lambda Proxy Integration with event.queryStringParameters, but that parses the data into a key-value object.

Then I went down the road of Mapping Templates in API Gateway, but again there doesn't seem to be any property that shows the whole querystring.

As much as I didn't want it to be true, I can only conclude that it is not possible...

I think your best option is to encode the parameter as base64 on the client, then decode in the Lambda function using Object.keys(event.queryStringParameters)[0].

Matt D
  • 3,289
  • 1
  • 15
  • 29
  • Thanks for trying to investigate this, even though it wasn't the answer I was hoping for. I really don't understand, why don't they pass on the raw url to be processed as you please... – skoll Oct 24 '18 at 05:21