← All insights

A captive portal for UniFi guest Wi-Fi: serverless, with a tiny redirector as the bridge

UniFi only accepts an IPv4 address as its external portal server, and CloudFront has no static IP. A stateless micro-redirector in front of a serverless backend closes the gap – a pattern for any vendor constraint of this kind.

For the open guest Wi-Fi at one of my sites I wanted my own sign-in page: accept the terms of use, get the device authorised, done. The network runs on UniFi. The case is small, but the pattern comes up with clients all the time: a vendor product imposes a condition that doesn’t fit the architecture, and you need the thinnest possible bridge. A use case, not a showcase.

Hypothesis

A captive portal for UniFi can run almost entirely serverless – static page, API, function, counter table – without a stateful server to look after. The one obstacle I knew about up front: in the “External Portal Server” field, UniFi accepts nothing but an IPv4 address. A CDN like CloudFront has no static IP. My assumption was that a tiny, stateless redirector with a fixed address would close that gap and have nothing else to do.

Three questions: Does the redirect chain from UniFi to the page work? Does the backend reach the gateway through the vendor’s cloud connector? And does the non-serverless part stay low-maintenance?

Setup

The flow has four stops:

  1. UniFi intercepts the first HTTP request from a guest who isn’t authorised yet and forwards it to the configured IPv4 address with the device identifier and target URL as query parameters.
  2. The redirector – an ARM micro instance (t4g.nano) running nginx with a fixed public address – answers every request with a 302 to the HTTPS portal page and passes the query string through unchanged.
  3. The portal page is a static site in S3 behind CloudFront. API calls go through the same origin to an HTTP API gateway and on to a Lambda function.
  4. The Lambda function talks to the gateway via the UniFi Site Manager cloud connector: it checks whether the device is currently connected as a guest on the hotspot network and, once the terms are accepted, authorises it.

A few deliberate choices:

Everything, including certificate and redirector, is CDK code. Only the cloud-connector API key (in a secret) and the UniFi hotspot settings live outside it.

Measurement

I didn’t run a load test – for guest Wi-Fi it would say little. I checked the functional chain and the pitfalls:

Two lessons learned:

On cost: most of the running cost is the micro instance and its public IPv4 address, each in the range of a few dollars a month. The serverless part is negligible at guest-traffic volumes. The redirector runs around the clock – stop it at night and guests get no sign-in page.

Conclusion

Hypothesis confirmed, with one caveat: it can’t be done entirely without a server, because the vendor insists on a fixed IPv4. But that server is reduced to the bare minimum – one redirect, no state, no data, replaceable at any time. The logic stays serverless, versioned and testable.

The pattern carries beyond Wi-Fi: when a legacy system, device or partner only accepts a fixed IP, only HTTP or one particular format, a thin, stateless adapter at exactly that point beats bending the whole architecture around the constraint. For this case I’m sticking with the micro instance: it patches itself, and any configuration change simply replaces it.

Stack: AWS CDK · CloudFront · S3 · API Gateway · Lambda · DynamoDB · EC2 · nginx · UniFi

← All insights