The Wayback Machine - https://web.archive.org/web/20201129024718/https://github.com/jeremydaly/lambda-api/issues/53
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

Add support to run standalone API server locally #53

Open
abmohan opened this issue Jun 28, 2018 · 10 comments
Open

Add support to run standalone API server locally #53

abmohan opened this issue Jun 28, 2018 · 10 comments

Comments

@abmohan
Copy link

@abmohan abmohan commented Jun 28, 2018

sls invoke is useful for testing our API one request at a time.

It would be nice to spin up a local version of the API on localhost to enable us to develop our frontend apps against it, and to more easily run integration and E2E tests.

@jeremydaly
Copy link
Owner

@jeremydaly jeremydaly commented Jul 8, 2018

@abmohan, this is a great idea. This might be possible with the serverless-offline plugin, but it would be nice to have a solution that wasn't tethered to a single framework. I'll do some investigating, but any ideas you have would be appreciated!

@abmohan
Copy link
Author

@abmohan abmohan commented Jul 9, 2018

Thanks, @jeremydaly. I was thinking of trying to wrap it in an express app for this purpose but opted to just go with serverless-offline, since we're using serverless for the rest of our build process as well.

If you do come up with an idea and would like some help putting it together, I'm happy to give it a shot!

@compwright
Copy link

@compwright compwright commented Sep 10, 2018

I can confirm that lambda-api works perfectly fine with serverless-offline.

Note that serverless-offline just simulates AWS API Gateway, so it is framework agnostic.

@GuidoNebiolo
Copy link

@GuidoNebiolo GuidoNebiolo commented Nov 5, 2018

I can confirm that lambda-api works fine with AWS SAM CLI https://github.com/awslabs/aws-sam-cli

@Sleavely
Copy link
Contributor

@Sleavely Sleavely commented Dec 30, 2018

In the spirit of keeping dependencies and external tools to a minimum, I solved this by splitting the route management into a separate module (api.js) so that it could be accessed either by lambda.js or local.js. The latter contains a small web server that fakes the essentials for lambda-api to function properly.

I've put my sample solution in a gist here: https://gist.github.com/Sleavely/f87448d2c1c13d467f3ea8fc7e864955

@jlopezcrd
Copy link

@jlopezcrd jlopezcrd commented May 23, 2020

In the spirit of keeping dependencies and external tools to a minimum, I solved this by splitting the route management into a separate module (api.js) so that it could be accessed either by lambda.js or local.js. The latter contains a small web server that fakes the essentials for lambda-api to function properly.

I've put my sample solution in a gist here: https://gist.github.com/Sleavely/f87448d2c1c13d467f3ea8fc7e864955

In my local env, throw a exception and not work :( You can help me? Thanks

image

@Sleavely
Copy link
Contributor

@Sleavely Sleavely commented May 23, 2020

In the spirit of keeping dependencies and external tools to a minimum, I solved this by splitting the route management into a separate module (api.js) so that it could be accessed either by lambda.js or local.js. The latter contains a small web server that fakes the essentials for lambda-api to function properly.
I've put my sample solution in a gist here: https://gist.github.com/Sleavely/f87448d2c1c13d467f3ea8fc7e864955

In my local env, throw a exception and not work :( You can help me? Thanks

image

It looks like there is no body in the response. Could it be because you don't have a route defined for the path you are accessing? If you copy-pasted my Gist as-is; does /status work? Are you able to share the code that's breaking?

@jlopezcrd
Copy link

@jlopezcrd jlopezcrd commented May 24, 2020

In the spirit of keeping dependencies and external tools to a minimum, I solved this by splitting the route management into a separate module (api.js) so that it could be accessed either by lambda.js or local.js. The latter contains a small web server that fakes the essentials for lambda-api to function properly.
I've put my sample solution in a gist here: https://gist.github.com/Sleavely/f87448d2c1c13d467f3ea8fc7e864955

In my local env, throw a exception and not work :( You can help me? Thanks
image

It looks like there is no body in the response. Could it be because you don't have a route defined for the path you are accessing? If you copy-pasted my Gist as-is; does /status work? Are you able to share the code that's breaking?

Yes, i upload the test code to my github: https://github.com/jlopezcrd/lambda-api-test

@jlopezcrd
Copy link

@jlopezcrd jlopezcrd commented May 26, 2020

In the spirit of keeping dependencies and external tools to a minimum, I solved this by splitting the route management into a separate module (api.js) so that it could be accessed either by lambda.js or local.js. The latter contains a small web server that fakes the essentials for lambda-api to function properly.

I've put my sample solution in a gist here: https://gist.github.com/Sleavely/f87448d2c1c13d467f3ea8fc7e864955

I've modified the local file and it works. You can review it:
https://github.com/jlopezcrd/lambda-api-test/compare/master...fixlocal?expand=1

Regards.

@Sleavely
Copy link
Contributor

@Sleavely Sleavely commented May 27, 2020

I've modified the local file and it works. You can review it:
https://github.com/jlopezcrd/lambda-api-test/compare/master...fixlocal?expand=1

Regards.

Interesting. I'm not sure why that approach works but I'm glad you got it running :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
6 participants
You can’t perform that action at this time.