Hi folks,
I’ve been playing around with AWS Lambda and API Gateway. Lambda is pretty nifty, but API Gateway is (imho) a beast, and introduces quite a bit of wiring complexity.
I’m tossing around the idea of writing an alternate HTTP gateway for Lambda, and I know Go, so a Caddy plugin seems like a possibility. Before I started I wanted to get some feedback on the idea and see if anyone else would find it useful.
Lambda has no notion of headers, so that creates some issues when you want to put a HTTP gateway in front of it. HTTP headers, status codes, and method names are all pretty critical bits of info. API Gateway has a (again, imho) fairly boroque mechanism for injecting request headers into the the Lambda request, and out the Lambda response. You have to wire up these rules for every lambda you expose. It’s all fairly complicated.
I’m envisioning something much simpler: Design a standard envelope format that would be used to wrap the HTTP request metadata (method, path, headers) and request body and invoke the lambda using this envelope. Expect the labmda to respond with a similar envelope that can be used to set the response status code, headers, and body.
If you want your Lambda to support the HTTP gateway, you need to write it so that it knows how to optionally handle this envelope.
This would enable a fairly simple Caddyfile directive that could be used to reverse proxy any Lambda function without special configuration for each. For example:
awslambda /lambda/ {
# access/secret optional - default to standard AWS env vars
aws_access access-key-here
aws_secret secret-key-here
# default to us-east-1 perhaps
aws_region us-west-2
# lambda qualifier - can be used to target execution to an alias
# which is useful for test/stage/prod env separation
qualifier prod
}
This would parse the function name from the path. For example: /lambda/hello
would invoke the hello
lambda function. /lambda/my-other-fx
would invoke the my-other-fx
function.
The standard Invoke operation would be used from the plugin (see: http://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html)
Any high level thoughts on this approach? If folks like it, then the main questions are:
- Envelope format (perhaps there’s a similar spec we can use)
-
Caddyfile
options
thanks,
– James