- Mastering Azure Serverless Computing
- Lorenzo Barbieri Massimo Bonanni
- 466字
- 2021-06-24 12:37:09
Exposing your Azure Functions on the internet with ngrok
As you have read in the previous paragraphs, you can use the Azure Functions runtime to host your functions, but the host process exposes your function on the localhost, so you cannot reach them from another PC than the one hosting them.
If you want to expose your functions on the internet and, therefore, solve the problem, you can use ngrok. ngrok is software (running on Windows, macOS, and Linux) that allows you to expose a local server to the internet using a secure tunnel, and it also works if your local server is behind a NAT or a firewall.
- To use ngrok, you need to register yourself on the ngrok website and create an account.
ngrok has a free plan that allows you to use the software for free with the limitation of only one process at a time with a maximum of four tunnels and a random port, but it is enough to test your functions.
- Once you download the ngrok client, you have to connect your account to the client (you need to do this operation once only) using the following command:
ngrok.exe authtoken <your_auth_token>
You can find your authentication token in the Auth section of your account dashboard:

- To expose your local function using ngrok, simply expose the local port using the http command:
C:>func host start --port 9999
C:>grok http 9999
The following screenshot shows the output of the preceding command:

The http command starts a tunnel from a random subdomain hosted by the ngrok platform (in the previous screenshot, a84984cb.eu.ngrok.io) to your PC. You can call your Azure Functions using the sub-domain instead, http://localhost; for example, if your function has the http://localhost:9999/api/books URL, you call it using the http://a84984cb.eu.ngrok.io/api/book URL.
The ngrok console shows the HTTP requests received through the tunnel, but ngrok also exposes a web GUI you can display using the http://localhost:4040 URL. The web console shows you all the requests received by the ngrok tunnel, as you can see in the following screenshot:

And it also shows you the metrics about your connection, as you can see in the following screenshot:

The web GUI allows you to inspect every single request received and gives you information about the tunnel and statistics about the requests (for example, connections and request duration).
- 30天自制操作系統
- 電腦組裝與系統安裝
- Linux系統架構與運維實戰
- 構建高可用Linux服務器(第4版)
- Implementing Cisco UCS Solutions
- Ubuntu Linux操作系統
- SharePoint 2013 WCM Advanced Cookbook
- 計算機系統開發與優化實戰
- Linux系統安全基礎:二進制代碼安全性分析基礎與實踐
- 無蘋果不生活 The New iPad隨身寶典
- Hands-On UX Design for Developers
- 大規模分布式系統架構與設計實戰
- 計算機應用基礎(Windows 7+Office 2010)
- Mastering Azure Serverless Computing
- Xamarin Mobile Application Development for Android