9
votes

We've got dockerized microservices in AWS, all behind an API Gateway and accessible via REST. Authentication is managed by the API Gateway.

Is there any possibility to test those REST-microservices on a local machine (including authentication/api gateway logic)? Is there a possibility to make the API Gateway echo back the requests to my local machine and to call the microservices running locally? What is best practice for testing API Gateway managed authentication locally?

Thanks!

3
For the authentication you use Cognito or custom authorizer?Rumesh Eranga Hapuarachchi
I use AWS IAM with federated identities for authentication. Users sign in via cognito user pool and are then provided with the identity pool id and IAM rights to access the APIMichael Walz
I will add this as a comment since it might not directly answer your question. When it comes to serverless development I use https://github.com/dherault/serverless-offline which emulates Lambda and API Gateway. In this, API Gateway emulates lot of functionalities with custom authorizer. However AFAIK it does not support user pools at the moment. However here you can't separate API Gateway, but I am sure you can hack a way to get it work with your microservices.Rumesh Eranga Hapuarachchi
I hoped for a simpler solution offered directly by API Gateway. Nevertheless thanks a lot for your helpful contribution!Michael Walz
Or use LocalStackRaf

3 Answers

12
votes

To use the AWS API Gateway locally, spin up SAM locally using the SAM CLI. There are however limits to what you can do with SAM, so you may not be able to do what you need to do locally. For example, websockets are still not supported (as of Sept 2020) as far as I know.

Instead of voting this answer down, please add a comment to provide other important information.

SAM stands for Serverless Application Model. See the Quickstart Guide for Developing Serverless Apps using SAM.

Other links:

Running API Gateway Locally

AWS CLI (required to run the SAM CLI)

Install the SAM CLI

SAM CLI Reference

5
votes

Unfortunately, API Gateway doesn't offer local testing/development solutions at the moment. Thank you for your feedback; I have added your use-case to our backlog.

Regards, Ritisha.

0
votes

To call the microservices locally a workaround could be to use Private integration on API Gateway which would use VPCLink. VPCLink will connect to services running within a VPC via NLB. For example, the setup would be API Gateway --> VPCLink Integration --> NLB --> EC2 instance (for example, acts as proxy) --> calls local service (VPC connects to local network via Direct connect)

Although a complicated setup but a possible workaround