AWS Learning
Analytics

Amazon Data Firehose

Fully managed streaming ETL/delivery service, S3/Redshift/OpenSearch/Splunk destinations, Lambda transform, format conversion, dynamic partitioning

Giới thiệu

Amazon Data Firehose là dịch vụ fully managed streaming ETL / delivery service dùng để nhận, xử lý nhẹ, buffer, và delivery dữ liệu streaming gần real-time đến các đích như Amazon S3, Amazon Redshift, Amazon OpenSearch Service, OpenSearch Serverless, Splunk, Snowflake, Apache Iceberg Tables, HTTP endpoint và nhiều dịch vụ third-party.

Tên cũ thường gặp trong tài liệu/đề thi là Amazon Kinesis Data Firehose. Hiện AWS dùng tên Amazon Data Firehose, nhưng nhiều API, CloudFormation resource và CLI namespace vẫn còn chữ firehose hoặc KinesisFirehose.

Ý tưởng cực ngắn

Producer chỉ cần gửi record vào Firehose stream; Firehose tự scale, gom batch, có thể transform/convert/partition, rồi ghi vào destination.

Đặc điểm chính

Đặc điểmÝ nghĩa
Fully managedKhông cần quản lý server/shard/consumer app cho pipeline delivery cơ bản
Near real-timeDữ liệu được buffer theo size/time rồi delivery, thường tính bằng giây đến phút
Auto scalingTự scale theo throughput; Direct PUT có quota mặc định và có thể tăng
Built-in transformCó thể gọi AWS Lambda để biến đổi record trước khi delivery
Format conversionCó thể đổi JSON sang Parquet hoặc ORC khi ghi S3
Dynamic partitioningCó thể partition S3 prefix dựa trên field trong record
Compression/encryptionHỗ trợ compression và server-side encryption cho S3
Monitoring tích hợpCloudWatch metrics/logs, CloudTrail API logging

Amazon Data Firehose giải quyết vấn đề gì?

Không có Firehose, bạn thường phải tự viết nhiều phần trong pipeline:

App / Server / IoT / Logs


Custom ingestion service
        │   ├─ scale theo traffic
        │   ├─ retry khi destination lỗi
        │   ├─ batch dữ liệu
        │   ├─ compress/encrypt
        │   ├─ transform format
        │   └─ monitor lỗi

S3 / Redshift / OpenSearch / Splunk / HTTP ...

Với Firehose:

App / Logs / Kinesis Data Streams / MSK / AWS Services


┌─────────────────────────────────────────────────────────────┐
│                  Amazon Data Firehose                       │
│  buffer + optional Lambda transform + optional conversion    │
│  + optional dynamic partitioning + retry + monitoring        │
└─────────────────────────────────────────────────────────────┘


S3 / Redshift / OpenSearch / Splunk / Snowflake / HTTP ...

Bạn dùng Firehose khi muốn đưa stream data vào data lake, warehouse, search/log platform hoặc endpoint khác mà không muốn tự vận hành pipeline delivery.


Khái niệm cốt lõi

Khái niệmGiải thích
Firehose streamEntity chính của Firehose. Bạn tạo stream, cấu hình source/destination, rồi gửi dữ liệu vào stream đó.
RecordMột đơn vị dữ liệu producer gửi vào Firehose. Với Direct PUT, record tối đa 1,000 KiB trước base64 encoding.
Data producerNguồn tạo dữ liệu: app server, log agent, Kinesis Data Streams, Amazon MSK, AWS service logs...
DestinationNơi Firehose delivery dữ liệu: S3, Redshift, OpenSearch, Splunk, Snowflake, HTTP endpoint...
Buffer sizeLượng dữ liệu Firehose gom lại trước khi delivery.
Buffer intervalThời gian tối đa Firehose chờ trước khi delivery batch.
Backup S3 bucketNơi lưu source record hoặc failed record tùy destination/cấu hình.
Dynamic partitioningCơ chế tạo S3 prefix động theo field trong record, ví dụ country=VN/year=2026/.

