Mục tiêu học tập
- Hiểu EventBridge event bus, rules, targets và event pattern matching
- Nắm các module Systems Manager phục vụ automation (Patch, Session, Run Command, Automation)
- So sánh các lựa chọn IaC (CloudFormation, CDK, Terraform) theo scenario
1. Amazon EventBridge
2. Event Patterns
{
"source": ["aws.ec2"],
"detail-type": ["EC2 Instance State-change Notification"],
"detail": {
"state": ["stopped", "terminated"]
}
}
3. AWS Systems Manager
4. Infrastructure as Code
CloudFormation:
- Native AWS
- JSON/YAML templates
- StackSets for multi-account/region
AWS CDK:
- Code-first approach
- TypeScript, Python, Java, C#
- Generates CloudFormation
Terraform:
- Multi-cloud
- HCL language
- State management
5. Câu hỏi ôn tập
-
EventBridge khác SNS ở những điểm nào khi làm event routing?
Xem đáp án
EventBridge: content-based filtering trên toàn bộ event payload (pattern matching), 130+ SaaS/AWS sources, schema registry, archive + replay, input transformation, cross-account event bus. SNS: pub/sub đơn giản, filter theo message attributes, fan-out tới hàng triệu subscriber (gồm email/SMS/mobile push), latency thấp hơn và throughput cao hơn. Lưu ý Professional: EventBridge không đảm bảo ordering và delivery là at-least-once — cần ordering thì dùng SNS FIFO/SQS FIFO. Keyword "route events from SaaS app" hoặc "filter theo nội dung event phức tạp" → EventBridge.
-
Session Manager thay SSH như thế nào và vì sao "most secure"?
Xem đáp án
Session Manager cho shell access không cần mở port 22, không bastion host, không SSH key — instance chỉ cần SSM Agent + IAM role, kết nối outbound tới SSM endpoints (qua VPC endpoint cho private subnet). Quyền kiểm soát bằng IAM policy (ai vào instance nào), session được log đầy đủ vào CloudTrail + S3/CloudWatch Logs (audit từng lệnh). Đáp án chuẩn cho "secure shell access, no inbound ports, full audit trail".
-
Patch tự động fleet EC2 multi-account dùng gì?
Xem đáp án
Patch Manager với patch baseline + maintenance window; scale multi-account/multi-region bằng Systems Manager Automation + AWS Organizations integration (target OUs) hoặc Quick Setup. Pattern đầy đủ: EventBridge schedule → SSM Automation runbook → Run Command patch theo tag, report compliance về SSM Compliance + Security Hub. Đề bài "automate patching across all accounts with least operational overhead" → Patch Manager + Organizations, không phải tự viết script/Lambda.
-
Khi nào chọn StackSets thay vì stack thường?
Xem đáp án
StackSets deploy cùng một template tới nhiều account/region từ một điểm quản lý — với service-managed permissions tích hợp Organizations, tự deploy vào account mới join OU (auto-deployment). Use case: baseline security (Config rules, IAM roles, GuardDuty) cho toàn Organization. Stack thường chỉ trong 1 account/region. Keyword "deploy IAM roles to every account in the Organization automatically" → StackSets service-managed.
6. Bài tập thực hành
-
EventBridge rule tự động hoá: tạo rule bắt event
EC2 Instance State-change Notificationstatestopped, target Lambda gắn tagstopped-atcho instance; stop một instance và verify. -
Session Manager không SSH: launch EC2 private subnet không key pair, gắn role
AmazonSSMManagedInstanceCore, kết nối bằng Session Manager và bật session logging vào CloudWatch Logs. -
SSM Automation runbook: chạy runbook
AWS-RestartEC2Instancetheo schedule EventBridge; sau đó viết runbook custom 2 bước (create AMI → restart) để hiểu cấu trúc document.
Tài liệu tham khảo chính thức
Ngày tiếp theo: CI/CD và DevOps