Lesson 9 of 10 Serverless and API Architecture

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.

ProblemFix
Queries scan whole JSON or CSV data setsConvert to partitioned Parquet with Glue
Slow planning for highly partitioned tablesPartition projection
Many tiny files from streamingCompaction (Iceberg or a scheduled job)
Repeated identical dashboard queriesAthena query result reuse
Select all that apply

Laying out data

Exam skills 1.1.3 · 3.4.1

Identify layout choices that reduce query cost and time in an S3 data pipeline.

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

Choosing Lambda or Glue

Lambda
Unit of workRecord or small batch
DurationUp to 15 minutes per invocation
Typical useEnrichment, validation, routing
Choose when Event-driven, per-record processing.
AWS Glue ETL
Unit of workData sets of gigabytes to terabytes
DurationMinutes to hours
Typical useJoins, aggregations, format conversion
Choose when Large batch transformations.
Worked example

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.

Check yourself

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.