Kiến trúc và luồng dữ liệu

Luồng tổng quát

┌──────────────┐
│  Producers   │
│ App / Logs   │
│ KDS / MSK    │
└──────┬───────┘
       │ PutRecord / source integration

┌──────────────────────────────────────────────────────────────┐
│                   Firehose stream                            │
│                                                              │
│  1. Ingest records                                           │
│  2. Deaggregate nếu cần                                      │
│  3. Decompress CloudWatch Logs nếu cấu hình                  │
│  4. Lambda transform nếu bật                                 │
│  5. Dynamic partitioning nếu ghi S3                          │
│  6. Convert JSON → Parquet/ORC nếu bật                       │
│  7. Buffer theo size/time                                    │
│  8. Deliver đến destination                                  │
└──────────────────────────────────────────────────────────────┘

       ├────────► Amazon S3 / Apache Iceberg Tables
       ├────────► Amazon Redshift qua S3 staging + COPY
       ├────────► Amazon OpenSearch / OpenSearch Serverless
       ├────────► Splunk / Datadog / New Relic / Elastic ...
       └────────► HTTP endpoint / Snowflake / MongoDB Atlas ...

Luồng đến Amazon S3

Producer → Firehose → optional Lambda → optional partition/format conversion → S3 objects

S3 là destination phổ biến nhất vì phù hợp làm data lake. Bạn có thể dùng Athena, Glue, EMR, Redshift Spectrum hoặc Lake Formation để phân tích tiếp.

Luồng đến Amazon Redshift

Producer → Firehose → S3 staging bucket → Redshift COPY → Redshift table

Firehose không ghi trực tiếp từng record vào Redshift. Nó ghi dữ liệu vào S3 trước, sau đó dùng lệnh COPY để load vào Redshift. Theo tài liệu AWS, delivery đến Redshift yêu cầu Redshift cluster có thể truy cập công khai trong giới hạn được nêu bởi Firehose.

Luồng đến OpenSearch/Splunk/HTTP

Producer → Firehose → destination
                  └→ optional S3 backup

Với các destination ngoài S3, bạn thường cấu hình S3 backup để giữ lại failed records hoặc tất cả records tùy nhu cầu audit/replay.


Nguồn dữ liệu

Firehose có thể nhận dữ liệu từ nhiều kiểu source:

SourceKhi nào dùng
Direct PUTApp gọi API PutRecord hoặc PutRecordBatch trực tiếp vào Firehose. Đơn giản nhất.
Kinesis Data StreamsKhi cần stream layer có retention, nhiều consumer, replay, ordering theo shard. Firehose đọc từ KDS và delivery đến destination.
Amazon MSKKhi dữ liệu đang ở Kafka/MSK và muốn delivery sang S3/analytics destinations.
AWS service logs / vended logsNhiều dịch vụ AWS có thể gửi log/event vào Firehose.
Kinesis Agent / Fluent Bit / agent khácThu thập log từ server/container rồi gửi vào Firehose.

Direct PUT vs Kinesis Data Streams source

Tiêu chíDirect PUT vào FirehoseKinesis Data Streams → Firehose
Đơn giảnRất đơn giảnPhức tạp hơn
Replay dữ liệuKhông phải mục tiêu chínhCó retention/replay trong KDS
Nhiều consumer độc lậpKhông phù hợpRất phù hợp
Ordering theo shardKhông phải trọng tâmCó ordering trong shard
Use caseLogs/events đi thẳng vào S3/OpenSearchStreaming platform có nhiều consumer + Firehose là một consumer delivery

Đích đến được hỗ trợ

Theo AWS Documentation, Amazon Data Firehose hỗ trợ nhiều destination, gồm:

DestinationGhi chú
Amazon S3Data lake, raw/processed logs, partitioned datasets
Apache Iceberg TablesGhi vào Iceberg table cho lakehouse workloads
Amazon RedshiftFirehose staging qua S3 rồi COPY vào Redshift
Amazon OpenSearch ServiceIndex logs/events để search/observability
Amazon OpenSearch ServerlessServerless search/analytics destination
SplunkLog/security analytics
SnowflakeCloud data platform destination
HTTP endpointCustom endpoint hoặc SaaS endpoint hỗ trợ
Third-party providersVí dụ Datadog, Dynatrace, LogicMonitor, MongoDB, New Relic, Coralogix, Elastic...

Lưu ý: destination support có thể khác theo Region và có thể thay đổi. Khi triển khai thật, kiểm tra AWS docs/console cho Region đang dùng.


Buffering, batching và độ trễ

Firehose không nhất thiết gửi từng record ngay lập tức. Nó buffer record theo hai điều kiện:

  1. Buffer size: đủ dung lượng MB đã cấu hình.
  2. Buffer interval: đủ thời gian chờ đã cấu hình.

Khi một trong hai điều kiện đạt ngưỡng, Firehose delivery batch đến destination.

Incoming records
  r1 r2 r3 r4 r5 ...


Firehose buffer
  ├─ flush khi đủ size
  └─ hoặc flush khi tới interval


Destination object / batch / request

Tác động của buffer

Buffer nhỏBuffer lớn
Latency thấp hơnLatency cao hơn
Nhiều object/request hơnÍt object/request hơn
Có thể tăng cost/overhead ở destinationTối ưu throughput/cost hơn
Phù hợp alert/log gần real-timePhù hợp data lake/batch analytics

Theo AWS quota docs, buffer interval hints nằm trong khoảng 60–900 giây.


Transform dữ liệu bằng AWS Lambda

Firehose có thể invoke AWS Lambda để transform record trước khi delivery.

Khi nào cần Lambda transform?

  • Parse log text thành JSON.
  • Mask hoặc xoá PII trước khi ghi S3.
  • Thêm metadata như source, env, tenant_id.
  • Chuẩn hóa timestamp.
  • Lọc record không hợp lệ.
  • Convert CSV hoặc custom text sang JSON để sau đó Firehose convert sang Parquet/ORC.
  • Tạo partition key động phức tạp cho S3 dynamic partitioning.

Flow

Record gốc


Firehose invokes Lambda

   ├─ Ok: transformed record
   ├─ Dropped: bỏ record
   └─ ProcessingFailed: đưa vào error flow / backup

Destination

Lưu ý quan trọng

  • Lambda phải trả response theo format Firehose yêu cầu.
  • Nếu Lambda lỗi hoặc timeout, Firehose retry theo cấu hình và có thể đưa record vào error backup.
  • Với Amazon MSK source, tài liệu AWS nêu record max 6 MB nếu bật Lambda do Lambda quota; 10 MB nếu không bật Lambda trong ngữ cảnh MSK source.
  • Không nên làm transform quá nặng trong Firehose Lambda. Nếu ETL phức tạp, cân nhắc AWS Glue, EMR, Flink hoặc consumer riêng.

Convert format sang Parquet/ORC

Firehose có thể đổi dữ liệu JSON → Apache Parquet hoặc Apache ORC trước khi lưu vào S3.

Vì sao nên dùng Parquet/ORC?

JSONParquet/ORC
Row-orientedColumnar
Dễ đọc/debugTối ưu analytics
Tốn dung lượng hơnNén tốt hơn
Athena scan nhiều data hơnAthena/Redshift Spectrum scan ít data hơn

Firehose cần gì để convert format?

Theo AWS docs, Firehose cần 3 thành phần:

  1. Deserializer để đọc JSON input:
    • Apache Hive JSON SerDe
    • OpenX JSON SerDe
  2. Schema trong AWS Glue Data Catalog để hiểu cấu trúc dữ liệu.
  3. Serializer để ghi output:
    • Parquet SerDe
    • ORC SerDe
JSON records


Deserializer + Glue schema


Parquet/ORC serializer


S3 optimized objects

Lưu ý

  • Input format phải là JSON. Nếu source là CSV/text, dùng Lambda transform sang JSON trước.
  • Schema trong Glue phải khớp cấu trúc input; field không có trong schema có thể không xuất hiện trong output converted data.
  • Nested JSON cần schema kiểu STRUCT tương ứng.
  • Khi bật record format conversion, use case chính là delivery đến S3.

