Search code examples
javascripthtmlamazon-web-serviceshtml-email

Get user agent using img tag


I'm using a simple img html tag in an email message in order to run an AWS Lambda everytime the message is reading. Img tag is like:

<img alt="" src="https://lambda-url?att=data">

I can send data to the lambda via url, but I want to be able to pass a full user agent to the lambda, without using a script tag, only with the img tag. How to do that?


Solution

  • You don't need to do anything - the user-agent is included in the event object passed to your script. I've not used Javascript in Lambda, but in Python, the user-agent is at

    event['Records'][0]['cf']['request']['headers']['user-agent'][0]['value']
    

    I assume you are aware that web bugs are not very reliable indicators.