lambda_http.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. def lambda_handler(event, context):
  2. response = {
  3. "statusCode": 200,
  4. "statusDescription": "200 OK",
  5. "isBase64Encoded": False,
  6. "headers": {
  7. "Content-Type": "text/html; charset=utf-8"
  8. }
  9. }
  10. response['body'] = """<html>
  11. <head>
  12. <title>Hello World!</title>
  13. <style>
  14. html, body {
  15. margin: 0; padding: 0;
  16. font-family: arial; font-weight: 700; font-size: 3em;
  17. text-align: center;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <p>Hello World!</p>
  23. </body>
  24. </html>"""
  25. return response
  26. # ====================分割线====================
  27. import json
  28. def lambda_handler(event, context):
  29. response = {
  30. "statusCode": 200,
  31. "headers": {
  32. "Content-Type": "text/plain;"
  33. },
  34. "isBase64Encoded": False
  35. }
  36. if event['path'] == '/myip':
  37. sourceip_list = event['headers']['x-forwarded-for'].split(',')
  38. if sourceip_list:
  39. sourceip = str(sourceip_list[0])
  40. response['body']=sourceip
  41. else:
  42. response['body']='?.?.?.?'
  43. return response
  44. response['body'] = json.dumps(event, indent=2)
  45. return response