No Anonymous API? No Problem: Inside a Pooled-Identity Architecture for Embedding QuickSight Chat Agents
QuickSight's chat agent has no anonymous embedding API, yet public websites need no-login chat. A component-by-component walkthrough of a pooled-identity architecture: an embeddable widget, a lease-managing pool client, Lambda coordination, an atomic DynamoDB ledger, and a scheduled reaper.
The Problem: A Chat Agent That Requires Identity, on a Site That Has None
You want to put an AI chat agent on your public website. Visitors should be able to ask questions about your data without creating an account. Simple ask, right?
Except Amazon QuickSight's chat agent (QuickChat) has no anonymous embedding API. The
GenerateEmbedUrlForAnonymousUser call supports dashboards, visuals, and Q&A search bars — but not chat agents. Every chat session must belong to a registered, licensed user.So you're stuck: the product you want to expose publicly requires identity infrastructure that's inherently private.
The solution is a pooled-identity architecture — a small pool of pre-registered synthetic users that anonymous visitors transparently borrow, one lease at a time, and return when they leave. This post walks through how the system works, component by component, and the design decisions that make it safe under concurrent load.
The System at a Glance
Any website installs the widget with one function call:
import { initQuickChatWidget } from '@quick-embed/chat-widget';
initQuickChatWidget({ apiBaseUrl: 'https://your-api.execute-api.us-east-1.amazonaws.com', theme: { primaryColor: '#106E9C', title: 'Ask the Assistant' },});Behind that single call, seven components work together:
Your Website Your AWS Account+---------------------------+ +----------------------------------+| Widget (Shadow DOM) | HTTPS | API Gateway (HTTP API) || Pool Client (lease mgmt) |--fetch--->| -> Chat Handler Lambda || QuickSight iframe | | -> DynamoDB (pool ledger) || |<-embed----| -> QuickSight (mint URL) |+---------------------------+ | EventBridge -> Reaper Lambda | +----------------------------------+The visitor sees a chat bubble. They click it. They talk to an AI agent. They never log in. They never know they're borrowing an identity.
One Visitor's Journey
Before diving into each component, here's the full flow for a single visitor:
- Page loads. The widget injects a floating bubble into the page. Nothing has touched AWS yet — zero cost so far.
- The visitor clicks the bubble. The pool client sends
GET /api/embed/chat. The browser attaches anOriginheader that JavaScript cannot forge.
- The gateway checks the guest list. CORS allowlist, then throttling, then forward to Lambda.
- The Lambda leases an identity. It re-validates the origin, then asks DynamoDB for an identity with spare capacity. An atomic write adds the visitor's lease.
- The Lambda mints an embed URL. QuickSight returns a single-use URL locked to the visitor's exact page origin, valid for 5 minutes, opening a 15-minute session.
- The chat renders. The widget hands the URL to the QuickSight embedding SDK, which creates the iframe. The visitor starts asking questions.
- Heartbeats keep the lease alive. Every 60 seconds the pool client pings the backend.
- The visitor leaves. Politely (tab close triggers a checkin beacon) or impolitely (laptop lid closes, heartbeats just stop — the reaper reclaims the lease 5 minutes later).
Now, the components that make each step work.
Component 1: The Widget
Runs in: the visitor's browser, inside your page
A self-isolating UI shell built on two browser primitives:
- Closed Shadow DOM. All widget UI lives inside
attachShadow({ mode: 'closed' }). The host site's CSS can't leak in and restyle it; the host site's JS can't query into it — evenelement.shadowRootreturnsnull.
- Maximum z-index on a fixed host. One
<div>withposition: fixedand z-index2147483647guarantees the bubble floats above everything, regardless of the host page's own stacking games.
The widget deliberately hosts nothing. There is no CDN, no
widget.js to serve — it ships inside the site's own JS bundle. A hasStarted flag ensures closing and reopening the panel resumes the same conversation instead of leasing a second identity.Component 2: The Pool Client
Runs in: the visitor's browser
The honest borrower. It manages the lease lifecycle with four operations:
- Checkout — Panel opens, calls
GET /api/embed/chat
- Heartbeat — Every 60s,
POST /api/embed/heartbeat
- Idle release — 5 min with no interaction, automatic checkin
- Checkin — Tab close or idle, via
navigator.sendBeacon
Two mechanisms here are worth understanding:
The tab-close problem. When a visitor closes the tab, normal
fetch() calls die mid-flight. navigator.sendBeacon() is designed for exactly this — "fire this small request even though the page is dying." One catch: sendBeacon always sends credentials, so the backend must set Access-Control-Allow-Credentials: true or the browser silently drops the beacon.The chatting-visitor problem. Idle detection listens for pointer and keyboard events on the host page — but a visitor typing inside the chat iframe generates none of those (it's a genuine cross-origin frame). Without a fix, a visitor mid-conversation would be disconnected after 5 minutes. The solution: every heartbeat checks "is the panel open and the tab visible?" — if yes, that counts as activity. Idle can only fire once the panel is closed or the tab is backgrounded.
Component 3: API Gateway
Runs in: AWS, fully managed
The front door. There's deliberately no CloudFront/CDN in front — the API Gateway URL is the public entry point the widget calls directly. Its two jobs:
- CORS allowlist. Built from the operator's
ALLOWED_EMBED_ORIGINSconfig. A browser on a non-approved site refuses to even send the real request after preflight.
- Throttling. 200 req/s steady-state, burst 400, at the stage level. (Per-IP limiting would require AWS WAF, which doesn't support HTTP APIs — a documented trade-off of the cheaper, faster HTTP API type.)
Four routes — checkout, heartbeat, checkin, health — all feed one Lambda.
Component 4: The Chat Handler Lambda
Runs in: AWS Lambda (Node.js 24, 256 MB)
The coordinator of each request. For a checkout:
- Validate the
Originheader against the allowlist — again. API Gateway already checked via CORS, but non-browser callers ignore CORS entirely, so the Lambda re-checks at the app layer. Two independent gates.
- Lease an identity from DynamoDB — find one with spare capacity.
- Mint an embed URL via
GenerateEmbedUrlForRegisteredUser, passing the validated origin asAllowedDomains. The same string that passed the CORS check locks the minted URL to the exact page that requested it — a stolen URL is useless anywhere else.
- Return
{ embedUrl, agentId, leaseId }.
If the mint fails, the Lambda immediately releases the lease — a compensating action that prevents capacity leaks on errors. And because QuickSight throttles this API aggressively at the account level, the mint retries with exponential backoff (250ms doubling up to 4s, five attempts). The Lambda timeout is 28 seconds — one second under API Gateway's hard 29-second ceiling — to give that backoff chain maximum room under burst traffic.
Component 5: The DynamoDB Pool
Storage: one table, one row per pool identity
This is where the real engineering lives. Hundreds of Lambda invocations may race simultaneously for 10 identities, and Lambda holds no state — so the database itself must enforce the rules, via atomic conditional writes:
Checkout: SET leases.<id> = now IF cooldownUntil <= now AND size(leases) < max
Checkin (last lease): REMOVE leases.<id> AND SET cooldownUntil = now + 15min IF size(leases) = 1 -- one atomic writeDynamoDB serializes conditional writes on a single item, so exactly as many checkouts succeed as there is capacity — the rest fall through to the next identity. Three design choices make the pool work:
Bin-packing. Checkout tries identities in fixed order: identity 1 fills to its cap (15 concurrent visitors) before identity 2 gets any. Why? An identity can only be recycled when completely empty. Packing visitors together keeps more identities fully drained and available.
The leaseId encodes its identity. A leaseId is
base64url(arn) + "." + UUID . Heartbeat and checkin can find the right row from the leaseId alone — no index lookup, no trusting the browser to send the ARN.Cooldown in the same write. When the last visitor leaves an identity, removing the lease and starting the 15-minute cooldown happen in one atomic write. If they were two writes and the process crashed between them, the identity would be instantly reusable — defeating the guarantee that successive borrowers never share a live QuickSight session. The cooldown equals the session lifetime precisely because there is no force-logout API: by the time an identity is re-leased, its previous session has provably expired.
Component 6: The Reaper
Trigger: EventBridge schedule, every 1 minute
A visitor whose laptop died never sends a checkin. On a traditional server you'd run
setInterval(reap, 30000) — but Lambda has no persistent process to run a timer in. So idle reclaim is a separate scheduled Lambda: every minute, it scans the pool table (10 rows — cheap) and releases any lease with no heartbeat in 5+ minutes, using the exact same checkin logic a live browser would. A reaped lease is indistinguishable from a polite one.Least-privilege detail: the reaper has no QuickSight permissions at all. It can only read and write the pool table. If it were ever compromised, it could free leases early — nothing more.
Component 7: QuickSight
Provisioned: once, before first deploy
The actual intelligence. Everything else is plumbing around one constraint: every chat session needs a registered user. So the pool is 10 pre-registered
READER_PRO identities (the minimum license tier with AI chat agents), held in a group, with synthetic email addresses no human ever logs in with.The part that trips up every first deployment: sharing does not cascade. Four layers must each be shared with the pool group independently:
- The agent itself — miss it and you get
401 Authorization denied by resource policy
- The agent's space — miss it and you get
ACCESS_DENIEDfetching the space
- The datasets/topics it queries — miss them and the agent chats happily but can't answer data questions
- The domain embedding it — miss it and the iframe renders blank
Each missing layer fails at a different stage with a different error, which makes under-provisioning genuinely confusing to debug.
Private mode isolates the strangers. Up to 15 visitors share one identity concurrently. Sessions run with private mode on and chat history hidden, so visitor A never sees visitor B's conversation, and nothing persists to the shared identity's history.
Why the Deployment Order Is Rigid
The stages have hard dependencies — each produces a required input for the next:
- Provision the pool — creates the QuickSight users, outputs their ARNs
- Configure — the ARNs go into the environment config
- Deploy the backend — the ARNs are baked into the Lambda's env vars AND its IAM policy
- Embed the widget — uses the API URL that the deploy outputs
Provision-first is non-negotiable for three reasons: the CDK stack hard-fails at synth time without the ARNs; the ARNs shape the IAM policy itself (the Lambda may mint embed URLs only for those exact synthetic users — least privilege, no wildcards); and placeholder ARNs deploy fine but break at runtime when QuickSight rejects the unknown user.
Defense in Depth: How the Layers Compose
Each security gate assumes the one before it might be bypassed:
- Browser CORS stops a malicious website from embedding your widget — the visitor's own browser refuses the call
- Gateway throttling stops runaway callers from exhausting Lambda and QuickSight
- App-layer origin re-check stops non-browser callers (curl ignores CORS; the Lambda checks
Originagain)
- AllowedDomains on every minted URL stops a stolen embed URL — it only renders inside the exact origin that requested it
- Single-use, 5-minute-expiry URLs stop replay of an intercepted URL
- Conditional writes + cooldown stop capacity over-commitment and session overlap between successive borrowers
- Least-privilege IAM bounds the blast radius — the chat Lambda can mint only for the 10 pool ARNs; the reaper can't mint at all
The interesting case: a non-browser client can forge any
Origin header it likes and obtain an embed URL. What stops that mattering is the next layer — the URL only works inside an iframe hosted on the allowlisted origin, which the attacker doesn't control.Results
- 150 concurrent-visitor capacity from 10 identities x 15 visitors each (verified at 100 concurrent checkouts with zero failures)
- Sub-second checkout including the DynamoDB conditional write and QuickSight mint
- Zero visitor-visible state — no login, no cookies, no local storage
- One function call to embed — no CDN, no iframe hosting
Honest Limitations
- Shared identities. The pool shares registered identities across strangers. Private mode and cooldown isolate them, but it's an accepted trade-off, not a zero-risk design.
- No per-IP rate limiting. AWS WAFv2 doesn't support HTTP APIs; stage-level throttling is the available substitute.
- QuickSight theming. The chat frame's colors, fonts, and greeting are fixed by the embedding SDK — only the bubble and header are themeable.
- Sharing doesn't cascade. Agent, space, and datasets must each be shared independently.
Key Takeaways
- The API gap is the real constraint, not the technology. QuickSight's chat agent is fully capable of embedded use — the missing anonymous path is a product surface gap. The pool is a workaround that should eventually be unnecessary.
- Atomic conditional writes replace locks. DynamoDB's condition expressions let hundreds of concurrent Lambda invocations race safely against a shared pool with no distributed locking. The database enforces the invariants, not the application code.
- Design for the impolite exit. Most of the pool's machinery — heartbeats, the reaper, TTL garbage collection — exists for visitors who vanish rather than leave politely. The polite path is easy; the crashed-laptop path is the design.
- Separation of concerns scales down. The widget doesn't know about DynamoDB. The reaper doesn't know about QuickSight. The Lambda holds no state. Seven components, each with one job and a clear interface.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article