Created
November 27, 2019 19:22
-
-
Save packetchef/758ce12f9c4794a0b8f9920847a93ecc to your computer and use it in GitHub Desktop.
Lambda function to return request HTTP headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def lambda_handler(event, context): | |
requestPath = event['path'] | |
xff = event['headers']['x-forwarded-for'] | |
clientIP = '<empty>' | |
response = ''' | |
<!DOCTYPE html><html><head></head><body> | |
<div class="info"> | |
<p><span>Client IP:</span> <span>{clientIP}</span></p> | |
<p><span>X-Forwarded-For:</span> <span>{xff}</span></p> | |
<p><span>Request path:</span> <span>{requestPath}</span></p> | |
</div> | |
</body> | |
</html> | |
'''.format(clientIP=clientIP, xff=xff, requestPath=requestPath) | |
return { | |
'statusCode': 200, | |
'body': response, | |
"headers": { | |
'Content-Type': 'text/html', | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment