Open peebles opened 4 years ago
Ran into this same problem myself and thanks much for confirming that this is an issue!
Quick thought: if AWS does "fix" this in the future, or if you want to be able to switch the code to run between ALB and API Gateway, I think you'll run into issues decoding an already decoded URL parameter. For example if the decoded value was something like A deal at %23 off
, then it would be improperly decoded to A deal at # off
if you decided to switch to API-G in the future (sort of a bad example, but you get it). Probably not a lot of people switching on a daily basis, but this would be important for any sort of distributed library.
Seems like maybe we need an if statement to determine if the event is coming from ALB vs. API Gateway? This would solve the ALB vs. APIG issue, but wouldn't necessarily solve the problem if they "fix" or change this in the future. Any other creative ideas thoughts? As far as I know, I can't think of a way to automatically determine if a string has already been urldecoded (because the actual value of the parameter might have characters that look like urlencoded chars), but who knows, maybe I'm missing something.
Two things:
Looks like the event payload might have:
requestContext': {
'elb': {
'targetGroupArn': 'arn:aws:elasticloadbalancing:us-east-1:XXXXXXXXXXX:targetgroup/sample/6d0ecf831eec9f09'
}
Which could be a hint
Looks like the event payload might have:
requestContext': { 'elb': { 'targetGroupArn': 'arn:aws:elasticloadbalancing:us-east-1:XXXXXXXXXXX:targetgroup/sample/6d0ecf831eec9f09' }
Which could be a hint
Brilliant! Yeah I thought maybe there would be a special/custom header that might give it away, but I didn't think about checking the rest of the event payload. Happy to submit a pull-request if you want.
PR #190 submitted.
I had a real hard time moving my function from behind API Gateway to behind an ALB with a target group. Using the ALB has some nice advantages (like routing) and it doesn't have the 30 second timeout that AGW does. But ... the event structure is slightly different! I thought about doing a pull request, but the nice architecture of this module makes it possible to deal with these differences with configuration. So it is a matter of documentation rather than making code changes. Here is my handler code that works behind an ALB:
Feel free to incorporate this somewhere in the doc, if you think it is worth it.