Dynamic partitioning với Amazon S3

Dynamic partitioning cho phép Firehose ghi record vào các S3 prefix khác nhau dựa trên nội dung record.

Ví dụ record:

{
  "event_time": "2026-05-28T10:15:00Z",
  "country": "VN",
  "service": "checkout",
  "level": "ERROR"
}

Có thể ghi vào S3 prefix:

s3://my-log-bucket/events/country=VN/service=checkout/year=2026/month=05/day=28/

Lợi ích

  • Athena/Glue query scan ít dữ liệu hơn.
  • Dữ liệu vào S3 đã sẵn sàng cho partition-based analytics.
  • Tránh phải chạy job repartition sau khi data landed.

Cách tạo partition key

CáchMô tả
Inline parsingDùng jq expression để trích field từ JSON. AWS docs nêu Firehose hỗ trợ jq 1.6.
Lambda functionDùng Lambda để tạo partition key, phù hợp dữ liệu nén/mã hóa/non-JSON hoặc logic phức tạp.
Kết hợp cả haiCó thể dùng cả inline parsing và Lambda partition key.

Thứ tự xử lý khi dynamic partitioning với S3

Theo tài liệu AWS cho destination S3, Firehose xử lý theo thứ tự:

KPL deaggregation
→ JSON/delimiter deaggregation
→ Lambda processing
→ data partitioning
→ data format conversion
→ S3 delivery

Lưu ý quan trọng

  • Dynamic partitioning khi đã bật trên một Firehose stream thì theo AWS docs không thể disable trên stream đó.
  • Nếu data được aggregate nhiều event trong một API call, cần bật deaggregation để Firehose tách record trước khi partition.
  • Quota mặc định cho dynamic partitioning là 500 active partitions trên mỗi Firehose stream.
  • Thiết kế partition key quá high-cardinality có thể làm tăng active partitions, tạo nhiều object nhỏ và gây lỗi/cost cao.

Backup, retry và xử lý lỗi

Firehose được thiết kế để retry khi destination tạm thời lỗi, nhưng bạn vẫn cần cấu hình backup/error path đúng.

Các kiểu lỗi thường gặp

Nhóm lỗiVí dụ
PermissionIAM role thiếu quyền ghi S3, KMS key policy sai, OpenSearch policy sai
Network/destinationHTTP endpoint down, Splunk unavailable, Redshift không truy cập được
FormatJSON không match schema Glue, Lambda output sai format
QuotaDirect PUT throughput bị throttle, active partitions vượt quota
Data qualityRecord quá lớn, encoding sai, timestamp/field thiếu

Retention khi destination unavailable

Theo AWS quota docs:

  • Với source Direct PUT, Firehose lưu record tối đa 24 giờ nếu destination unavailable.
  • Với source Kinesis Data Streams, retention phụ thuộc cấu hình retention của Kinesis Data Streams.

S3 backup

Nên cấu hình S3 backup cho:

  • Failed records từ destination ngoài S3.
  • Source records trước transform nếu cần audit/replay.
  • Error prefix rõ ràng để debug, ví dụ:
s3://my-bucket/firehose-errors/!{firehose:error-output-type}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/

Bảo mật

IAM role

Firehose dùng IAM role để access destination và các dịch vụ liên quan:

  • Ghi object vào S3.
  • Dùng KMS key nếu mã hóa SSE-KMS.
  • Invoke Lambda transform.
  • Đọc schema AWS Glue Data Catalog khi format conversion.
  • Ghi vào OpenSearch/Redshift/Snowflake/HTTP destination theo cấu hình.

Ví dụ quyền tối thiểu cho S3 destination thường cần:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:AbortMultipartUpload",
        "s3:GetBucketLocation",
        "s3:GetObject",
        "s3:ListBucket",
        "s3:ListBucketMultipartUploads",
        "s3:PutObject"
      ],
      "Resource": [
        "arn:aws:s3:::my-firehose-bucket",
        "arn:aws:s3:::my-firehose-bucket/*"
      ]
    }
  ]
}

