AWS API Gateway: Pass Referrer URL

后端 未结 2 1719
南笙
南笙 2021-02-10 18:23

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 \"go

2条回答
  •  我在风中等你
    2021-02-10 18:51

    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

提交回复
热议问题