Building a Serverless Dungeon Master Agent on AWS
A build log for an AI Dungeon Master that runs a persistent tabletop RPG on fully serverless AWS. Bedrock Agents does the storytelling, Lambda action groups handle the game mechanics, DynamoDB holds the memory, and CDK wires it all up for about $1-5 a month.
I wanted a Dungeon Master that remembers my character between sessions, improvises encounters, and doesn't cost anything when nobody's playing. This is the write-up of that proof of concept. It's a fully serverless AI DM where Amazon Bedrock Agents does the reasoning and storytelling, Lambda action groups handle the actual game mechanics, and DynamoDB is the long-term memory. Everything is defined in CDK, and because it's all pay-per-request it runs for roughly $1-5 a month.
The architecture is five services. API Gateway exposes the REST endpoint. A session-proxy Lambda invokes the Bedrock Agent and streams its chunked response back with CORS headers attached. The agent calls a second "game actions" Lambda through defined functions (get_character, save_character, append_log) that read and write player state. DynamoDB stores that state under a composite key of playerId plus sessionId, so one player can have several campaigns going. A static web client lives in S3. Player input flows from API Gateway to the session proxy, into the Bedrock Agent, out to the game actions Lambda, down to DynamoDB, and back.
Key takeaways
- The model is stateless, so the architecture is the memory: DynamoDB with a playerId/sessionId composite key, plus if_not_exists and conditional expressions
- Action groups are where an agent stops being a chatbot: get_character, save_character, append_log let the DM change state, not just narrate
- The friction is all plumbing: per-account Bedrock model access, region-limited config, 3s default timeout (bump to 60), CORS at two layers, inconsistent action-parameter keys (normalize first)
Who this is for
Developers building LLM agents that need to take real actions and hold state across many turns, using D&D as a concrete low-stakes version of that problem. It assumes intermediate AWS (Lambda, IAM, DynamoDB, CDK v2, Node 20+) and no tabletop experience. The post also sketches a migration path to Bedrock AgentCore for anything headed toward production.
The full write-up, with the CDK stack, the architecture diagram, and the Lambda code, is on DEV.to.