Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@petrabarus
Created March 6, 2017 23:52
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 petrabarus/bcb8c4feb29f10617c80334f0885c67b to your computer and use it in GitHub Desktop.
Save petrabarus/bcb8c4feb29f10617c80334f0885c67b to your computer and use it in GitHub Desktop.
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