-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.py
26 lines (23 loc) · 1.01 KB
/
handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import sys
sys.path.append('gen-py')
sys.path.append('vendored')
from thrift.protocol import TBinaryProtocol, TJSONProtocol
from thrift.server import TServer
from thrift.transport import TTransport
from lambda_thrift_service import MultiplicationService
class MultiplicationServiceHandler(object):
def multiply(self, i, j):
return i * j
handler = MultiplicationServiceHandler()
processor = MultiplicationService.Processor(handler)
# I tried using TBinaryProtocol but somewhat it won't work, TJSONProtocol works
protocol_factory = TJSONProtocol.TJSONProtocolFactory()
server = TServer.TServer(processor, None, None, None, protocol_factory, protocol_factory)
def multiply(event, context):
body = event['body']
itrans = TTransport.TMemoryBuffer(body)
otrans = TTransport.TMemoryBuffer()
iprot = server.inputProtocolFactory.getProtocol(itrans)
oprot = server.outputProtocolFactory.getProtocol(otrans)
server.processor.process(iprot, oprot)
return {'statusCode': 200, 'body': otrans.getvalue()}