Change Your Bedrock Model Without a Deploy: Dynamic Routing with AWS AppConfig

Hardcoded model IDs turn every model change into a code deploy. I built a Lambda router that reads its model choices from AWS AppConfig, sends paying and free users to different Amazon Bedrock models, and uses Intelligent Prompt Routing to keep free users on a cheaper model. A JSON Schema validator blocks bad changes before they go live, and a CloudWatch alarm rolls back a bad change automatically. Includes a deployable sample.

Picture a support assistant inside a SaaS product. Free users ask it simple things: where's the export button, how do I reset my password. Paying customers ask harder questions about their own data, and they expect better answers. Every few months a new model comes out that's cheaper, or better, or both. And every time, someone changes one string in the code, opens a pull request, waits for review and the pipeline, and deploys, just to change which model answers.
The model choice is a business decision, and it changes more often than the code around it, so I moved it out of the code. I built a small router on Amazon Bedrock that reads its model choices from AWS AppConfig at runtime, and then tested what happens when a change goes wrong.
I wrote this for engineers who already know AWS Lambda, Amazon API Gateway, IAM and CloudFormation, and who have called a model on Amazon Bedrock at least once. I don't assume you've used AppConfig, so I explain its pieces as they come up. By the end, you'll know how to switch the model behind a live API in seconds, what stops a bad change from reaching users, and the two places where I got it wrong first.

How the router works

A user's request goes to API Gateway, then to a Lambda function. Before calling Bedrock, the function looks up a small JSON document of rules: which model each customer tier gets, with what settings. Changing a model means publishing a new version of that document. The code never changes.
The rules live in AWS AppConfig, a service for runtime settings. It does three things an environment variable can't. It checks a new version against rules I define before it can go live. It rolls it out gradually, to a growing share of the running Lambda instances. And it rolls it back by itself if an alarm fires during the rollout. An environment variable is simpler, but every change to one updates the function, there's no check, and everyone gets the change at once. For a value that decides what every user sees, that's the wrong trade.

Architecture: a client calls API Gateway, which invokes a Lambda router with the AppConfig Agent. The router calls Amazon Bedrock: Claude Sonnet 4.6 for premium, an Intelligent Prompt Router over Nova Lite and Nova Pro for standard, Nova Micro when the experiment flag is on. An operator deploys validated routing rules and flags through AppConfig, and an API 5XX alarm in CloudWatch triggers automatic rollback.
In my build, paying customers (the premium tier) get Claude Sonnet 4.6. Free users (the standard tier) get something more interesting, which is where the cost savings come from.

A prompt router for the free tier

For free users, I didn't want to choose one model. Most of their questions are easy, and a small model answers them well. A few are hard. Paying for a large model on every request wastes money; using a small one on every request gives bad answers on the hard ones.
Amazon Bedrock has a feature for exactly this: Intelligent Prompt Routing. A prompt router holds two models from the same family. One of them is the fallback, the model it uses by default. For each prompt, Bedrock predicts how well each model would answer, and only uses the other model when it's predicted to be better by more than a set threshold, the response quality difference.
The choice of fallback decides what the router is for. The default Nova router in Frankfurt falls back to Nova Pro, the stronger model, so it saves money only when it's confident the small model is good enough. I wanted the opposite for free users, so I built my own router that falls back to Nova Lite, the cheap one, and only escalates to Nova Pro when it's predicted to be at least 10% better.
Then I tested both with the same 10 prompts, from "Say hello" to a multi-step cost calculation. My router kept all 10 on Nova Lite. The default router sent 3 of 10 to Nova Pro, and its choices surprised me: it sent "What is the capital of Japan?" to the expensive model and kept a question about a Fibonacci algorithm on the cheap one. The router predicts answer quality, not how hard a question looks to a person. For a free tier, a router that almost never escalates is the point. For anything that matters, I'd test it with real prompts before trusting it.
The useful detail for the design is that a router has its own ARN, and Bedrock's Converse API accepts it anywhere a model ID goes. So for the function, the standard tier's "model" is just the router's ARN. The response tells me which model actually answered.

Validating the routing rules

