apex / gateway

Drop-in replacement for Go net/http when running in AWS Lambda & API Gateway
MIT License
652 stars 73 forks source link

Toggle to fall back to http.ListenAndServe #10

Open mozey opened 6 years ago

mozey commented 6 years ago

Using sam local start-api is great but

I'd like to have a toggle to fall back to net/http only:

ApexGatewayDisabled := os.Getenv("APEX_GATEWAY_DISABLED")
if ApexGatewayDisabled == "true" {
    log.Fatal(http.ListenAndServe(":3000", nil))
} else {
    log.Fatal(gateway.ListenAndServe(":3000", nil))
}

Everywhere AWS specific functionality is used above condition must also be checked.

Does this approach make sense or is there a better way?

piotrkubisa commented 6 years ago

Why don't you use separate binaries - one for serverless (apex) and second for serverfull (http)? More code in handler = larger binary = more money spent on uploading artifact = (in many cases) worse performance = more money spent on Lambda runtime (yeah, I know free tier). I highly advocate for separating logic, especially in Lambda handlers.

mohemohe commented 4 years ago

you can use AWS_LAMBDA_FUNCTION_NAME envronment variable.

if os.Getenv("AWS_LAMBDA_FUNCTION_NAME") == "" {
    log.Fatal(http.ListenAndServe(":3000", nil))
} else {
    log.Fatal(gateway.ListenAndServe(":3000", nil))
}
ilgityildirim commented 4 years ago

@mohemohe thanks for the env suggestion. It is useful to know.