What you’ll need
- An ngrok account.
- Your ngrok auth token.
- An ngrok API key.
This doc assumes you’ve already completed the Agent CLI Quickstart—if not, you should start there to learn about some of ngrok’s fundamental features before continuing here.
Part one: your first cloud endpoint
The best way to familiarize yourself with cloud endpoints is to create one in your ngrok dashboard.1. Install the ngrok Agent CLI
If this is your first time using ngrok, run the command that corresponds to your operating system to install the Agent CLI:2. Connect your account
Connect your agent to your ngrok account by providing your auth token as shown below—replace$YOUR_TOKEN
with the string given to you in the dashboard.
3. Create your cloud endpoint in the dashboard
Click here to create a new cloud endpoint in your dashboard. There are three bindings to choose from: for this example, select Public. In the URL field, enter the domain you reserved in step 1. Then click Create Cloud Endpoint. This takes you to a page where you can manage your new endpoint’s traffic policy. You can leave all of the default settings in place for now.Traffic policies are optional for agent endpoints but required for cloud endpoints, which is why the dashboard generates one for you automatically.
4. Start your app or service
Start up the app or service you’d like to put online. If you don’t have an app to work with, you can create a minimal app in your language of choice using the following code to set up a basic HTTP server at port8080
.
5. Start your agent endpoint
Start the ngrok agent by running the following command (replace8080
if your app is running on a different port):
--url
flag connects your agent endpoint to your cloud endpoint, so when requests are made to your domain they’ll be routed here.
The default URL for this is https://default.internal
, which was defined in the traffic policy when you created the cloud endpoint in step 4.
6. Test your cloud endpoint
Your endpoint should now be online. Visit your domain URL to see the app that’s running on your local device.Part two: creating cloud endpoints via the ngrok API
Now that you’re familiar with the key concepts necessary to work with cloud endpoints, let’s create another one using the ngrok API, which you can access via the Agent CLI. (You can use any HTTP client you prefer for interacting with the ngrok API, but the Agent CLI provides a simple and direct access point for getting started.) Keep your local app and agent endpoint from part one running. If you only have one domain to work with, delete the cloud endpoint you created in the dashboard before continuing so you can reuse the domain in the steps below.1. Create your traffic policy
Create apolicy.yml
on your local machine and add the code snippet below.
This policy states that incoming HTTP requests should be forwarded to your internal agent endpoint at https://default.internal
; if that endpoint’s not reachable, then it falls back on a custom response to indicate that the app is offline.
policy.yml
2. Create your cloud endpoint
Create your cloud endpoint by running the following command—replace$YOUR_API_KEY
and $YOUR_DOMAIN
with their respective values:
3. Test your endpoint
Your endpoint should now be online. Visit your reserved domain URL to see the app that’s running on your local device. To see the fallback response, terminate your local app or agent endpoint and then visit your cloud endpoint URL again. You should see the custom message defined inpolicy.yml.
What’s next?
In this guide, you learned how to create a Cloud Endpoint using both the dashboard and the ngrok API. You configured a basic traffic policy to forward requests from one endpoint to another, and you saw how cloud endpoints can be layered on top of agent endpoints to route traffic to different services and fallback responses based on the criteria you define. What else can you do with these features?- See the cloud endpoints overview to learn more about use cases, how they compare to agent endpoints, and more.
- If you need to interact with cloud endpoints programmatically, check out ngrok’s API client libraries.
- See Load Balancing with Cloud Endpoints to learn how to distribute traffic across multiple internal endpoints.
- This quickstart barely scratches the surface of what’s possible with a traffic policy—check out the Actions overview to see what else you can do.