Open mozey opened 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.
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))
}
@mohemohe thanks for the env
suggestion. It is useful to know.
Using
sam local start-api
is great butI'd like to have a toggle to fall back to
net/http
only:Everywhere AWS specific functionality is used above condition must also be checked.
Does this approach make sense or is there a better way?