Lesson 9 of 10 Data Pipeline Design Patterns

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.

SourceConsumer
Supported SaaS applications (Salesforce, ServiceNow, SAP)Amazon AppFlow, with no code
Small, frequent calls to a REST APILambda on an EventBridge Scheduler schedule
Long-running extractsGlue Python shell job or a container on ECS or AWS Batch
API calls as steps in a workflowStep Functions HTTP task with an EventBridge connection
AWS service APIsAWS SDKs, using paginators and built-in retries
Match the pairs

Consuming APIs

Exam skills 1.1.4 · 3.1.5

Match each API source with the consumer that fits it.

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

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.

NeedService or feature
Front door with authentication, throttling and cachingAmazon API Gateway
Business logic and data accessAWS Lambda
Low-latency lookups by keyAmazon DynamoDB
SQL on Redshift without drivers or connectionsRedshift Data API
SQL on Aurora over HTTPSRDS Data API
Queries on the data lakeAthena 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.

The sales metrics API. Every five minutes the pipeline writes each store's totals to DynamoDB. The mobile application calls an IAM-authorised API Gateway REST API, limited to 50 requests per second per client by a usage plan, and a Lambda function reads the store's item in milliseconds. Redshift is not queried per request.
The dashed card is not part of the request path.
Scenario questions

Publishing data through an API

Exam skills 1.2.8 · 3.1.5

Choose the building block for each requirement.

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

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.

True or false

Maintaining APIs

Exam skills 3.1.5

Decide whether each statement about maintaining data APIs is true.

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

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.

Check yourself

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.