A tool for creating a temporary Cloudflare tunnel allowing HTTP access to servers in private subnets.
The AWS Session Manager Plugin is required to connect to the EC2 instance.
Follow this link to install the plugin:
The target server needs to have the cloudflared
binary installed.
Add these commands to your launch template or user data:
# NOTE: Install wget if not already installed
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 \
-O /usr/local/bin/cloudflared
chmod +x /usr/local/bin/cloudflared
cloudflared --version
Run the target service on the EC2 as needed.
Use the cloudflare-tunnel.py
script to create a tunnel.
The script expects these parameters:
--tag
or-t
: The value of theName
tag on at least one running instance.--port
or-p
: The port to forward to tunnel to on the server's localhost. Default is8000
.--region
or-r
: The region to create the tunnel in. Default isus-east-1
.
For example:
python3 ./cloudflare-tunnel.py --tag backend-dev --port 3000
If the tunnel is created successfully, you will see output similar to the following:
2025-04-14T18:15:19Z INF +--------------------------------------------------------------------------------------------+
2025-04-14T18:15:19Z INF | Your quick Tunnel has been created! Visit it at (it may take some time to be reachable): |
2025-04-14T18:15:19Z INF | https://rocks-authorized-packages-employed.trycloudflare.com |
2025-04-14T18:15:19Z INF +--------------------------------------------------------------------------------------------+
You may need to wait a 1-2 minutes for the tunnel to be reachable.
Follow the link to access the tunnel.
If the tunnel fails to connect, type CTRL+C
to stop the script and run it again.