Encryption

  • S3 destination hỗ trợ server-side encryption, gồm SSE-KMS.
  • Có thể dùng AWS managed key hoặc customer managed KMS key.
  • Nếu dùng customer managed key, cần key policy cho Firehose role.

Network/private connectivity

  • Với một số destination hoặc source, cần chú ý VPC access, security group, endpoint/network reachability.
  • Nếu ghi đến HTTP endpoint public, cần xác thực và bảo vệ secret/token.
  • Không log plaintext secret trong Lambda transform hoặc CloudWatch Logs.

Data protection

  • Mask PII trước khi delivery nếu destination không nên lưu dữ liệu nhạy cảm.
  • Dùng S3 bucket policy, Block Public Access, Object Ownership, lifecycle và retention phù hợp.
  • Bật CloudTrail để audit API calls liên quan Firehose.

Monitoring và troubleshooting

Firehose publish metrics vào namespace AWS/Firehose. AWS khuyến nghị bật alarm cho các metrics liên quan destination để phát hiện lỗi kịp thời.

Metrics nên biết

MetricÝ nghĩa
IncomingBytesSố bytes ingest vào Firehose
IncomingRecordsSố records ingest vào Firehose
DeliveryToS3.SuccessDelivery S3 thành công
DeliveryToS3.DataFreshnessTuổi của record cũ nhất chưa được delivery xong đến S3
DeliveryToRedshift.SuccessRedshift COPY thành công
DeliveryToAmazonOpenSearchService.SuccessIndex OpenSearch thành công
DeliveryToSplunk.SuccessDelivery Splunk thành công
DeliveryToHttpEndpoint.SuccessDelivery HTTP endpoint thành công
ThrottledRecordsRecords bị throttle với Direct PUT/API-level scenario
DeliveryToS3.ObjectCountSố object tạo ra trên S3, hữu ích để phát hiện small files
PartitionCountSố active partitions khi bật dynamic partitioning
PartitionCountExceededBáo vượt active partition limit
Lambda transform metricsTheo dõi lỗi/duration transform
Format conversion metricsTheo dõi lỗi convert JSON sang Parquet/ORC

Checklist debug nhanh

1. Không thấy dữ liệu ở destination?
   ├─ Kiểm tra IncomingRecords/IncomingBytes có tăng không
   ├─ Kiểm tra buffer interval: có thể chưa flush
   ├─ Kiểm tra CloudWatch Logs của Firehose nếu đã bật
   ├─ Kiểm tra IAM role/KMS/bucket policy
   └─ Kiểm tra error backup prefix trong S3

2. Dữ liệu đến chậm?
   ├─ Xem DataFreshness
   ├─ Buffer size/interval có quá lớn không
   ├─ Destination có throttle/lỗi không
   └─ Lambda transform có chậm/lỗi không

3. Quá nhiều file nhỏ ở S3?
   ├─ Tăng buffer size/interval nếu latency cho phép
   ├─ Giảm cardinality partition key
   └─ Kiểm tra quota Direct PUT có bị set quá cao so với traffic thực không

4. Dynamic partitioning lỗi?
   ├─ Kiểm tra jq expression
   ├─ Kiểm tra missing field/null value
   ├─ Kiểm tra active partitions
   └─ Kiểm tra error-output prefix

Quotas quan trọng

Một số quota được AWS docs nêu rõ:

