Closed rynop closed 6 years ago
https://github.com/apex/gateway looks to be promising, will investigate and report back
https://github.com/apex/gateway still requires a full blown HTTP server (listening on a port etc). I think I can get it to work, but my “ideal” solution would be to use all the Twirp badassness (routing, code generation, error handling etc) WITHOUT the need for the HTTP stack because APIG is already providing the HTTP stack - for example already parsed the headers out of HTTP, which apex/gateway has to re-do to send onto net/http
.
Would it require a ton of Twirp re-factoring to “turn off” the http protocol stuff and instead just pass the Headers and POST body to Twirp directly? I’d just pass along the Twirp sterilized JSON response on the Lambda return
.
Bummer is to get application/protobuf
working I’d have to base64 encode the Twrip protobuf response before sending it back from Lambda (which incurs performance penalty)
@spenczar correctly pointed out to me that:
the
address
part of apex/gateway's ListenAndServe is a red herring - if you check the source, you'll see that it's unused. It's just there to match the standard librarynet/http.ListenAndServe
signature that people are used to
So apex/gateway
does not start a full blown HTTP server. Re-setting the HTTP headers is almost a no-op, a small price to pay to get integration with Twirp.
I will report back here if/when I get something working.
I got this working. It is super slick. I'll write a blog post and put link here in the next day or so.
OK wrote a blog post and created an example/guide that details how to run Twirp completely serverless on AWS with JSON and binary protobuf support.
Closing
Anyone tried to run Twirp on Lambda yet?
I'm not a fan of API Gateway (APIG) and all the complexity, but I love lambda. I think it would be sweet to do the following:
ANY
method on the/{proxy+}
resource will reverse proxy everything to one Lambda function (lambda function is a go binary using Twirp).application/json
request comes into APIG, it gets routed to Lambdaevents. APIGatewayProxyRequest
(github.com/aws/aws-lambda-go/events) to the HTTP request object that Twitch needs.return events.APIGatewayProxyResponse
Questions (I'm a go noob, never used RPC or protobuf but they make sense to me):