Created
March 6, 2017 23:52
-
-
Save petrabarus/bcb8c4feb29f10617c80334f0885c67b to your computer and use it in GitHub Desktop.
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 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()} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment