Open fabianfett opened 4 years ago
I think the handler name is important as the code could contain many lambda function in the same binary even if it executes the only one selected.
Hi @Andrea-Scuderi , you can easily achieve the use case you mention with the tools at hand right now:
import AWSLambdaRuntime
switch Lambda.env("_HANDLER") {
case "foo":
Lambda.run(FooHandler())
case "bar":
Lambda.run(BarHandler())
default:
preconditionError("Unexpected handler name: \(Lambda.env("_HANDLER") ?? "none given")")
}
In my humble opinion it doesn't make much sense though to include two or more Handlers
in one executable:
Instead I would suggest you create an executable target for each lambda. This way you will have better performance and one less String attached. 😉
In other languages like golang the _HANDLER
referrers to the name of the binary. This is something that you can easily build yourself with a bootstrap script that you ship with your lambda. But be aware including multiple binaries within your zip will dramatically worsen your cold start performance.
@fabianfett Agreed, your considerations are right, but there are cases in which this could make sense: 1) The binary can be stored in a lambda layer and shared among lambdas. 2) If the size of the binary doesn't change dramatically by adding more Lambdas, the advantage of having a fatter one could pay in terms of deployment time by reducing the complexity of creating more swift targets in the package. Having a small number of target in the swift package could speed up build time, packaging and upload time. 😉
Here the example with multiple handlers #125
We currently don't respect the chosen handler and rely on the executable being named bootstrap. We should at least document that we don't care about the given handler name, or that developers might want to use it in their lambda startup method to decide which handler they wanna attach to the runtime.