Building Serverless Data Pipelines with Kinesis, Lambda, Glue and Athena
This lesson explains the stages of a serverless data pipeline, the service for each stage, and how data layout keeps Athena queries fast and cheap.
Learning outcomes
After completing this lesson, you will be able to:
- Identify the services for ingestion, transformation and analysis in a serverless pipeline.
- Explain how file format, partitioning and partition projection affect Athena cost and speed.
- Choose between Lambda and AWS Glue for a transformation.
Stages and services
Ingestion
Kinesis Data Streams captures streaming records, keeps them in order per partition key and lets several consumers read them, in on-demand or provisioned capacity mode. Files arriving in S3 start processing through S3 event notifications or EventBridge.
Transformation
Lambda handles per-record or small-batch transformations, reading streams and queues through event source mappings with batching, batching windows, parallelisation factor and partial batch failure reporting. AWS Glue ETL jobs run serverless Apache Spark for large batch transformations and joins, and Glue crawlers register tables in the Data Catalog.
Analysis
Amazon Athena queries data in S3 with SQL through the Glue Data Catalog and charges per data scanned. Step Functions or Glue workflows orchestrate the stages.
Laying out data for cost and speed
Because Athena charges per byte scanned, the pipeline should write columnar, compressed formats such as Parquet, partition data by common filters such as date, and avoid many tiny files, which slow queries. Partition projection lets Athena compute partitions from a path template instead of looking them up, which helps tables with many partitions. Apache Iceberg tables add transactional updates and compaction. Query result reuse and per-workgroup data limits control repeated and runaway queries.
| Problem | Fix |
|---|---|
| Queries scan whole JSON or CSV data sets | Convert to partitioned Parquet with Glue |
| Slow planning for highly partitioned tables | Partition projection |
| Many tiny files from streaming | Compaction (Iceberg or a scheduled job) |
| Repeated identical dashboard queries | Athena query result reuse |
Laying out data
Choosing Lambda or Glue
Clickstream analytics
An e-commerce company collects 3 TB of clickstream events a day and wants near real-time fraud flags and daily reporting in Athena at low cost.
Events go to Kinesis Data Streams; a Lambda function with an event source mapping enriches each batch with user risk scores from DynamoDB and flags suspicious sessions to EventBridge.
Raw events are delivered to S3, and a nightly Glue job converts them to Parquet partitioned by date and hour in an Iceberg table, which cut Athena scanned data by more than 90% compared with querying the raw JSON.
Why does converting CSV to Parquet reduce Athena cost?
Show answer
Athena charges per data scanned. Parquet is columnar and compressed, so queries read only the columns they need, and partitioning lets them skip whole partitions.
Exam Tips
Remember for the exam
- Reduce Athena cost: partitioned, compressed Parquet; many partitions: partition projection.
- Per-record streaming enrichment: Lambda with a Kinesis event source mapping.
- Terabyte-scale batch transformation without clusters: AWS Glue ETL.
- Ad hoc SQL on S3: Athena over the Glue Data Catalog.