はじめに
Azure CloudShellは基本的に外部からアクセスすることはできません。あえてこれを外部に公開してアクセスできるようにします。
方法はいたって簡単です。ngrokを利用します。
インストール
ngrokは事前にアカウントを作成しておく必要があります。
下記よりngrokをダウンロードします。
wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz tar zxvf ngrok-v3-stable-linux-amd64.tgz
トークンを登録します。
./ngrok config add-authtoken 2E9bezjGkBXa5BQPaGaoidfbvoabroavb9ZZFJxHipoo
ngrokの準備はこれだけです。
Webサーバー
Webサーバーを準備する必要があります。root権限はないのでnode.jsで構築します。
main.js
const http = require("http");
const port = 3000;
const server = http.createServer((request, response) => {
response.writeHead(200, {
"Content-Type": "text/html"
});
const responseMessage = "<h1>Hello World</h1>";
response.end(responseMessage);
console.log(`Sent a response : ${responseMessage}`);
});
server.listen(port);
console.log(`The server has started and is listening on port number: ${port}`);
バックグラウンドで起動します。
node main.js &
外部公開
ngrokで外部公開します。
./ngrok http 3000

問題なく公開されています。

まとめ
あまり使うようとはないと思います。ちょっとしたTips的な使い方です。
セキュリティ的にもいろいろと常時起動はできないので仮想マシンの代わりにはなりません。