QuotaGiá trị / ghi chú
Max record size với Direct PUT1,000 KiB trước base64 encoding
PutRecordBatchTối đa 500 records/call hoặc 4 MiB/call, lấy điều kiện nhỏ hơn
Buffer interval hints60–900 giây
Direct PUT throughput mặc định ở us-east-1, us-west-2, eu-west-1500,000 records/s, 2,000 requests/s, 5 MiB/s mỗi stream
Direct PUT throughput mặc định ở Regions khác100,000 records/s, 1,000 requests/s, 1 MiB/s mỗi stream
Dynamic partitioning active partitionsMặc định 500 active partitions mỗi stream
Dynamic partitioning per active partition throughputTối đa 1 GB/s mỗi active partition
Retention khi Direct PUT destination unavailableTối đa 24 giờ
Amazon MSK source read throughputMặc định 10 MB/s per partition
Amazon MSK source max record size10 MB, hoặc 6 MB nếu bật Lambda
Control plane APIsMột số API như Create/Delete/Describe/List/Update có hard limit 5 invocations/s
Customer managed CMK encryptionCó thể encrypt tối đa 500 Firehose streams với CMK type CUSTOMER_MANAGED_CMK

Quotas thay đổi theo Region và thời gian. Khi thiết kế production, luôn kiểm tra Service Quotas và AWS General Reference.


Pricing

Amazon Data Firehose có mô hình pay-as-you-go. Các nhóm chi phí chính thường gồm:

Nhóm chi phíMô tả
IngestionTính theo GB dữ liệu ingest; với Direct PUT/KDS thường làm tròn theo record size increment nhất định.
Format conversionPhí khi convert JSON sang Parquet/ORC.
Dynamic partitioningPhí bổ sung khi bật dynamic partitioning.
VPC deliveryCó thể có phí cho delivery qua VPC tùy destination/cấu hình.
Destination costsS3 storage/PUT, Redshift, OpenSearch, Splunk/SaaS, KMS, Lambda, CloudWatch Logs... tính riêng.

Cost traps hay gặp

  • Gửi quá nhiều record nhỏ: pricing ingestion có thể làm tròn theo kích thước record, nên nhiều record nhỏ có thể đắt hơn ít record lớn với cùng tổng bytes.
  • Dynamic partitioning high-cardinality tạo nhiều S3 object nhỏ.
  • Lambda transform chạy lâu hoặc memory cao.
  • CloudWatch Logs debug bật quá verbose.
  • Destination như OpenSearch/Redshift/Snowflake có cost riêng đáng kể.

So sánh Firehose với các dịch vụ liên quan

Firehose vs Kinesis Data Streams

Tiêu chíAmazon Data FirehoseAmazon Kinesis Data Streams
Mục tiêuDelivery stream data đến destinationStreaming backbone cho producers/consumers
Quản lý consumerFirehose quản lý deliveryBạn tự viết consumer hoặc dùng Lambda/Flink/etc.
ReplayKhông phải điểm mạnhCó retention và replay
Multi-consumerKhông phải trọng tâmRất phù hợp
LatencyNear real-time, phụ thuộc bufferMillisecond/sub-second tùy consumer
ScalingFully managed, auto scalingTheo shard/on-demand mode
Use caseLogs/events → S3/OpenSearch/Redshift/SaaSEvent streaming, nhiều consumer, real-time processing

Mẹo nhớ:

  • Cần stream platform + replay + nhiều consumers → Kinesis Data Streams.
  • Cần đưa data vào S3/Redshift/OpenSearch/Splunk nhanh, ít vận hành → Firehose.

Firehose vs AWS Glue

Tiêu chíFirehoseAWS Glue
Kiểu xử lýStreaming delivery + transform nhẹETL batch/streaming phức tạp
LatencyGần real-timeThường batch hoặc streaming job
TransformLambda đơn giảnSpark/Python/Glue ETL mạnh hơn
Use caseIngest logs/events vào data lakeClean/join/enrich large datasets

Firehose vs Amazon MSK / Kafka

Tiêu chíFirehoseMSK/Kafka
Vai tròManaged delivery pipelineDistributed event streaming platform
Consumer modelDestination-orientedTopic/partition/consumer group
ReplayKhông phải trọng tâmRetention/replay là core feature
OpsRất ítNhiều khái niệm hơn dù MSK managed

Firehose vs CloudWatch Logs subscription

Tiêu chíFirehoseCloudWatch Logs subscription
Vai tròDestination delivery serviceCơ chế xuất log từ CloudWatch Logs
Quan hệCó thể là destination của log subscriptionCó thể gửi log vào Firehose

Use cases phổ biến

1. Centralized logging vào S3 data lake

Applications / Servers / Containers


Firehose

        ├─ Lambda mask PII
        ├─ Dynamic partition by app/env/date
        └─ Convert JSON → Parquet

S3 Data Lake → Glue Catalog → Athena/QuickSight

2. Near real-time search logs bằng OpenSearch

App logs → Firehose → OpenSearch
                    └→ S3 backup failed/all records

Dùng khi muốn query log nhanh trên OpenSearch nhưng vẫn giữ raw data ở S3 để archive/replay.

3. Clickstream analytics

Web/mobile events → Firehose → S3 partitioned by date/country/app
                              → Athena/Redshift Spectrum

4. Security events vào SIEM/Splunk

AWS logs / security events → Firehose → Splunk
                                      └→ S3 backup

5. Kafka/MSK data lake sink

Amazon MSK topic → Firehose → S3 / Iceberg / Snowflake

Phù hợp khi đội data muốn lấy Kafka topic vào lake/warehouse mà không tự vận hành Kafka Connect sink.


Best practices

Thiết kế S3 data lake

  • Dùng prefix có cấu trúc rõ ràng:
s3://bucket/raw/service=checkout/env=prod/year=2026/month=05/day=28/hour=10/
  • Dùng Parquet/ORC nếu query bằng Athena/Redshift Spectrum thường xuyên.
  • Tránh partition key quá high-cardinality như user_id nếu traffic lớn.
  • Bật newline delimiter nếu lưu JSON và muốn Athena đọc record dễ hơn.

Reliability

  • Luôn cấu hình S3 backup/error prefix cho destination ngoài S3.
  • Bật CloudWatch alarms cho destination success/failure/data freshness.
  • Producer nên retry với exponential backoff khi Direct PUT bị throttle.
  • Với use case cần replay chắc chắn, đặt Kinesis Data Streams hoặc MSK trước Firehose.

Performance/cost

  • Điều chỉnh buffer size/interval theo trade-off latency vs object size.
  • Gom record nhỏ ở producer nếu hợp lý để giảm overhead/cost.
  • Theo dõi DeliveryToS3.ObjectCount và số lượng small files.
  • Với Athena, partition + Parquet thường giảm cost scan đáng kể.

Security

  • IAM role theo least privilege.
  • Mã hóa S3 với SSE-KMS nếu dữ liệu nhạy cảm.
  • Không đưa secret vào record/log.
  • Mask/tokenize PII trước khi lưu vào destination rộng quyền truy cập.

Schema evolution

  • Nếu convert sang Parquet/ORC, quản lý schema trong Glue cẩn thận.
  • Thay đổi field/type cần test trước vì schema không khớp có thể gây mất field hoặc lỗi conversion.
  • Cân nhắc versioned prefix: schema_version=1/, schema_version=2/.

Ví dụ triển khai nhanh

Ví dụ minh họa để học. Khi chạy thật, thay bucket/role/region phù hợp và kiểm tra IAM trust policy cho Firehose.

1. Tạo S3 bucket làm destination

aws s3 mb s3://my-firehose-demo-bucket --region ap-southeast-1

2. Tạo IAM role cho Firehose

Trust policy ví dụ:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "Service": "firehose.amazonaws.com" },
      "Action": "sts:AssumeRole"
    }
  ]
}

Policy tối thiểu cho S3 destination cần quyền ghi bucket như phần Security ở trên.

3. Tạo Firehose stream Direct PUT đến S3 bằng CLI

File s3-destination.json:

{
  "RoleARN": "arn:aws:iam::123456789012:role/firehose-s3-role",
  "BucketARN": "arn:aws:s3:::my-firehose-demo-bucket",
  "Prefix": "raw/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/hour=!{timestamp:HH}/",
  "ErrorOutputPrefix": "errors/!{firehose:error-output-type}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/",
  "BufferingHints": {
    "SizeInMBs": 5,
    "IntervalInSeconds": 60
  },
  "CompressionFormat": "GZIP"
}

Tạo stream:

aws firehose create-delivery-stream \
  --delivery-stream-name demo-directput-to-s3 \
  --delivery-stream-type DirectPut \
  --s3-destination-configuration file://s3-destination.json \
  --region ap-southeast-1

4. Gửi một record test

aws firehose put-record \
  --delivery-stream-name demo-directput-to-s3 \
  --record 'Data={"event":"signup","user_id":"u-001","country":"VN"}' \
  --region ap-southeast-1

Sau khi buffer flush, kiểm tra S3:

aws s3 ls s3://my-firehose-demo-bucket/raw/ --recursive

5. CloudFormation resource name

Trong CloudFormation, resource type vẫn là:

Type: AWS::KinesisFirehose::DeliveryStream

Điều này dễ gây nhầm vì service đã đổi tên marketing thành Amazon Data Firehose.


Exam tips

  • Firehose = delivery/load streaming data, không phải general-purpose stream processing engine.
  • Nếu đề nói load streaming logs to S3/Redshift/OpenSearch/Splunk with minimal administration → chọn Firehose.
  • Nếu cần replay, nhiều consumer, ordering theo shard → chọn Kinesis Data Streams, có thể kết hợp Firehose làm một consumer.
  • Nếu cần ETL phức tạp, join/enrich lớn → Glue/EMR/Flink phù hợp hơn Lambda transform trong Firehose.
  • Firehose đến Redshift: nhớ luồng S3 staging → Redshift COPY.
  • Firehose có thể convert JSON sang Parquet/ORC khi ghi S3, cần Glue Data Catalog schema.
  • Dynamic partitioning giúp ghi S3 prefix theo field trong record; tránh high-cardinality.
  • Firehose là near real-time, không phải low-latency millisecond pipeline.
  • S3 backup/error prefix rất quan trọng cho troubleshooting và replay.

Nguồn chính thức

On this page

Giới thiệuÝ tưởng cực ngắnĐặc điểm chínhAmazon Data Firehose giải quyết vấn đề gì?Khái niệm cốt lõiKiến trúc và luồng dữ liệuLuồng tổng quátLuồng đến Amazon S3Luồng đến Amazon RedshiftLuồng đến OpenSearch/Splunk/HTTPNguồn dữ liệuDirect PUT vs Kinesis Data Streams sourceĐích đến được hỗ trợBuffering, batching và độ trễTác động của bufferTransform dữ liệu bằng AWS LambdaKhi nào cần Lambda transform?FlowLưu ý quan trọngConvert format sang Parquet/ORCVì sao nên dùng Parquet/ORC?Firehose cần gì để convert format?Lưu ýDynamic partitioning với Amazon S3Lợi íchCách tạo partition keyThứ tự xử lý khi dynamic partitioning với S3Lưu ý quan trọngBackup, retry và xử lý lỗiCác kiểu lỗi thường gặpRetention khi destination unavailableS3 backupBảo mậtIAM roleEncryptionNetwork/private connectivityData protectionMonitoring và troubleshootingMetrics nên biếtChecklist debug nhanhQuotas quan trọngPricingCost traps hay gặpSo sánh Firehose với các dịch vụ liên quanFirehose vs Kinesis Data StreamsFirehose vs AWS GlueFirehose vs Amazon MSK / KafkaFirehose vs CloudWatch Logs subscriptionUse cases phổ biến1. Centralized logging vào S3 data lake2. Near real-time search logs bằng OpenSearch3. Clickstream analytics4. Security events vào SIEM/Splunk5. Kafka/MSK data lake sinkBest practicesThiết kế S3 data lakeReliabilityPerformance/costSecuritySchema evolutionVí dụ triển khai nhanh1. Tạo S3 bucket làm destination2. Tạo IAM role cho Firehose3. Tạo Firehose stream Direct PUT đến S3 bằng CLI4. Gửi một record test5. CloudFormation resource nameExam tipsNguồn chính thức