lambda_logs_refund.py 932 B

123456789101112131415161718192021222324252627282930
  1. import json
  2. import urllib.request
  3. import urllib.parse
  4. import base64
  5. import gzip
  6. def lambda_handler(event, context):
  7. game_id=456
  8. user_id=123
  9. url = "http://onlyellow.cstor.cn:18888/launch_refund"
  10. de_content = base64.b64decode(event['awslogs']['data'])
  11. ret = json.loads(gzip.decompress(de_content).decode('utf8'))
  12. log_msg = ret['logEvents'][0]['message']
  13. tup_log = log_msg.split(' ', -1)
  14. if len(tup_log[5]) == 36:
  15. refund_id = tup_log[5]
  16. data = json.dumps({"user_id":user_id, "game_id":game_id, "refund_id":refund_id})
  17. last_data=bytes(data,encoding='utf-8')
  18. headers = {"Content-Type":'application/json'}
  19. req = urllib.request.Request(url=url, headers=headers, data=last_data)
  20. response = urllib.request.urlopen(req)
  21. print(response.read().decode('utf-8'))
  22. else:
  23. print('hhhhhhhhhhhhaaaaaaaaaa')