Lesson 1 of 4 Model Routing and Cascading

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.

Tier-based routing from configuration. A routing table in AWS AppConfig maps each customer tier to a model; product managers deploy changes through AppConfig with validation and gradual rollout, and the backend Lambda function reads the table, so the code never changes.
The model assignments are illustrative.

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.

Scenario questions

Static routing without code

Exam skills 2.4.4

Choose how to implement each static routing requirement.

Log in to try this activity Interactive activities are free with an account.

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.

MechanismChanges viaFits
Routing table in AppConfigConfiguration deploymentExplicit request types; safe changes
API Gateway resources and pathsAPI deploymentDifferent operations to different backends
API Gateway stage variablesStage settingsDifferent models per environment
API Gateway mapping templatesAPI deploymentRequest transformation and simple routing logic
Worked example

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.

Check yourself

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.