Delivering Streaming Data to Storage with Amazon Data Firehose
This lesson explains how Amazon Data Firehose, formerly Kinesis Data Firehose, loads streaming data into storage and analytics destinations with no consumer code to manage.
Learning outcomes
After completing this lesson, you will be able to:
- Identify the sources and destinations that Firehose supports and how a Lambda function transforms records.
- Explain how buffer size and interval settings affect delivery latency.
- Describe how Firehose retries failed deliveries and backs up records to Amazon S3.
- Choose between Amazon Data Firehose and Kinesis Data Streams.
Destinations and transformation
Amazon Data Firehose receives records from producers, such as applications calling PutRecordBatch, Kinesis Data Streams, CloudWatch Logs subscription filters or AWS IoT, and delivers them to a destination without any consumer code. Destinations include Amazon S3, Amazon Redshift, Amazon OpenSearch Service, Apache Iceberg tables, Splunk, generic HTTP endpoints and partner services such as Datadog.
On the way, Firehose can change the data. A Lambda transformation function receives batches of records and returns them modified, for example with sensitive fields removed or formats converted. Format conversion turns JSON into Parquet or ORC using a schema from the AWS Glue Data Catalog, which makes later queries with Amazon Athena faster and cheaper. Dynamic partitioning writes records to S3 prefixes based on fields in the data, such as customer=42/, so queries can skip irrelevant data.
A transformation function must return every record it received, each with its original recordId and a result of Ok, Dropped or ProcessingFailed, as the following example shows.
import base64, json
def handler(event, context):
output = []
for record in event["records"]:
data = json.loads(base64.b64decode(record["data"]))
if data.get("level") == "DEBUG":
output.append({"recordId": record["recordId"], "result": "Dropped"})
continue
data.pop("password", None)
line = (json.dumps(data) + "\n").encode()
output.append({"recordId": record["recordId"], "result": "Ok", "data": base64.b64encode(line).decode()})
return {"records": output}Buffering
Firehose does not write each record as it arrives. It collects records in a buffer and writes them when the buffer reaches a configured size, such as 5 MiB, or when a configured interval, such as 60 seconds, has passed, whichever happens first. Delivery is therefore near real time rather than immediate.
The buffer settings are a trade-off. Larger buffers and longer intervals produce fewer, larger files, which are cheaper to store, require fewer S3 requests and are faster to query, but data takes longer to appear at the destination. Smaller buffers reduce the delay but create many small files, which slow down Athena queries. When data must be available within a second or two, Kinesis Data Streams with a custom consumer is the better choice.
The following diagram shows when Firehose flushes its buffer under heavy and light traffic.

Reliability
Firehose scales automatically with the volume of incoming data, with no shards to manage. When a delivery fails, for example because an HTTP endpoint is unavailable or a Redshift load is rejected, Firehose retries it for a configurable period. Records that still cannot be delivered, or that a transformation function marked as ProcessingFailed, are written to a backup S3 location together with details of the error, so no data is lost and failed records can be reprocessed later.
Delivery problems appear in CloudWatch metrics, such as DeliveryToS3.Success and the data freshness metric, which shows the age of the oldest record not yet delivered, and in error logs that Firehose writes to CloudWatch Logs when error logging is enabled.
Tune Firehose delivery
Firehose or Kinesis Data Streams?
Amazon Data Firehose and Kinesis Data Streams both ingest streaming data, but they solve different problems.
Amazon Data Firehose is a delivery service. Producers send records to a Firehose stream, which buffers them until a size or time threshold is reached and then writes them to a destination such as S3, Amazon Redshift, OpenSearch Service or an HTTP endpoint. It can transform records with a Lambda function, convert them to columnar formats such as Parquet, and compress them on the way. There are no shards and no consumer code: capacity scales automatically. Records are delivered once and cannot be read again, and buffering means data arrives in near real time rather than immediately.
Kinesis Data Streams is a storage layer for custom processing. Records stay in the stream for the retention period, several consumers can read them independently with sub-second latency, and any consumer can replay them. The application provides the consumers and, in provisioned mode, manages the number of shards. The two are often combined: a stream feeds real-time consumers, and a Firehose stream reading from it archives the same data to S3. The following table summarises the differences.
Firehose or Data Streams?
Data Streams or Firehose?
Kinesis Data Streams and Firehose suit different streaming requirements. The following table identifies the appropriate service for each requirement.
| Requirement | Choice |
|---|---|
| Store clickstream events in S3 for analytics, with no code to manage | Firehose |
| Three different applications must read the same events independently and replay them | Data Streams |
| Events must be processed in under a second | Data Streams (Firehose buffers for seconds to minutes) |
| Convert JSON to Parquet and partition by date on the way into S3 | Firehose |
| Load events into Amazon OpenSearch or Splunk | Firehose |
A common design uses both: Data Streams for real-time consumers, with Firehose reading from the stream to archive everything in S3.
How can records be converted before Firehose delivers them to S3?
Show answer
Enable data transformation with a Lambda function. Firehose sends buffered batches to the function and delivers what it returns; it can also convert records to Parquet or ORC.
Exam Tips
Remember for the exam
- "Load streaming data into S3 or Redshift with minimal management" points to Firehose.
- When you need custom consumers or replay, use Kinesis Data Streams instead.
- For fewer, larger files in S3, increase the Firehose buffer size and interval.
- To partition output in S3 by a field in the data, use dynamic partitioning.