The rules document is short:
{
"routes": {
"premium": { "modelId": "eu.anthropic.claude-sonnet-4-6", "temperature": 0.3, "maxTokens": 2048 },
"standard": { "modelId": "<prompt router ARN>", "temperature": 0.5, "maxTokens": 1024 },
"experiment": { "modelId": "eu.amazon.nova-micro-v1:0", "temperature": 0.5, "maxTokens": 1024 }
}
}
Changing this file changes the model for every user within seconds, and a typo would spread just as fast. A  temperature  of 5 instead of 0.5, or a model ID nobody approved, would go live just as fast.
So AppConfig checks every version against a JSON Schema, a standard format for describing what valid JSON looks like. Mine allows only five model IDs, keeps  temperature  between 0 and 1, caps  maxTokens  at 4,096, and rejects any key it doesn't know, so  maxToken  can't sneak through as a silent no-op:
"modelId": { "enum": ["eu.anthropic.claude-sonnet-4-6", "eu.amazon.nova-micro-v1:0",
"eu.amazon.nova-lite-v1:0", "eu.amazon.nova-pro-v1:0", "<prompt router ARN>"] },
"temperature": { "type": "number", "minimum": 0, "maximum": 1 },
"maxTokens": { "type": "integer", "minimum": 1, "maximum": 4096 }
The allow-list is also a cost control. Nobody can point free users at the most expensive model without changing the schema on purpose.
Two things caught me out. First, AppConfig only accepts draft 4 of JSON Schema for this. Most examples online use draft-07, and they fail. Second, and more important: I saved a version with  temperature: 5  to test the check, and AppConfig stored it. Validation doesn't run on save. It runs on deployment, or on request:

The validate-configuration command rejecting the invalid version: numeric instance is greater than the required maximum (maximum: 1, found: 5)
A bad version can sit in the store; it just can't reach production. If I kept these files in Git, I'd run that same check in the pipeline, so a bad file fails the build instead of the deployment. And the error message starts with "Could not build JSON schema from invalid input" and prints the whole schema before the real problem, at the very end. It reads like the schema is broken when it isn't.

Reading the rules from the AppConfig Agent

If the function asked AppConfig for the rules on every request, it would add a network call to each one, and under load it could hit AppConfig's request limits. Instead, it reads them from  localhost .
AWS publishes an AppConfig Agent that runs as a Lambda extension, a small process that runs next to the function code in the same execution environment. It fetches the rules when the function starts, keeps them in memory, and checks AppConfig for a new version in the background. My code just makes a local HTTP call to  localhost:2772 . Once the rules were cached, that call took 1.1 to 1.5 ms. The function never calls AppConfig itself, no matter how much traffic it gets. And if AppConfig is briefly unreachable, the agent keeps serving the last good version.
One edge case is worth knowing. Before the first deployment, there's nothing to fetch, so the agent returns HTTP 404 and only tries again 60 seconds later, not at the poll interval I set. A function that starts before the first deployment can take up to a minute to see it.

IAM for inference profiles and prompt routers

In Frankfurt, these models are only offered through cross-Region inference profiles: IDs like  eu.amazon.nova-lite-v1:0  that let Bedrock serve a request from any of several EU Regions, depending on capacity. The data stays in the EU and the price is Frankfurt's, but IAM checks the model in whichever Region actually serves the request. So the function's role has to allow the model in all of them, while still not allowing calls that bypass my profiles.
I wrote the policy that way: allow any foundation model, but only when the call comes through one of my four inference profiles. Premium requests worked. Every request through the prompt router failed:
AccessDeniedException: ... is not authorized to perform: bedrock:InvokeModel on resource:
arn:aws:bedrock:eu-west-3::foundation-model/amazon.nova-lite-v1:0
The router had picked Nova Lite, and the profile had sent it to Paris. But a call through a prompt router doesn't count as coming through the profile, even though the router's targets are those same profiles. I didn't find that in the documentation; I found it in this error. The fix is a second statement, keyed on the router instead:
- Effect: Allow
Action: bedrock:InvokeModel
Resource: !Sub "arn:${AWS::Partition}:bedrock:*::foundation-model/*"
Condition:
ArnEquals:
bedrock:PromptRouterArn: !GetAtt StandardTierRouter.PromptRouterArn
It keeps the same rule as before: the function can reach the models behind the router, but only through my router. After that, every tier returned 200. I had tested the premium route and stopped. Now I test every route before I trust a policy.

