Consuming and Publishing Data Through APIs
This lesson explains how pipelines consume data from APIs, such as SaaS and partner services, and publish data through APIs so applications can use it without direct database access, handling pagination, rate limits and credentials.
Learning outcomes
After completing this lesson, you will be able to:
- Consume a REST API with pagination, rate limiting and secure credentials.
- Publish data through Amazon API Gateway with a suitable back end.
- Version and maintain data APIs.
Consuming data APIs
Reading from a REST API differs from reading a file: results arrive in pages, the provider enforces rate limits, and requests need credentials. A reliable consumer follows the pagination token (such as NextToken or a cursor) until the last page, retries throttled requests (HTTP 429) with exponential backoff and jitter, reads API keys or OAuth credentials from Secrets Manager, and records the last timestamp or cursor it read so the next run fetches only new data.
AWS offers several ways to run such a consumer. For supported SaaS applications, Amazon AppFlow handles authentication, pagination and incremental transfer with no code. For other APIs, a Lambda function on an EventBridge Scheduler schedule suits small, quick calls; a Glue Python shell job suits longer extracts; and Step Functions can call HTTPS endpoints directly with its HTTP task, using an EventBridge connection to hold the credentials. AWS's own APIs are called through the SDKs, whose paginators and built-in retries handle most of this automatically. The following table summarises the options.
| Source | Consumer |
|---|---|
| Supported SaaS applications (Salesforce, ServiceNow, SAP) | Amazon AppFlow, with no code |
| Small, frequent calls to a REST API | Lambda on an EventBridge Scheduler schedule |
| Long-running extracts | Glue Python shell job or a container on ECS or AWS Batch |
| API calls as steps in a workflow | Step Functions HTTP task with an EventBridge connection |
| AWS service APIs | AWS SDKs, using paginators and built-in retries |
Consuming APIs
Creating data APIs
To publish data, a pipeline exposes an API instead of sharing database credentials. The usual front door is Amazon API Gateway, which provides authentication (IAM, Cognito or Lambda authorizers), throttling and usage plans with API keys, request validation and, for REST APIs, a response cache. Behind it, a Lambda function reads from the appropriate store: DynamoDB for single-digit millisecond lookups by key, Aurora or RDS through RDS Proxy or the RDS Data API, or a precomputed table for aggregates.
Analytical stores have their own APIs that need no database connections. The Redshift Data API runs SQL asynchronously over HTTPS with IAM or Secrets Manager authentication, which suits Lambda and Step Functions. The Athena API starts a query, then returns paginated results. Because analytical queries take seconds, an API that must answer quickly should serve precomputed results, for example aggregates written to DynamoDB by the pipeline, rather than run a warehouse query on every request. The following table summarises the building blocks.
| Need | Service or feature |
|---|---|
| Front door with authentication, throttling and caching | Amazon API Gateway |
| Business logic and data access | AWS Lambda |
| Low-latency lookups by key | Amazon DynamoDB |
| SQL on Redshift without drivers or connections | Redshift Data API |
| SQL on Aurora over HTTPS | RDS Data API |
| Queries on the data lake | Athena API (asynchronous, paginated results) |
The following diagram shows the request path of an API that serves sales metrics, and the pipeline that keeps its totals current.

Publishing data through an API
Maintaining data APIs
Once other systems depend on an API, it must change carefully. Breaking changes are published as a new version, such as a /v2 path or a new stage, while the old version keeps working until consumers migrate. CloudWatch metrics for latency, 4XX and 5XX errors and throttled requests show whether the API meets its targets, and API Gateway access logs record who called what. Throttling limits in usage plans protect the data store behind the API from any single consumer.
Maintaining APIs
A sales metrics API
A mobile application needs today's sales totals per store within 100 milliseconds. Running a Redshift query per request would be too slow and would load the warehouse. Instead, the pipeline writes each store's totals to a DynamoDB table every five minutes. API Gateway, with an IAM-authorised REST API and a usage plan limiting each client to 50 requests per second, invokes a Lambda function that reads the store's item. The API returns in milliseconds, and the warehouse is untouched.
What should a client do when a data API returns HTTP 429?
Show answer
Back off and retry later, following the API's limits.
Exam Tips
Remember for the exam
- API consumers must follow pagination tokens, back off on HTTP 429 and keep credentials in Secrets Manager.
- SaaS sources with built-in connectors: Amazon AppFlow.
- Expose data to other systems with API Gateway in front of Lambda, with throttling and authentication.
- Run SQL on Redshift from Lambda or Step Functions without connections: Redshift Data API.
- Fast APIs serve precomputed results (for example from DynamoDB) instead of querying the warehouse per request.