AWS API Gateway: Pass Referrer URL

后端 未结 2 1687
南笙
南笙 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:45

    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.

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题