Home > Software engineering >  How to get client full url in AWS lambda through AWS gateway requested by <script src="***&q
How to get client full url in AWS lambda through AWS gateway requested by <script src="***&q

Time:12-23

I am using html script tag to ping AWS gateway endpoint to trigger a function in AWS lambda.

In this lambda function, I need to retrieve the original client's full url. I can get referer data but can't figure out how to get the full url.

I tried to see if there is "origin" info in "event" object but there is no such data.

exports.handler = async (event, context) => {
  return {
    statusCode: 200,
    body: "console.log("  JSON.stringify(event)  "," JSON.stringify(context)  ")"
  };  
}

Here is the client code that pings the http api gateway index.html

<html>
  <script src="http api gateway endpoint" defer async />
  <body></body>
</html>

Now how can I get the client full url in lambda function?

CodePudding user response:

The information sent in a referrer header is restricted for security reasons. You can adjust this with a header or the referrerpolicy attribute.

Note that the <script> element is not a void element. The end tag is mandatory.

<script src="http api gateway endpoint" defer async referrerpolicy"unsafe-url"></script>

You could also generate the <script> element dynamically and pass data from window.location in the query string.

  • Related