AWS API Gateway: Pass Referrer URL

喜欢而已 提交于 2019-12-09 06:45:29

问题


Is it possible for requests to the API-Gateway to pass the referrer URL to Lambda? For example, I'd love to let my lambda functions know if a request comes from the domain "good.com" vs. "bad.com".

I'm familiar with the list of supported $context Variables and I know a referrer url is not in there. I'm wondering if there is another way. If it is possible, what steps do I need to take?


回答1:


Here's how to do it.

  1. As it turns out, the mapping template allows you to map HTTP headers, not just the list of supported variables in the documentation.

  2. The HTTP header that contains the referrer domain is called "Origin". The header that contains the referer page URL is called "Referer".

  3. So, for example, you can put this in your mapping template and it will grab the associated header information:

    {
    "origin" : "$input.params('origin')",
    "referer" : "$input.params('referer')"
    }
    

Origin grabs example.com. Referer grabs example.com/pagename




回答2:


It's an HTTP header, so if you are mapping HTTP headers in the template it will be passed to the Lambda function. Look at this answer for an example of how to map HTTP headers in the request template.



来源:https://stackoverflow.com/questions/37892000/aws-api-gateway-pass-referrer-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!