# Adapter Pattern

The Adapter Pattern translates a provider-specific interface into a stable application interface so implementations can change without changing calling code.

Cloud concept. Updated 2026-10-29. Page: https://blowstack.com/tools/cloud-concepts-hub/adapter-pattern

> An adapter isolates differences in request formats, authentication, responses, and errors behind a consistent contract. In generative AI architectures, adapters let applications use different foundation models while configuration controls which supported model or provider handles a request.

Practice exams covering Adapter Pattern: [AIP-C01 AWS Certified Generative AI Developer - Professional](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional), [SAP-C03 AWS Certified Solutions Architect - Professional](https://blowstack.com/practice-exams/aws-certified-solutions-architect-professional).

## 6 key aspects of Adapter Pattern

Adapters isolate interface differences behind a stable contract, while configuration, capability checks, and routing policies enable controlled model switching.

1. **Stable application contract**: Define requests, responses, streaming events, and errors independently of a provider SDK. Business logic depends on this contract rather than on individual model APIs.
2. **Provider-specific translation**: Keep request mapping, authentication integration, response conversion, and error normalization inside each adapter. Preserve useful diagnostic metadata without forcing callers to understand provider-specific schemas.
3. **Configuration-driven selection**: Resolve logical model names to deployed adapters and model identifiers through validated runtime configuration. Switching among supported targets does not require changing application code, although a new provider integration may require a new adapter.
4. **Explicit capability boundaries**: Check context limits, tool support, modalities, and output requirements before invoking a model. A shared interface must not imply that every provider supports identical behavior.
5. **Separation of translation and policy**: Let routing policy choose the target while adapters handle interface differences. Enforce approved providers, regions, and data-handling rules on both primary and fallback routes.
6. **Compatibility testing and observability**: Use contract tests to verify adapter behavior and evaluations to measure model suitability. Track model identity, configuration version, errors, latency, and usage so configuration changes can be assessed and rolled back.

## Cloud services for Adapter Pattern

API Gateway exposes a stable application endpoint, while Lambda runs routing and provider-specific adapters. AppConfig supplies validated mappings from logical model names to approved targets, allowing supported models to change without modifying callers. Adapters can invoke Bedrock through its common conversational APIs or translate requests for external providers, retrieving external credentials from Secrets Manager when needed. Configuration controls selection, but adapter code remains responsible for translation and capability enforcement. Together, these services support controlled switching when permissions, model access, compliance checks, configuration refresh, and compatibility tests are implemented explicitly.

- **[AWS Lambda](https://blowstack.com/tools/cloud-services-hub/aws-lambda)**: Lambda can host provider adapters and routing logic behind a shared application interface. Keep provider SDK calls inside adapters, and evaluate execution duration, concurrency, payload, and streaming requirements before choosing the integration.
- **[AWS AppConfig](https://blowstack.com/tools/cloud-services-hub/aws-appconfig)**: AppConfig can distribute validated configuration that maps logical model names to approved adapters, providers, and model identifiers. Its deployment controls support gradual changes and alarm-driven rollback; application logic must retrieve and apply configuration updates.
- **[Amazon API Gateway](https://blowstack.com/tools/cloud-services-hub/amazon-api-gateway)**: API Gateway provides a stable API endpoint in front of adapter implementations and supports controls such as authorization and throttling. Simple mapping transformations can handle limited schema differences, but complex provider translation and model-selection policy generally belong in application logic.
- **[Amazon Bedrock](https://blowstack.com/tools/cloud-services-hub/amazon-bedrock)**: The Bedrock Converse and ConverseStream APIs provide common conversational interfaces across supported models, reducing adapter complexity. Adapters may still be needed to unify Bedrock with other providers or to handle model-specific options and capability differences.
- **[AWS Secrets Manager](https://blowstack.com/tools/cloud-services-hub/aws-secrets-manager)**: Secrets Manager can store credentials required by external model providers so adapters do not embed API keys in code or routing configuration. Grant each adapter access only to the secrets it requires and handle credential rotation appropriately.

## Adapter Pattern exam questions

Real practice exam questions on Adapter Pattern, with the correct answer and its explanation.

### Question 1 (SAP-C03)

**Question:**

A records-management company is modernizing access to an on-premises document archive. An Amazon API Gateway REST API already has working private HTTP connectivity to the archive. The archive application cannot be modified.

New clients send POST requests to /documents/{documentId}?office=code. The archive expects requests to /records/{id}, with the office code in the X-Office-Code HTTP header instead of a query string. The JSON request body contains a digitally signed document and must pass through unchanged. For successful responses, API Gateway must expose the archive's X-Archive-Version header as X-Document-Version and add Access-Control-Allow-Origin with the static value https://portal.example.com. Response bodies must also remain unchanged. CORS preflight handling is already configured.

The company wants to implement the stable client-facing contract without introducing custom compute or payload transformation templates. Which solution meets these requirements?

**Correct answer:** Use an HTTP non-proxy integration. Map the document ID to the integration path and the office query parameter to X-Office-Code, without forwarding the office query parameter. Declare the required method response headers and use integration response parameter mappings to copy X-Archive-Version to X-Document-Version and set the static CORS value. Configure request and response body passthrough without mapping templates.

**Explanation:** REST API parameter mapping can adapt integration request paths, query strings, and headers without modifying the request payload. A non-proxy integration also supports integration response parameter mappings, allowing the backend header to be renamed and a static CORS header to be supplied. Body passthrough preserves the request and response payloads without custom compute or payload templates.

### Question 2 (AIP-C01)

**Question:**

A company operates a streaming text-generation service backed by AWS Lambda. An existing router refreshes AWS AppConfig at runtime to select between two approved foundation model providers. Both provider integrations are deployed, but their streaming output differs:

• Provider A emits newly generated text in each content event.
• Provider B emits the complete text generated so far in each content event. Each successive text value extends the previous value without revisions.
• Both providers interleave non-content events and report final token usage differently.

Clients use an append-only renderer and require a stable stream containing text-delta events followed by exactly one completion event with normalized token usage. Generated text must reach clients incrementally, before inference finishes. After a one-time integration update, operators must be able to switch providers through the existing configuration without changing clients or redeploying code.

Which implementation meets these requirements?

**Correct answer:** Introduce provider-specific stream translators behind a shared streaming interface. For each invocation, forward Provider A's text deltas, derive only the newly added suffix from Provider B's cumulative text, handle non-content events, and translate terminal usage into one completion event.

**Explanation:** This applies an adapter at the streaming boundary. Invocation-scoped state allows Provider B's cumulative snapshots to become append-only deltas without buffering the complete generation. Each translator also handles its provider's event lifecycle and usage format. The existing configuration-driven router can then switch between the deployed integrations without changing clients or code.

## Practice Adapter Pattern in a full exam

Questions on Adapter Pattern in each practice exam, with every answer option and an explanation for each:

- [AIP-C01](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional): 5 questions
- [SAP-C03](https://blowstack.com/practice-exams/aws-certified-solutions-architect-professional): 4 questions

## What is Adapter Pattern

The Adapter Pattern is a structural design pattern that makes an existing interface usable through the interface an application expects. The application calls a stable contract, and an adapter translates that call into the operations required by a particular implementation. In cloud systems, adapters commonly sit between business logic and external APIs, storage systems, payment providers, or foundation model endpoints. The objective is to contain integration differences rather than spread provider-specific conditions throughout application code.

For foundation model integration, define an application-facing contract containing messages, generation settings, tool definitions, and an explicit response format. Each provider adapter maps supported fields into the provider's request schema and converts its response into a common result. That result might contain generated content, normalized completion status, usage information, and provider metadata. Streaming requires its own contract for incremental content, tool-call events, completion, and errors; a synchronous response wrapper does not automatically provide streaming compatibility.

A practical architecture exposes a stable endpoint through Amazon API Gateway and invokes adapter logic hosted in AWS Lambda. A routing component reads AWS AppConfig configuration that maps a logical model name, such as support-assistant, to an approved provider, model identifier, and adapter. The application continues calling the same endpoint while operators change the configuration. Configuration can also express approved fallback targets or rollout settings. Adapters perform interface translation; routing or strategy logic decides which adapter to invoke. These responsibilities are related but distinct.

Switching without code modifications is possible when the target provider and capabilities are already supported by deployed adapters. Adding an incompatible provider generally requires implementing and deploying another adapter, but the calling application can remain unchanged. Configuration updates also need validation, controlled rollout, and monitoring. Applications must retrieve refreshed configuration rather than load it permanently at startup, and operators should account for caching and deployment propagation time.

A common misconception is that a uniform API makes models interchangeable. Models differ in context limits, tokenization, tool support, structured output behavior, safety controls, and response quality. Validate required capabilities before routing and reject unsupported options rather than silently discarding them. Amazon Bedrock Converse provides a common interface across supported models, reducing translation work, but model-specific capabilities and parameters still require explicit handling.

Adapters introduce maintenance work and can hide useful provider features if the shared contract is too restrictive. Use a small stable core with explicit capability checks and carefully controlled extensions. Normalize errors while retaining diagnostic details, apply bounded retries only to suitable failures, and recognize that retries can incur additional inference charges. Automatic fallback must respect data residency, authorization, and approved-provider policies rather than send sensitive prompts to any available endpoint. Record the selected model, configuration version, latency, usage, and outcome without unnecessarily logging sensitive prompts. Contract tests and model evaluations should verify both interface compatibility and task quality before a routing change reaches production.

## Learn Adapter Pattern in lessons

3 short lessons on Adapter Pattern in 2 certification courses.

- SAP-C03: Adapter Pattern: translating legacy interfaces (Premium), https://app.blowstack.com/lessons/adapter-pattern-translating-legacy-interfaces-sap-c03
- AIP-C01: Adapter Pattern: provider-independent model contracts (Premium), https://app.blowstack.com/lessons/adapter-pattern-provider-independent-model-contracts-aip-c01
- AIP-C01: Adapter Pattern vs Strategy Pattern: translation versus selection (Premium), https://app.blowstack.com/lessons/adapter-pattern-vs-strategy-pattern-translation-versus-selection-aip-c01
