I am experimenting with Go on AWS lambda, and i found that each function requires a binary to be uploaded for execution.
My question is that, is it possible to have a single binary that can have two different Handler
functions, which can be loaded by two different lambda functions.
for example
func Handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
fmt.Println("Received body in Handler 1: ", request.Body)
return events.APIGatewayProxyResponse{Body: request.Body, StatusCode: 200}, nil
}
func Handler1(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
fmt.Println("Received body in Handler 2: ", request.Body)
return events.APIGatewayProxyResponse{Body: request.Body, StatusCode: 200}, nil
}
func EndPoint1() {
lambda.Start(Handler)
}
func EndPoint2() {
lambda.Start(Handler1)
}
and calling the EndPoints
in main
in such a way that it registers both the EndPoints
and the same binary would be uploaded to both the functions MyFunction1
and MyFunction2
.
I understand that having two different binary is good because it reduces the load/size of each function.
But this is just an experimentation.
Thanks in advance :)
I believe it is not possible since Lambda console says the handler is the name of the executable file:
Handler: The executable file name value. For example, "myHandler" would call the main function in the package “main” of the myHandler executable program.
So one single executable file is unable to host two different handlers.
you can do the workaround to have same executable to upload to two different lambda like following
func main() {
switch cfg.LambdaCommand {
case "select_lambda_1":
lambda1handler()
case "select_lambda_2":
lambda2handler()
通过向 template.yaml 中的函数添加环境变量,并使 main() 检查变量并调用适当的处理程序,我取得了成功。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.