Routing Requests with Static and Configuration-Based Rules
This lesson covers static routing in application code and API Gateway, which maps each type of request to a model chosen in advance and becomes flexible when the mapping lives in configuration.
Learning outcomes
After completing this lesson, you will be able to:
- Keep routing tables in configuration.
- Route with API Gateway paths and stage variables.
- Recognize the limits of static routing.
Routing tables in configuration
Static routing uses a table that maps a request attribute, such as the endpoint, the use case name, the customer tier or the language, to a model ID and parameters. The application looks up the route and calls the model. Keeping the table in AWS AppConfig rather than in code allows validated, gradual changes with rollback, so moving "summarize" to a new model is a configuration deployment. Static routing works well when request types are explicit, such as different buttons in a user interface or different API operations.
The following diagram shows the routing table and who changes it.

Routing with API Gateway
Routing decides which model or back end handles a request. The simplest form, static routing, is decided by the request's address or by configuration, and Amazon API Gateway can perform it without custom code. Separate resources or paths, such as /summarize and /translate, integrate with different back ends. Stage variables select different back-end functions or models for each stage, such as a cheaper model in development.
In REST API integrations, mapping templates, written in Velocity Template Language (VTL), transform the client's request into the back end's format, for example inserting a model ID or reshaping fields, and can use values from the request to choose the target. Keeping simple routing logic at the edge in this way means back-end functions stay focused on their task and routing can change through configuration.
Static routing without code
Limits of static routing
Static routing works when the path or a field in the request already identifies the task, but it cannot adapt to the content of free-form requests. A chat endpoint, for example, receives both trivial questions that a small model could answer and complex ones that need the largest model, and static routing must send all of them to the same model, either wasting money or lowering quality.
Static routing also ignores live conditions, such as a model's current latency, error rate or throttling. These needs are met by content-based routing, which inspects each request, and metric-based routing, which reacts to the health of each model, described in the following topics. The following table summarises the static routing options.
| Mechanism | Changes via | Fits |
|---|---|---|
| Routing table in AppConfig | Configuration deployment | Explicit request types; safe changes |
| API Gateway resources and paths | API deployment | Different operations to different backends |
| API Gateway stage variables | Stage settings | Different models per environment |
| API Gateway mapping templates | API deployment | Request transformation and simple routing logic |
Tier-based routing
A SaaS product offers Basic and Enterprise tiers. Enterprise customers get a more capable model. Product managers want to change the model for each tier without developer involvement.
A routing table in AppConfig keyed by tier, read by the backend Lambda function, meets the need: product managers deploy configuration changes through AppConfig with validation and gradual rollout, and the code never changes.
Where can a routing table be kept so that it changes safely without a code deployment?
Show answer
In AWS AppConfig, which validates and deploys configuration changes gradually.
Exam Tips
Remember for the exam
- Explicit request types: static routing table.
- Keep routing tables in AppConfig for safe changes without code.
- API Gateway mapping templates transform requests and support simple routing.
- Free-form requests need content-based routing.