Switching the premium model under live traffic

To test a real switch, I moved paying customers from Sonnet to Nova Pro. I changed one value in the rules, published it as a new version and deployed it, while a script sent a premium request about every 11 seconds:
time http route model
16:19:32 200 premium eu.anthropic.claude-sonnet-4-6
16:19:43 200 premium eu.anthropic.claude-sonnet-4-6
16:19:54 200 premium eu.amazon.nova-pro-v1:0
16:20:05 200 premium eu.amazon.nova-pro-v1:0
The rollout reached 25% at 16:19:41. Thirteen seconds later, premium was on Nova Pro. All 54 requests returned 200. No code changed, nothing was redeployed, and the function wasn't restarted.
AppConfig doesn't switch everyone at once. It hands the new version to a growing share of Lambda instances at each step, so if the new model misbehaves, only part of the traffic sees it at first. My test script mostly hit one warm instance, which happened to be in the first quarter. I ran the rollout over 4 minutes, plus 2 minutes of watching at the end; that's short for a demo. For real traffic, AppConfig's slower predefined strategies take 20 to 30 minutes plus a watch period, which is a lot more time for something to go wrong in a small slice before it goes wrong for everyone.

Deployment history of the prod environment in the AWS AppConfig console: six completed deployments, including the model switch, the flag, and the revert to version 1

Rolling back a bad change automatically

The schema catches changes that are malformed. It can't catch one that's valid and still breaks things. For example, someone adds Claude Haiku 4.5 to the allow-list, points paying customers at it, and forgets to update the function's IAM role. The rules pass every check. Every premium request fails.
AppConfig's answer is to watch a CloudWatch alarm while it rolls out. When a Bedrock call fails, the function returns an error and API Gateway returns a 5XX, so I put one alarm on the API's 5XX count: three or more in a minute. I watched API Gateway rather than Bedrock's own error metric on purpose, because Bedrock doesn't count requests it rejects before processing them, and an IAM denial is one of those. The alarm has to see what users see.
Then I made that mistake on purpose, with a premium request every 5 seconds:
Time
What happened
17:14:57
Deployment of the broken rules started
17:18:06
First failed request, just after the 75% step
17:18:59
Rollout reached 100%, final watch period started
17:19:56
Alarm fired
17:19:59
AppConfig finished rolling back, on its own
17:20:21
First successful request again, back on Sonnet

The 5XX alarm in the CloudWatch console: the error count peaks at 11 per minute, crosses the threshold of 3, and the alarm goes from OK to In alarm and back to OK

The prod environment in the AWS AppConfig console after the rollback: the bad deployment and the environment state both show Rolled back
The alarm fired almost two minutes after the first error. That delay is normal: the alarm evaluates one-minute periods, and the metric arrives with a delay. By the time it fired, the rollout had already reached 100%. What saved it was the 2-minute watch period after 100%, which AppConfig calls the bake time. With a bake time of zero, the deployment would have been marked complete a minute before the alarm fired, and nothing would have rolled back. So the bake time has to be longer than the alarm needs to notice a problem.
One CloudFormation detail tripped me up here. My first alarm watched the function's own error count and referenced the function by name. But the function's settings reference the AppConfig environment, and the environment references the alarm. That's a circle, and CloudFormation refuses to create it. Watching the API instead, with its name written out, broke the circle and turned out to be the better signal anyway.

Results

Changing which model answers is now a config deployment: checked before it ships, rolled out to a slice of traffic first, and undone automatically if errors spike. In my tests, the switch reached requests 13 seconds after their turn, reading the rules cost about a millisecond, and a broken change was rolled back 3 seconds after the alarm noticed it. Free users go through a router that keeps them on the cheap model unless a stronger one is clearly worth it.
If I built it again, I'd start with the two things that bit me: test every route against the IAM policy, not just the first one, and size the bake time to the alarm before the first real deployment, not after.
The CloudFormation template, the router code and the scripts I used for these tests are on GitHub:  https://github.com/mdotsalman/bedrock-appconfig-model-routing 
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article