mrserverless / serverless-golang

AWS Lambda Go functions using Serverless Framework and Python shim
Other
302 stars 21 forks source link

Multi-function example #4

Closed cristim closed 7 years ago

cristim commented 7 years ago

The example should be extended to contain multiple functions collected in a single serverless configuration, for example:

mrserverless commented 7 years ago

To clarify, do you mean:

  1. a HTTP CRUD API with 4 different functions behind an API Gateway
  2. Or multiple functions serving both HTTP and other Event Sources at the same time?
cristim commented 7 years ago

@yunspace it doesn't really matter, I think the point is to show how to support serverless stacks with multiple functions.

I guess combining both would be even better: CRUD API for HTTP, and an additional trigger using a different source type.

cristim commented 7 years ago

This should work out of the box, with the caveat that it only supports a relatively small number of handlers until https://github.com/golang/go/issues/19269 is fixed.

Quoting @fsenart, the author of aws-lambda-go-net:

you can have several handlers exported if you need, if you export Handle1 and Handle2 then in one lambda you can configure handler.Handle1 and in the other handler.Handle2 with the same binary. But be aware of known limitation https://github.com/eawsy/aws-lambda-go-shim#known-limitations.

When more than 8 handlers are needed in the same binary, the code would need to be built into multiple golang binaries. This example doesn't support such multi-binary builds yet, and the question is if it makes sense to do it or we can just wait until that issue is fixed in golang.

I personally think it's fine to wait for it and that this issue can be closed with that caveat, once we create multiple handlers and reference them from the serverless configuration.

If someone out there really needs support for more handlers sooner, a PR with multi-binary support would be more than welcome.

mrserverless commented 7 years ago

thanks @cristim for all the thorough research. I've been busy preparing to speak at the Docker 4th Birthday (will squeeze in a quick mention of this lib also), once that's over I'll focus on getting the separate examples setup and the multi-function.

mrserverless commented 7 years ago

I have created a CRUD example that uses a single Handler (Lambda function) to serve all CRUDs behind a Mux and a single API GW. I think this is sufficient to illustrate the functionality of serverless and the go-net shim. Will close this for now and add more event driven examples as a separate ticket.