Swap Bedrock models without redeploying: AWS AppConfig + Lambda
How I switched the model behind a streaming Bedrock API in 19 seconds with AWS AppConfig, without redeploying Lambda.
- AWS
- AppConfig
- Bedrock
- Lambda
- Serverless
The problem: your model ID is a deploy
Confession time: for a while, every GenAI Lambda I wrote had its model ID hardcoded somewhere. An environment variable if I was feeling responsible, a string constant if it was Friday. Want to try Nova Micro instead of Nova 2 Lite for a cheaper route? That’s a code change, a pull request, a pipeline run, a deploy and a small prayer to the CI gods.
That’s a lot of ceremony for what is really a runtime decision. Models launch, get cheaper or quietly change every few months, and the knobs I actually turn most aren’t code at all.
There’s the model itself, because a new one shows up roughly every Tuesday. There’s the system prompt and settings like maxTokens and temperature, which I tweak more often than I’d like to admit. And there’s the kill switch, for the morning the Bedrock bill looks like a phone number.
So I built a small project, bedrock-config-router, to move those decisions out of the deployment and into AWS AppConfig. The punchline: I switched the model behind a live, streaming API in 19 seconds without deploying a single line of code. Not even a semicolon.
What the usual pitch gets wrong
You’ve probably seen the conference-slide version of this story: updating Lambda environment variables “causes downtime”, and AppConfig “pushes config instantly into memory”. It’s a great story. It’s also about as precise as a weather forecast, and the real benefits are better than the myth anyway.
Let’s start with the downtime. Changing environment variables doesn’t take your API offline: in-flight requests finish, and new requests land on fresh execution environments. You pay in cold starts, not in an outage.
The Lambda extension polls AppConfig and keeps its own cache in each execution environment. I set the poll interval to 15 seconds. In my test, the first response from the new model came 19 seconds after the AppConfig deployment finished. How the AppConfig Lambda extension polls.
So if it isn’t magic, why bother? Because config gets superpowers that code deploys don’t.
There’s a bouncer at the door: AppConfig checks every new version against a JSON Schema, so it can catch missing fields, out-of-range values and a model ID with the wrong prefix before rollout. There’s a paper trail too. Every change is a numbered version you can roll back to, and CloudTrail remembers who deployed it, even when you’d rather it didn’t.
You also get gradual rollout with automatic rollback. A deployment strategy can send new config to 10% of environments first and undo itself when a CloudWatch alarm fires. It’s a canary release, and no birds are harmed. A config change also leaves warm execution environments in place.
The architecture
There are two roads in this picture. Requests drive left to right along the top, and config takes the scenic route up from the bottom, never touching the function’s code.
A client signs each request with IAM credentials, because an open endpoint in front of a paid model is basically a donation button. API Gateway’s REST API streams the Lambda’s reply back token by token, a trick it only learned in late 2025. The Lambda carries the AppConfig extension as a layer: a tiny sidecar that fetches the config, keeps it in memory and serves it on localhost:2772. All of it fits in one CDK stack of about 100 lines.
The code: one JSON file, one schema, one handler
The whole runtime contract is one small JSON document, stored as an AppConfig hosted configuration. Five fields. I’ve written longer commit messages:
{
"enabled": true,
"modelId": "eu.amazon.nova-2-lite-v1:0",
"systemPrompt": "You are a concise, helpful assistant.",
"maxTokens": 1024,
"temperature": 0.5
}
A JSON Schema stands guard over it. AppConfig runs the schema on every new version, so a bad value is rejected before any function has to deal with it:
{
"type": "object",
"required": ["enabled", "modelId", "maxTokens"],
"additionalProperties": false,
"properties": {
"enabled": { "type": "boolean" },
"modelId": { "type": "string", "pattern": "^(eu|us|apac|global)\\.amazon\\.nova-" },
"systemPrompt": { "type": "string" },
"maxTokens": { "type": "integer", "minimum": 1, "maximum": 10000 },
"temperature": { "type": "number", "minimum": 0, "maximum": 1 }
}
}
Inside the handler, reading config is a plain fetch to localhost. The extension can serve the value from its local cache, which takes far less time than a meeting about changing an environment variable.
const CONFIG_URL = `http://localhost:2772/applications/${APP}/environments/${ENV}/configurations/model`;
const res = await fetch(CONFIG_URL);
const config = await res.json();
const version = res.headers.get('Configuration-Version');
The rest is a standard Bedrock ConverseStream call. Both Nova models in this demo support the same Converse interface, so swapping modelId needs no other code change.
const { stream } = await bedrock.send(new ConverseStreamCommand({
modelId: config.modelId,
system: config.systemPrompt ? [{ text: config.systemPrompt }] : undefined,
messages: [{ role: 'user', content: [{ text: prompt }] }],
inferenceConfig: { maxTokens: config.maxTokens, temperature: config.temperature },
}));
for await (const chunk of stream ?? []) {
const text = chunk.contentBlockDelta?.delta?.text;
if (text) out.write(text);
}
Successful responses carry x-model and x-config-version headers, and Powertools adds both values to the request logs. So when someone asks “which model said that?”, you can answer in seconds instead of opening a detective novel.
Demo: Nova 2 Lite to Nova Micro in 19 seconds
Time for the fun part. I changed one line in config/model.json, swapping eu.amazon.nova-2-lite-v1:0 for eu.amazon.nova-micro-v1:0, and pushed it to AppConfig:
bun run config:deploy
# Created config version 2
# 8 COMPLETE
The script creates a new config version and starts a deployment. That’s it. The Lambda isn’t rebuilt, redeployed or even told. Then I called the API every few seconds and watched the x-model header like a pot of water.
Four seconds in, Nova 2 Lite was still answering. Twelve seconds in, still Nova 2 Lite, and I started to doubt myself. At nineteen seconds the header flipped to eu.amazon.nova-micro-v1:0.
Same function, same code, a different model. Nineteen seconds is about how long it takes me to find my coffee mug, and a lot less than any pipeline I’ve ever waited on. Rolling back was the same command with the old file, which became config version 3.
The enabled field works the same way as a kill switch. Set it to false and the API answers 503 without calling Bedrock. It’s the big red button for when spend spikes and you’d like it to stop before your pipeline has even finished checking out the repo.
Things that bit me along the way
My 400s were wearing a 502 costume. With Lambda response streaming, you set the status code and headers with awslambda.HttpResponseStream.from(). My error path called .end(body) right after it, and API Gateway handed the client a 502 instead of my perfectly good 400. Writing the body first, then ending, fixed it:
const out = awslambda.HttpResponseStream.from(stream, { statusCode: 400, headers });
out.write(JSON.stringify({ error: 'Missing "prompt"' }));
out.end();
The kill switch follows the same polling schedule. Each execution environment can keep serving its current config until it refreshes. If you need to block new Lambda invocations while the flag propagates, you can set the function’s reserved concurrency to zero.
AppConfig deletion protection. It was enabled on my account, and it blocks deleting a configuration profile that was read in the last 60 minutes. It’s a lovely safety net, and a confusing one if you discover it mid-refactor. Wait out the window, or check aws appconfig get-account-settings first.
Orphaned config versions. Versions pushed by a script aren’t tracked by CloudFormation. When the stack later deletes that profile, those strays can block the delete. Tidy them up first, like a responsible adult, or at least a responsible script.
Signing requests without an SDK. The API uses IAM auth, and it turns out curl can sign requests itself with --aws-sigv4. So the test client is a short shell script instead of yet another package.json. One trap if you write it in zsh: $REGION:execute-api gets mangled, because zsh reads :e as a variable modifier. Write ${REGION}:execute-api and save yourself a long stare at signature errors.
Taking it to production
The repo is deliberately minimal, the “hello world” of config-driven GenAI. Its first version had more features, and these are the pieces worth adding back once real users, and real invoices, show up.
The first is gradual rollout with automatic rollback. Swap the immediate deployment strategy for a linear or canary one and attach CloudWatch alarms to the AppConfig environment, and a config change that spikes errors rolls itself back while you’re still reading the alert. The second is a fallback chain: make modelId a list, and if a model throttles before the first token, try the next one instead of apologising to your users.
Then there’s A/B testing. Give each route weighted variants and hash the user ID to pick one, so a given user always gets the same model and your experiment stays honest. Cost rules come next: cap maxTokens and send large prompts to a cheaper model above a size threshold. Your finance team might even send you a fruit basket.
Finally, compliance and flags. Check the destination regions for your Bedrock inference profiles against your data residency requirements, select the Bedrock Guardrail version through config, and consider AppConfig’s feature-flag profile for on/off switches.
Wrapping up
Which model you call is a runtime decision, so treat it like configuration. AppConfig gives that configuration validation, versioning and rollback, and the Lambda extension keeps a local copy for the handler. You change models in seconds, without a deploy, with a clear record of what changed and when. And you get to keep your Friday afternoons.
The code, about 240 lines of CDK, TypeScript and shell, is at github.com/tomassabol/bedrock-config-router. Fork it, break it, and tell me which model you end up switching to.