Serverless AI chatbot patterns for private company data on AWS

How to build an internal AI chatbot on AWS serverless services: streaming answers, sign-in, per-user document permissions, low idle cost and what to log.

Westerwick4 min read

Yellow fibre-optic patch cables plugged into rows of green connectors in a network cabinet
Photo: Albert Stoynov on Unsplash (Unsplash License)
On this page

An internal AI assistant that answers staff questions from company documents is one of the most common first AI projects. For most mid-sized organisations, usage is uneven: busy at 9am, quiet overnight and at weekends. That makes a serverless AI chatbot, where you pay per request rather than for servers running all day, a natural fit.

The architecture is well established. The details that decide whether it's safe to use are sign-in, document permissions and what gets logged.

The basic shape

A typical AWS setup has five parts:

  1. A web front end where staff sign in and chat.
  2. Sign-in through Amazon Cognito, or your existing Microsoft or Google identity.
  3. A small function (AWS Lambda) that checks who the user is and passes the question on.
  4. Amazon Bedrock Knowledge Bases, which searches your documents and has a language model write an answer with citations.
  5. Document storage in Amazon S3, with a vector index (a searchable store of document meanings) managed for you.

None of these run servers you manage, and most charge only when used. Our own Westerwick AI chat follows a similar pattern: it runs on Amazon Bedrock, streams answers as they're written, and stores no conversation content on our servers.

Streaming answers without a long wait

Language models write answers a few words at a time. Streaming shows those words as they arrive, instead of making the user wait for the whole answer.

AWS describes three serverless ways to do this1:

  • Lambda function URLs with response streaming: the simplest. But "Lambda URLs don't directly support Amazon Cognito user pool authorizers", so your code must check the user's sign-in token itself1.
  • API Gateway WebSockets: more setup, and "the API Gateway integration timeout is 29 s", so the function must respond promptly1.
  • AWS AppSync subscriptions: integrates with Cognito, which AWS calls "the most developer-friendly option for authentication"1.

Two operational details catch people out. Streamed responses "are not interrupted or stopped when the invoking client connection is broken", and "customers are billed for the full function duration"2, so set sensible time limits. And "Lambda function URLs do not support response streaming within a VPC environment"2, so if your design must run inside a private network, plan for a different route.

Permissions: the part that matters most

A company chatbot must not show an employee something they couldn't open themselves. If HR documents, board papers and customer contracts all go into one knowledge base, the chatbot needs to know who's asking.

The standard approach is metadata filtering. Each document is tagged, for example by department or sensitivity, and every search is filtered by what the signed-in user may see. AWS describes how this lets you "ensure that the retrieval only fetches and uses information that a particular user or application is authorized to access"3.

AWS is also clear about where responsibility sits: "developers must implement proper metadata filtering in their application code. Failure to enforce appropriate metadata-based filtering could result in unauthorized access to sensitive documents"4.

Bedrock's managed knowledge bases can read permissions from sources such as SharePoint and apply them to results. But AWS warns that this "provides ACL-aware filtering, not a security boundary", and that the service "does not authenticate end users"5. Permission changes are only "as fresh as the last sync" for most sources5. One point in its favour: if the permission check fails, it "fails closed", so documents aren't returned5.

Sign-in decides who's asking. Filters decide what they may see. The chatbot should never be the one deciding.

In practice, we recommend keeping truly restricted documents out of a general staff assistant altogether, rather than relying on filters alone.

Keeping idle costs low

The search index is often the part that costs money when nobody's using it. Amazon S3 Vectors, generally available since December 2025, "reduces the total costs to upload, store, and query vectors by up to 90%", lets you query "without provisioning any infrastructure", and works with Bedrock Knowledge Bases6. It's available in the Africa (Cape Town) Region7. For smaller document sets, you may not need a dedicated vector store at all, as we explain in when a vector database is overkill.

Logging without keeping what people asked

You need logs to know the chatbot is working: request counts, errors, response times and cost. You usually don't need the text of every question and answer. Staff will paste customer details, salary questions and personal matters into a chatbot, so storing conversation text creates a POPIA responsibility you may not want.

A sensible default is to log metadata, not content. If you must keep content, for quality review for example, set a short retention period and restrict who can read it.

Running it from South Africa

Organisations can use Bedrock from the Africa (Cape Town) Region through global cross-Region inference, where the model processing can happen in other AWS Regions. AWS notes that "Amazon CloudWatch and AWS CloudTrail logs are recorded in af-south-1", and advises customers to evaluate whether this approach fits their obligations, "including the Protection of Personal Information Act (POPIA)"8. Confirm the right setup with your privacy adviser.

What to do next

  1. List the document collections the chatbot will use, and who's allowed to see each one.
  2. Tag documents with access metadata before loading them, and enforce the filter in code on every query.
  3. Leave the most sensitive collections out of the first version.
  4. Decide what you'll log, and default to metadata rather than conversation text.
  5. Pilot with one department and its documents, then widen access once permissions have been tested. You can try a working example in our Ask demo.

See it on your own data first.

We stand up a working proof of concept on our AWS account. Real sample data, no cost to you, before you commit to a build.