Skip to content

Instantly share code, notes, and snippets.

@packetchef
Created November 27, 2019 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save packetchef/758ce12f9c4794a0b8f9920847a93ecc to your computer and use it in GitHub Desktop.
Save packetchef/758ce12f9c4794a0b8f9920847a93ecc to your computer and use it in GitHub Desktop.
Lambda function to return request HTTP headers
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