← All lessons
AWS generative AI developer exam prep · Lesson 10 of 17

APIs and enterprise integration

Most apps reach a model through an API you own. Amazon API Gateway in front of Lambda gives you authentication, request validation, throttling and usage plans per client, before a single token is spent. Mind the timeout: REST APIs have a default integration timeout of 29 seconds (it can be raised for Regional and private REST APIs, sometimes at the cost of throttle quota), so a long generation should stream, or be made asynchronous.

For real-time feedback, stream. API Gateway WebSocket APIs keep a connection open so the backend can push tokens as Bedrock streams them; Lambda response streaming (through a function URL) and server-sent events are other ways. AWS AppSync can stream to clients over GraphQL subscriptions.

For work that doesn't need an instant answer, go asynchronous. The API accepts the request, puts it on an Amazon SQS queue and returns a job id; workers pull from the queue at a rate the model's quota can take, and the client polls or is notified (for example through Amazon SNS or a WebSocket). Queues also smooth bursts, so a spike doesn't turn into a wall of throttling errors.

Event-driven integration keeps systems loosely coupled. Amazon EventBridge routes events (a new support ticket, an uploaded contract, a CRM update) to the AI step that handles them, and from there to whoever needs the result; DynamoDB Streams can start work when a record changes. Existing systems don't need to know a model is involved.

Be resilient. When Bedrock returns ThrottlingException, retry with exponential backoff and jitter (the AWS SDK's retry modes do this) and stay within the account's tokens-per-minute and requests-per-minute quotas, or ask for an increase through Service Quotas. AWS X-Ray traces a request across API Gateway, Lambda and downstream calls to show where time goes.

Enterprises often build a central GenAI gateway: one internal API that every team calls, which picks the model, applies guardrails, logs usage per team, enforces quotas and hides provider changes. Ship it like any service, with AWS CodePipeline and AWS CodeBuild running tests, security scans and prompt evaluations before deploy, and rollback when checks fail. For data that must stay on premises or near users, AWS Outposts runs AWS infrastructure in your data center and AWS Wavelength puts compute at the edge of 5G networks. Amplify helps build front ends; Amazon Q Developer helps write and debug the code.

Practice

Users of an API Gateway REST API get 504 errors on long answers that take about 40 seconds to generate. What's the best fix for the user experience?

More info

Quick reference

API Gateway REST timeout29 s by default; can be raised for Regional and private REST APIs.
WebSocket APIKeeps a connection open to push streamed tokens.
SQSQueue to absorb bursts and process asynchronously.
EventBridgeRoutes events between loosely coupled systems.
ThrottlingExceptionRetry with exponential backoff and jitter; check quotas.
GenAI gatewayOne internal API for models, guardrails, logging and quotas.
Outposts / WavelengthAWS on premises / at the 5G edge.

Related courses