Core concepts
- Cloud Endpoints are centrally managed endpoints in the cloud that you can use to route traffic to Agent Endpoints.
- Internal endpoints are endpoints that are not publicly accessible and are only reachable from within your network by Cloud Endpoints via the forward action.
- Load balancing improves application performance and reduces load by distributing incoming traffic across servers. This leads to faster response times for user-facing applications.
Prerequisites
To follow this guide, you need a local computer withngrok installed.
You can download ngrok here.
If you’re following along using the ngrok CLI, you need:
- An ngrok API key configured on your ngrok agent.
- An ngrok API key as an environment variable named
NGROK_API_KEY.
Create an internal endpoint
Start by creating an internal endpoint, initiated from the agent.
The endpoints use HTTP in this guide, but you can also use TCP or TLS.After running the above command, you should see an internal endpoint with an “online” status for your domain.
This endpoint routes traffic to the app running at your local port 80.
You can set up any HTTP server to run on this port locally, and the endpoint internally routes traffic to that server.
Create a domain
Next, create the domain that the Cloud Endpoint resides on.
For the purpose of this guide, create an ngrok HTTP domain.When you have completed this step, you can move on to the next step.
- ngrok CLI
- CURL
- ngrok dashboard
- Replace or set
${NGROK_SUBDOMAIN}as the subdomain you’d like to use for this guide.
skip-validation
Create a Traffic Policy for your Cloud Endpoint
Unlike Agent Endpoints in which Traffic Policies are optional, Cloud Endpoints require a Traffic Policy so they know how to handle incoming traffic.
This guide shows one of the simplest and most common use cases: forwarding traffic to other endpoints (the internal endpoint you created in Step 1) via the forward action.
Create an ngrok Cloud Endpoint
Now create an ngrok Cloud Endpoint that points to the newly created internal endpoint.
You can create Cloud Endpoints via the API or the ngrok dashboard.
- API
- ngrok dashboard
Use the URL from Step 2 as the
url value in the Traffic Policy, and the Traffic Policy from Step 3 as the traffic-policy value.
This command sets the binding to public so anyone can access the Cloud Endpoint.- Replace NGROK_SUBDOMAIN with the value you used in Step 2.
Conclusion
You’re done. You’ve successfully created a Cloud Endpoint that you can access from the URL you reserved:${NGROK_SUBDOMAIN}.ngrok.app
The Cloud Endpoint refers to its Traffic Policy and forwards traffic to the internal endpoint.
The internal endpoint finally exposes the local port you created it on in Step 1.