Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle to fall back to http.ListenAndServe #10

Open
mozey opened this issue Jun 1, 2018 · 3 comments
Open

Toggle to fall back to http.ListenAndServe #10

mozey opened this issue Jun 1, 2018 · 3 comments

Comments

@mozey
Copy link

mozey commented Jun 1, 2018

Using sam local start-api is great but

  • it's slow handling requests
  • it would be nice to have the option of running code stand alone outside Lambda

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
Copy link

piotrkubisa commented Jun 1, 2018

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
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants