AWS Glue
Serverless ETL, Data Catalog, Crawlers, Spark/Python Jobs, Glue Studio
Tổng quan
AWS Glue là một dịch vụ serverless data integration giúp bạn khám phá, chuẩn bị, di chuyển và tích hợp dữ liệu từ nhiều nguồn khác nhau. Nó được thiết kế cho:
- Analytics - Chuẩn bị dữ liệu cho phân tích
- Machine Learning - ETL pipeline cho ML workflows
- Application Development - Tích hợp dữ liệu cho ứng dụng
[!TIP] AWS Glue là fully managed - bạn không cần quản lý infrastructure. Nó tự động scale và bạn chỉ trả tiền khi job đang chạy.
Kiến trúc tổng quan
Thành phần chính (Core Components)
1. AWS Glue Data Catalog
Data Catalog là nơi lưu trữ metadata (persistent metadata store) của AWS Glue:
Đặc điểm quan trọng:
- Mỗi AWS account có một Data Catalog per Region
- Tables chỉ chứa metadata, không chứa actual data
- Data thực tế vẫn ở data store gốc (S3, RDS, etc.)
- Sử dụng được với: Amazon Athena, Amazon EMR, Amazon Redshift Spectrum
Metadata dùng để làm gì?
Metadata trong Glue Data Catalog giúp:
- Định vị dữ liệu: biết dataset nằm ở path nào (
s3://...) - Mô tả schema: biết cột nào, kiểu dữ liệu gì, partition theo trường nào
- Cho phép query dạng table: Athena/EMR/Spectrum dùng metadata để query dữ liệu ở nguồn
- Dùng chung giữa services: nhiều dịch vụ AWS đọc cùng một catalog metadata
Ví dụ cụ thể (data lake trên S3):
- Bạn có dữ liệu thật ở S3:
s3://health-lake-raw/patient/date=2026-03-04/data.parquet - Glue Crawler scan folder và tạo table
raw_db.patient_eventstrong Data Catalog - Table metadata chứa:
- columns:
patient_id,heart_rate,event_time - format:
Parquet - location:
s3://health-lake-raw/patient/
- columns:
- Khi chạy Athena:
SELECT * FROM raw_db.patient_events LIMIT 10;- Athena đọc metadata từ Data Catalog
- rồi đọc data thật từ S3
- Nếu xóa table external trong Athena/Glue, bạn xóa metadata table definition; file S3 vẫn còn
2. Crawlers
Crawler là chương trình tự động kết nối với data store và tạo metadata:
Crawler hỗ trợ:
- Data stores: S3, DynamoDB, MongoDB, JDBC databases (RDS, Redshift)
- File formats: CSV, JSON, Parquet, Avro, ORC, XML
3. Classifiers
Classifier xác định schema của data:
| Classifier Type | Mô tả |
|---|---|
| Built-in | CSV, JSON, Avro, XML, Parquet, ORC |
| JDBC | Cho relational databases |
| Grok | Custom patterns (tương tự Logstash) |
| XML | Dùng row tag |
4. Connections
Connection lưu thông tin kết nối đến data store:
5. ETL Jobs
Job chứa business logic để ETL data:
6. DynamicFrame
DynamicFrame là abstraction của AWS Glue (khác với Spark DataFrame):
Ưu điểm DynamicFrame:
- Xử lý semi-structured data dễ dàng
- Schema flexibility cho dirty data
- Built-in transforms:
ApplyMapping,DropFields,ResolveChoice
7. Triggers
Trigger kích hoạt ETL jobs:
| Trigger Type | Mô tả | Use Case |
|---|---|---|
| Scheduled | Chạy theo cron expression | Daily/weekly ETL |
| On-demand | Chạy manual | Testing, ad-hoc |
| Event-based | Kích hoạt bởi event | S3 upload → ETL |
| Conditional | Chạy khi job khác hoàn thành | Job chaining |
8. Workflows
Workflow orchestrate multiple crawlers, jobs, và triggers:
AWS Glue Studio
Glue Studio là giao diện visual để tạo ETL jobs:
Tính năng Glue Studio:
- Visual ETL - Drag & drop để tạo pipeline
- Auto-generated scripts - Tự động sinh PySpark code
- Schema preview - Xem schema ở mỗi step
- Data preview - Sample data ở mỗi transform
- Job monitoring - Track job runs trong cùng interface
AWS Glue DataBrew
AWS Glue DataBrew là dịch vụ visual data preparation giúp làm sạch, chuẩn hóa và biến đổi dữ liệu với giao diện point-and-click, không cần viết code.
Khi nào nên dùng DataBrew?
| Nhu cầu | DataBrew fit? | Ghi chú |
|---|---|---|
| Data engineer + business analyst cùng chuẩn bị dữ liệu | ✅ | Workflow trực quan, dễ cộng tác |
| Cần chuẩn hóa dữ liệu nhanh (null handling, datetime, dedup, normalize text) | ✅ | Dùng recipe steps thay vì code |
| Cần data profiling trước khi transform | ✅ | Có profile job và thống kê theo cột |
| Cần custom ETL logic phức tạp bằng Spark code | ⚠️ | Nên dùng Glue Studio/Glue ETL jobs |
Core Concepts (DataBrew)
| Thành phần | Mô tả |
|---|---|
| Project | Workspace tương tác để chuẩn bị dữ liệu |
| Dataset | Tập dữ liệu nguồn (S3, Glue Data Catalog, JDBC...) |
| Recipe | Danh sách các bước transform có thể lưu và tái sử dụng |
| Job | Job chạy recipe hoặc chạy data profile |
| Data lineage | Theo dõi nguồn gốc và luồng biến đổi dữ liệu |
| Data profile | Tóm tắt chất lượng dữ liệu theo cột (distribution, nulls, data type...) |
Pattern thực tế: S3 Data Lake (Parquet) + DataBrew
DataBrew vs Glue Studio (chọn nhanh)
| Tiêu chí | DataBrew | Glue Studio |
|---|---|---|
| Mục tiêu chính | Data preparation không code | ETL pipeline/engineering |
| Người dùng chính | Analyst + Data Engineer | Data Engineer |
| Cách làm việc | Recipe-based, point-and-click | Visual nodes + generated Spark script |
| Phù hợp nhất khi | Cần profiling + chuẩn hóa nhanh + chia sẻ logic | Cần orchestrated ETL jobs phức tạp |
Nguồn chính thức (AWS):
- Core concepts and terms in AWS Glue DataBrew
- Connecting to data with AWS Glue DataBrew
- Supported file types and integrations
- Getting started with AWS Glue DataBrew
- AWS Prescriptive Guidance: AWS Glue DataBrew
AWS Glue Features
Data Discovery & Organization
| Feature | Mô tả |
|---|---|
| Data Catalog | Centralized metadata repository |
| Crawlers | Tự động discover và catalog data |
| 70+ connectors | Kết nối nhiều data sources |
| Schema Registry | Quản lý và versioning schemas |
Data Transformation
| Feature | Mô tả |
|---|---|
| Visual ETL | Glue Studio visual editor |
| Spark ETL | Distributed processing |
| Streaming ETL | Real-time data processing |
| FindMatches ML | Deduplicate và fuzzy matching |
| Sensitive Data Detection | Tự động detect PII |
Data Pipeline
| Feature | Mô tả |
|---|---|
| Auto-scaling | Scale workers theo workload |
| Event triggers | Event-driven ETL |
| Workflows | Orchestrate complex pipelines |
| Job Bookmarks | Track processed data (incremental) |
Job Bookmarks (Incremental Processing)
Job Bookmark giúp xử lý incremental data:
Enable Job Bookmark:
Streaming ETL
AWS Glue Streaming xử lý real-time data:
Use cases:
- Real-time log analytics
- IoT data ingestion
- Fraud detection
- Live dashboards
Worker Types & Pricing
Worker Types
| Worker Type | vCPU | Memory | Disk | Use Case |
|---|---|---|---|---|
| Standard | 4 | 16 GB | 50 GB | General ETL |
| G.1X | 4 | 16 GB | 64 GB | Memory-efficient |
| G.2X | 8 | 32 GB | 128 GB | ML, complex transforms |
| G.4X | 16 | 64 GB | 256 GB | Large datasets |
| G.8X | 32 | 128 GB | 512 GB | Very large datasets |
Memory-Optimized (cho ML workloads)
| Worker Type | vCPU | Memory | Disk |
|---|---|---|---|
| R.1X | 4 | 32 GB | 64 GB |
| R.2X | 8 | 64 GB | 128 GB |
| R.4X | 16 | 128 GB | 256 GB |
| R.8X | 32 | 256 GB | 512 GB |
Pricing Model
So sánh với các dịch vụ khác
AWS Glue vs Other ETL Services
| Feature | AWS Glue | AWS Data Pipeline | Amazon EMR |
|---|---|---|---|
| Type | Serverless ETL | Managed workflow | Managed Hadoop/Spark |
| Scaling | Automatic | Manual | Manual/Auto |
| Management | Fully managed | AWS managed | Self-managed cluster |
| Data Catalog | Built-in | ❌ | Use Glue Catalog |
| Cost model | Pay per use | Per activity | Per instance-hour |
| Best for | ETL pipelines | Data movement | Big data processing |
Khi nào dùng AWS Glue?
| Scenario | Recommendation |
|---|---|
| Serverless ETL cần scale tự động | ✅ AWS Glue |
| Simple data movement S3 ↔ RDS | Consider Data Pipeline |
| Complex ML + Spark with custom control | Consider EMR |
| Need central metadata catalog | ✅ AWS Glue Data Catalog |
| Visual ETL development | ✅ AWS Glue Studio |
| Code-free data prep + profiling + recipe sharing | ✅ AWS Glue DataBrew |
| Real-time streaming ETL | ✅ AWS Glue Streaming |
Ví dụ thực tế: E-commerce Data Pipeline
Code Examples
PySpark ETL Job
Crawler CLI
Best Practices
Performance
| Practice | Mô tả |
|---|---|
| Partition data | Partition theo date/time để tăng performance |
| Use Parquet/ORC | Columnar formats cho analytics workloads |
| Enable Job Bookmarks | Incremental processing, tránh xử lý lại |
| Right-size workers | Chọn worker type phù hợp với workload |
| Use pushdown predicates | Filter tại source để giảm data transfer |
Cost Optimization
| Practice | Mô tả |
|---|---|
| Auto-scaling | Enable auto-scaling để tối ưu resources |
| Timeout settings | Set job timeout để tránh runaway jobs |
| Development Endpoints | Dùng Interactive Sessions thay vì Dev Endpoints |
| Monitor DPU usage | Theo dõi và optimize DPU consumption |
Security
| Practice | Mô tả |
|---|---|
| IAM Roles | Least privilege cho Glue service role |
| Encryption | Enable encryption at rest và in transit |
| VPC | Chạy jobs trong VPC cho data sources private |
| Data Catalog security | Dùng Lake Formation cho fine-grained access |
Tích hợp với các dịch vụ AWS
Tổng kết
| Component | Mục đích |
|---|---|
| Data Catalog | Central metadata store |
| Crawlers | Auto-discover schemas |
| ETL Jobs | Transform data (Spark/Python/Ray) |
| Glue Studio | Visual ETL development |
| Glue DataBrew | Code-free data preparation + profiling |
| Triggers | Schedule/event-based execution |
| Workflows | Orchestrate complex pipelines |
| Job Bookmarks | Incremental processing |
| Streaming | Real-time ETL |
[!IMPORTANT] AWS Glue là lựa chọn tốt khi:
- Cần serverless ETL không quản lý infrastructure
- Muốn central metadata catalog cho data lake
- Cần tích hợp với Athena, Redshift, EMR
- Muốn visual ETL development với Glue Studio