Bài này gộp 3 chủ đề: Monitoring và Logging, EventBridge và Automation, CI/CD và DevOps trên AWS.
Mục tiêu học tập
- Nắm các thành phần CloudWatch (metrics, logs, alarms, dashboards) và pattern subscription filter
- Phân biệt CloudTrail (ai làm gì) vs Config (trạng thái cấu hình) vs X-Ray (trace request)
- Thiết kế centralized logging multi-account ở mức Professional
- 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
- Nắm chuỗi Developer Tools (CodeBuild/CodeDeploy/CodePipeline) và vai trò CodeConnections với Git provider bên ngoài
- Phân biệt các deployment strategy (rolling, blue/green, canary) theo trade-off
- Biết pattern multi-account pipeline và IaC selection ở mức Professional
Phần 1: Monitoring và Logging
1. CloudWatch Deep Dive
2. CloudWatch Logs Architecture
3. X-Ray
Distributed Tracing:
- Trace requests across services
- Service map visualization
- Performance bottleneck identification
Components:
- X-Ray SDK (in application)
- X-Ray Daemon (collects and sends traces)
- X-Ray Console (analysis)
Sampling:
- First request each second: traced
- 5% of additional requests: traced
- Custom sampling rules available
4. CloudTrail
5. AWS Config
6. AWS Health (Personal Health Dashboard)
Monitoring không chỉ là metric/log của workload — còn phải biết khi chính AWS có sự cố hoặc lên lịch bảo trì ảnh hưởng tài nguyên của bạn. Đó là việc của AWS Health.
6.1. Hai góc nhìn của AWS Health Dashboard
| Service health | Your account health | |
|---|---|---|
| Tên cũ | Service Health Dashboard (SHD) | Personal Health Dashboard (PHD) |
| Phạm vi | Trạng thái chung của mọi service/region, public, không cần đăng nhập | Sự kiện ảnh hưởng tài nguyên CỦA BẠN (cá nhân hoá theo account) |
| Nội dung | Service đang operational/degraded ở region nào | Scheduled changes (EC2 instance retirement, maintenance EBS/RDS), service issues đang tác động resource cụ thể |
| Chi tiết | Không biết bạn có bị ảnh hưởng hay không | Timeline sự kiện + danh sách affected resources (instance ID, volume ID...) |
Đề thi hỏi "how to know if your resources are affected by an AWS event" → Your account health (PHD), không phải trang status public.
6.2. AWS Health API và organizational view
- AWS Health API: truy cập programmatic vào các health event — yêu cầu Business hoặc Enterprise Support plan (điểm hay bị gài trong đề).
- Organizational view: bật ở management account (hoặc delegated administrator) → gom health event của toàn bộ member account trong Organization về một chỗ. Pattern chuẩn cho ops team trung tâm theo dõi sự cố/bảo trì trên hàng trăm account mà không phải đăng nhập từng account.
6.3. Automation với EventBridge
AWS Health phát event vào EventBridge (source aws.health) → rule → target tự động hoá:
Ví dụ kinh điển hay thi: AWS lên lịch retire host vật lý → event EC2 instance scheduled for retirement xuất hiện trong PHD → EventBridge rule bắt event → Lambda stop rồi start instance (EBS-backed) để nó được đặt lên host mới trước deadline, thay vì chờ AWS cưỡng chế. SNS song song để notify on-call.
6.4. Exam keywords
- "be notified when AWS schedules maintenance on YOUR resources" → AWS Health (Your account health / PHD) + EventBridge → SNS. Không phải CloudWatch metric — retirement/maintenance không phải là metric của workload.
- "automate response to instance retirement" → AWS Health event + EventBridge rule + Lambda (stop/start).
- "aggregate health events across all accounts in the Organization" → AWS Health organizational view (delegated admin, cần Business/Enterprise Support cho Health API).
7. Resilience, Incident Response và Quota Automation
Domain 3 (Continuous Improvement) không dừng ở "có metric và log". Đề hỏi về kiểm chứng khả năng chịu lỗi, điều phối khi sự cố, và tự động xử lý giới hạn dịch vụ.
| Service | Làm gì | Keyword đề thi |
|---|---|---|
| CloudWatch Contributor Insights | Rule đọc log group (JSON/CLW format) và tính top-N contributor theo thời gian thực: IP gọi nhiều nhất, URL lỗi nhiều nhất, DynamoDB partition key nóng nhất | "identify which clients/keys generate the most traffic/errors" → Contributor Insights, không phải Logs Insights (query ad hoc) |
| AWS Resilience Hub | Khai báo RTO/RPO policy cho ứng dụng (từ CloudFormation/Terraform/Resource Group), Resilience Hub đánh giá kiến trúc, chấm điểm, gợi ý (thêm AZ, bật backup, Multi-AZ) và sinh alarm/SOP/FIS experiment | "assess whether the application meets RTO/RPO targets and get recommendations" |
| AWS Fault Injection Service (FIS) | Chaos engineering có kiểm soát: experiment template (stop EC2, throttle API, mất AZ, network latency), stop condition gắn CloudWatch alarm để tự dừng khi vượt ngưỡng | "validate resilience by injecting failures in a controlled manner" |
| Amazon Application Recovery Controller (ARC) (tên cũ Route 53 ARC) | Routing control: công tắc on/off cho từng cell/Region, đổi trạng thái qua cluster 5 endpoint ở 5 Region (data plane có HA cao) → failover thủ công, có kiểm soát; zonal shift / zonal autoshift rút traffic khỏi AZ lỗi; Region switch điều phối failover cả ứng dụng sang Region khác theo plan. Readiness check không còn nhận khách mới. | "fail over between Regions in a controlled, operator-initiated way during a large-scale event" → ARC routing control / Region switch; "shift traffic away from an impaired AZ" → zonal shift |
| Incident Manager + OpsCenter (Systems Manager) | OpsCenter gom OpsItem từ CloudWatch alarm/EventBridge/Config; Incident Manager tạo response plan: escalation, on-call schedule, chat channel, runbook Automation chạy tự động khi alarm. Incident Manager không còn nhận khách mới — đề thi vẫn có thể hỏi; khách mới dùng OpsCenter + Automation hoặc công cụ on-call khác | "automatically engage on-call responders and run a runbook when a critical alarm fires" |
| Service Quotas automation | Service Quotas publish metric usage lên CloudWatch → alarm khi ≥ 80% quota → EventBridge/Lambda gọi RequestServiceQuotaIncrease; Quota request template để account mới trong org tự xin quota khi tạo | "proactively avoid hitting service limits across new accounts" → quota request template + alarm, không phải Trusted Advisor thủ công |
Phân biệt hay thi: Trusted Advisor chỉ báo service limit (một phần check), Service Quotas mới có API xin tăng và metric để alarm; Logs Insights là query khi cần, Contributor Insights là rule chạy liên tục cho top-N; Route 53 health check failover là tự động (health check và trả lời DNS chạy trên data plane của Route 53) nhưng quyết định do health check đưa ra, dễ flapping khi sự cố một phần; ARC routing control cho operator chủ động failover qua cluster 5 Region, hợp với sự cố lớn cần kiểm soát.
Phần 2: EventBridge và Automation
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
Phần 3: CI/CD và DevOps trên AWS
Tổng quan CI/CD
AWS Developer Tools
1. Source control: CodeCommit hoặc GitHub/GitLab/Bitbucket qua CodeConnections
Cập nhật trạng thái CodeCommit (quan trọng cho đề 2026): tháng 07/2024 AWS ngừng nhận khách hàng mới cho CodeCommit, nhưng ngày 24/11/2025 AWS công bố CodeCommit trở lại General Availability và mở lại đăng ký cho khách hàng mới (The Future of AWS CodeCommit). Vì vậy KHÔNG loại một đáp án chỉ vì nó có CodeCommit. Chọn theo yêu cầu của đề: cần repo Git do AWS quản lý, phân quyền bằng IAM, truy cập qua VPC endpoint, log CloudTrail, không phụ thuộc bên thứ ba thì chọn CodeCommit; code đã nằm ở GitHub, GitLab hoặc Bitbucket thì nối vào CodePipeline/CodeBuild qua AWS CodeConnections (tên cũ: CodeStar Connections). Câu hỏi soạn trong giai đoạn 07/2024-11/2025 có thể vẫn coi CodeCommit là legacy, nên luôn đọc yêu cầu thay vì chọn theo tên dịch vụ.
2. AWS CodeBuild
buildspec.yml Example:
version: 0.2
phases:
install:
runtime-versions:
nodejs: 18
pre_build:
commands:
- npm install
build:
commands:
- npm run build
- npm test
post_build:
commands:
- echo "Build completed"
artifacts:
files:
- '**/*'
base-directory: dist
cache:
paths:
- node_modules/**/*
3. AWS CodeDeploy
appspec.yml (EC2):
version: 0.0
os: linux
files:
- source: /
destination: /var/www/html
hooks:
BeforeInstall:
- location: scripts/before_install.sh
AfterInstall:
- location: scripts/after_install.sh
ApplicationStart:
- location: scripts/start.sh
ValidateService:
- location: scripts/validate.sh
4. AWS CodePipeline
Deployment Strategies Deep Dive
1. Rolling Deployment
2. Blue/Green Deployment
3. Canary Deployment
Infrastructure as Code
AWS CloudFormation
AWS CDK (Cloud Development Kit)
Terraform on AWS
CodeGuru
CodeGuru Reviewer
CodeGuru Profiler
Exam Scenarios
Scenario 1: Zero-Downtime Deployment
Scenario 2: Multi-Account Pipeline
Scenario 3: Container CI/CD
Quick Reference
CloudFormation Custom Resources & Resource Import
Custom Resources — chạy logic CloudFormation không hỗ trợ
Khi stack cần làm việc mà CloudFormation không có resource type tương ứng, dùng Custom Resource: một resource "ảo" mà lifecycle (Create/Update/Delete) được xử lý bởi code của bạn — Lambda-backed (phổ biến nhất) hoặc SNS-backed (gửi event tới topic, thường cho hệ thống on-premises/bên ngoài xử lý).
Cơ chế:
- Template khai báo
Custom::<Tên>(hoặcAWS::CloudFormation::CustomResource) với thuộc tính bắt buộcServiceTokentrỏ tới Lambda ARN (hoặc SNS topic ARN). - Khi stack Create/Update/Delete, CFN invoke Lambda với event chứa
RequestType(Create/Update/Delete),ResourceProperties, vàResponseURL— một pre-signed S3 URL. - Lambda PHẢI gửi response (SUCCESS/FAILED) về
ResponseURL— dùng modulecfn-response(có sẵn khi viết inline code) hoặc thư việncrhelper. Quên gửi response = stack treo ởCREATE_IN_PROGRESS/DELETE_IN_PROGRESScho tới hếtServiceTimeout(mặc định 3600 giây = 1 giờ, đặt được từ 1 đến 3600 giây) rồi mới FAILED — lỗi kinh điển. ĐặtServiceTimeoutngắn (vd 300) khi Lambda chỉ cần vài giây để phát hiện lỗi sớm.
Use case kinh điển trên đề:
- Empty S3 bucket trước khi delete stack — CFN không xoá được bucket còn object; custom resource nhận event
Delete→ xoá hết object (kể cả version) → bucket xoá được. (Từ 2023AWS::S3::Bucketkhông có thuộc tính auto-empty; custom resource vẫn là đáp án chuẩn.) - Gọi API bên thứ ba trong lúc provision (đăng ký license, tạo record ở SaaS, lookup AMI ID mới nhất...).
- Provision resource CFN chưa hỗ trợ (service mới, tính năng mới chưa có resource type).
Snippet YAML (Lambda-backed, empty bucket on delete):
Resources:
MyBucket:
Type: AWS::S3::Bucket
EmptyBucketOnDelete:
Type: Custom::EmptyBucket
Properties:
ServiceToken: !GetAtt EmptyBucketFunction.Arn # Lambda ARN — bắt buộc
BucketName: !Ref MyBucket
# Trong Lambda handler (rút gọn)
import cfnresponse
def handler(event, context):
if event['RequestType'] == 'Delete':
empty_bucket(event['ResourceProperties']['BucketName'])
cfnresponse.send(event, context, cfnresponse.SUCCESS, {}) # BẮT BUỘC
Lưu ý Professional: với nhu cầu tái sử dụng nhiều account/nhiều team, cân nhắc nâng cấp custom resource thành CloudFormation Registry private resource type / hook — nhưng khi đề chỉ hỏi "one-off logic trong stack", custom resource là đáp án gọn nhất.
Resource Import — đưa resource tạo thủ công vào stack
Vấn đề: hạ tầng legacy tạo tay (console/CLI) nằm ngoài IaC — muốn quản lý bằng CloudFormation mà không tạo lại (không downtime, không đổi ARN).
Giải pháp: Resource Import (cloudformation import, console: Stack actions → Import resources into stack):
- Template phải mô tả resource với identifier thực tế (vd BucketName) và mọi resource được import BẮT BUỘC có
DeletionPolicy(thườngRetain) — đây là điều kiện cứng của import operation. - Resource type phải hỗ trợ import (đa số resource phổ biến đều hỗ trợ).
- Import vào stack mới hoặc stack đang có đều được; import không thay đổi resource — chỉ gắn vào stack.
- Best practice sau import: chạy Drift Detection ngay để xác nhận template khớp 100% cấu hình thực tế — template viết tay dễ thiếu thuộc tính, drift detection lộ ra chênh lệch trước khi update stack gây thay đổi ngoài ý muốn.
Use case: chuẩn hoá hạ tầng legacy vào IaC theo lộ trình (governance, review qua change set) mà không cần migration/tạo lại resource.
Exam keywords
| Keyword trên đề | Đáp án |
|---|---|
| "Delete stack fails because S3 bucket is not empty" | Lambda-backed custom resource empty bucket khi nhận event Delete |
| "Provision resource/call API CloudFormation doesn't support" | Custom resource (ServiceToken → Lambda/SNS) |
| "Bring existing resources under CloudFormation management without recreating" | Resource Import (+ DeletionPolicy bắt buộc, drift detection sau import) |
| "Stack stuck in CREATE_IN_PROGRESS with custom resource" | Lambda quên gửi cfn-response về pre-signed URL |
EC2 Image Builder
Bài toán: tổ chức cần golden image (AMI/container image đã hardened, cài sẵn agent, patch mới nhất) build lại định kỳ và phân phối cho nhiều region, nhiều account — làm tay bằng Packer/script + Lambda + EventBridge là nhiều moving part. EC2 Image Builder là managed service làm trọn pipeline này.
Thành phần chính:
- Components: bước build (cài software, hardening, patch) và test (validate image trước khi distribute) — viết bằng YAML document, AWS có sẵn nhiều managed component (vd
update-linux, STIG hardening, Inspector test). - Image recipe (AMI) / container recipe (Docker image cho ECR): base image + danh sách components + version.
- Infrastructure configuration: instance type, subnet, IAM instance profile dùng để build/test.
- Distribution configuration: copy AMI sang nhiều region, share cross-account (launch permission cho account/OU, hoặc qua AWS RAM / AWS Organizations), gắn license configuration, output alias ECR cho container.
- Pipeline + schedule: chạy theo cron (vd hàng tháng khi có patch) hoặc khi dependency có bản mới (semantic versioning trên base image/component) — golden image luôn mới mà không cần chạm tay.
Điểm Professional cần nhớ:
- Build instance cần Systems Manager Agent — Image Builder điều khiển build qua SSM (base image AWS đã có sẵn SSM Agent; Image Builder tự cài nếu thiếu).
- Miễn phí — chỉ trả tiền tài nguyên bên dưới (EC2 build instance, EBS, S3 log, data transfer/copy AMI).
- Build cả AMI và container image (output ECR).
- Kết hợp: pipeline output AMI mới → EventBridge/SNS notification → update Launch Template version cho ASG, hoặc dùng làm base cho CodePipeline.
Exam keyword: "automate golden AMI creation and distribution across accounts/regions with least operational overhead" → EC2 Image Builder (KHÔNG phải tự viết Packer + Lambda + Step Functions — nhiều operational overhead hơn); "monthly patched AMI shared to all accounts in the organization" → Image Builder pipeline schedule hàng tháng + distribution configuration share qua Organizations/RAM.
Câu hỏi ôn tập
-
CloudTrail vs Config — khác nhau cốt lõi và khi nào dùng cả hai?
Xem đáp án
CloudTrail trả lời "AI đã gọi API gì, khi nào, từ đâu" (audit trail các API call). Config trả lời "resource đang/từng có cấu hình gì, có compliant không" (configuration timeline + rules). Ví dụ security group bị mở 0.0.0.0/0: Config rule phát hiện trạng thái non-compliant (+ auto-remediation), CloudTrail cho biết ai đã gọi
AuthorizeSecurityGroupIngress. Điều tra incident hoàn chỉnh cần cả hai — đề hỏi "who made the change" → CloudTrail; "detect non-compliant configuration + remediate" → Config. -
Subscription filter dùng khi nào thay vì export S3?
Xem đáp án
Subscription filter: stream log near real-time ra Lambda (xử lý ngay), Kinesis Data Streams (multi-consumer), Firehose (đổ S3/OpenSearch) — dùng cho real-time alerting, centralized logging cross-account (destination ở account log trung tâm). Export task sang S3: batch, trễ tới 12 giờ — chỉ cho archive thủ công. Pattern chuẩn multi-account: mỗi account có subscription filter → Kinesis/Firehose ở log-archive account → S3 + Athena phân tích.
-
Composite alarm giải quyết vấn đề gì?
Xem đáp án
Kết hợp nhiều alarm bằng AND/OR để giảm alarm noise: chỉ báo khi (CPU cao AND latency cao), hoặc suppress alarm con khi có maintenance alarm. Use case Professional: hàng trăm microservices — thay vì on-call nhận 50 alert khi 1 AZ lỗi, composite alarm gom thành 1 alert "AZ degradation". Actions vẫn là SNS/Auto Scaling như metric alarm thường.
-
CloudTrail organization trail có lợi thế gì so với trail từng account?
Xem đáp án
Tạo một lần ở management account (hoặc delegated administrator) → tự động áp cho mọi member account kể cả account mới join, member không tắt được — đảm bảo audit coverage 100% không phụ thuộc từng team. Log đổ về một S3 bucket trung tâm (thường ở log-archive account) với log file validation + KMS. Đây là đáp án chuẩn cho "ensure all accounts in Organization log API activity, prevent tampering".
-
AWS thông báo một EC2 instance "scheduled for retirement" — làm sao được notify và tự động xử lý trước deadline?
Xem đáp án
Sự kiện này xuất hiện trong AWS Health Dashboard – Your account health (Personal Health Dashboard) dưới dạng scheduled change, kèm affected resources — không phải CloudWatch metric nên alarm thường không bắt được. Giải pháp: EventBridge rule match
source = aws.health,eventTypeCode = AWS_EC2_INSTANCE_RETIREMENT_SCHEDULED→ target SNS (notify ops) + Lambda tự động stop → start instance (EBS-backed) để nó chuyển sang host mới trước deadline. Cần gom event toàn Organization → bật organizational view với delegated administrator (Health API yêu cầu Business/Enterprise Support). -
Ứng dụng multi-Region cần failover sang Region phụ theo quyết định của operator trong một sự cố diện rộng, không để health check tự động flapping. Dùng gì?
Xem đáp án
Amazon Application Recovery Controller (ARC) — routing control (hoặc Region switch để điều phối cả ứng dụng): trạng thái on/off được đổi qua cluster gồm 5 endpoint ở 5 Region, gắn với health check của Route 53 nên DNS chuyển ngay khi operator lật công tắc; thao tác này không cần sửa DNS record (vốn là control plane). Health check failover thông thường (Tuần 2 Ngày 4) cũng chạy trên data plane nhưng tự động theo health check, khó kiểm soát khi sự cố một phần. Trong Region, dùng zonal shift để rút traffic khỏi AZ lỗi. Lưu ý: readiness check của ARC không còn nhận khách mới.
-
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.
- Trên đề 2026, khi nào chọn CodeCommit và khi nào chọn GitHub/GitLab/Bitbucket + CodeConnections?
Xem đáp án
CodeCommit từng ngừng nhận khách hàng mới (07/2024) nhưng đã trở lại General Availability từ 24/11/2025, nên không còn là đáp án bị loại mặc định. Chọn CodeCommit khi đề cần repo Git do AWS quản lý: phân quyền IAM, truy cập private qua VPC endpoint, log CloudTrail, không phụ thuộc nhà cung cấp ngoài. Chọn GitHub/GitLab/Bitbucket + AWS CodeConnections (tên cũ CodeStar Connections) khi code đã nằm ở các nền tảng đó: connection quản lý bằng IAM, không lưu credentials trong pipeline. Khác với cặp SMS → MGN (SMS đã ngừng hẳn), CodeCommit là dịch vụ đang được hỗ trợ đầy đủ.
- Blue/Green khác Canary ở trade-off nào?
Xem đáp án
Blue/Green: chuyển 100% traffic một lần sau khi test Green — rollback tức thì (switch ngược), nhưng tốn gấp đôi infrastructure trong lúc deploy và lỗi (nếu lọt qua test) ảnh hưởng toàn bộ user. Canary: đưa 10% traffic vào version mới, monitor rồi tăng dần — phát hiện lỗi sớm với blast radius nhỏ, nhưng cần routing + monitoring phức tạp hơn và deploy lâu hơn. Lambda dùng canary/linear qua alias traffic shifting; ECS blue/green qua CodeDeploy + ALB.
- Multi-account pipeline (dev → staging → prod) cần những mảnh ghép nào?
Xem đáp án
(1) CodePipeline ở account trung tâm (tooling/shared services), (2) cross-account IAM roles cho deploy action assume vào từng account đích, (3) artifact bucket + KMS key cho phép account đích đọc (bucket policy + key policy), (4) manual approval gate trước prod, (5) CloudFormation StackSets nếu deploy hạ tầng chuẩn hoá nhiều account. Bẫy hay gặp: quên grant KMS key cross-account → deploy fail dù role đúng.
- CodeDeploy hỗ trợ những compute target nào và chiến lược tương ứng?
Xem đáp án
(1) EC2/on-premises: in-place (theo deployment config: OneAtATime, HalfAtATime, AllAtOnce) hoặc blue/green với ASG mới; hooks trong appspec.yml. (2) ECS: blue/green qua ALB target groups (task set mới, test listener, switch). (3) Lambda: canary (10% rồi 100%) hoặc linear (10% mỗi X phút) qua alias — kèm alarms + hooks (BeforeAllowTraffic/AfterAllowTraffic) để auto-rollback. Chọn theo compute của đề bài — không có "CodeDeploy cho S3 static site" (đó là pipeline + S3 deploy action).
- Delete stack fail vì S3 bucket còn object — giải quyết thế nào bằng CloudFormation? Nếu muốn đưa một bucket tạo tay vào stack thì sao?
Xem đáp án
Bucket not empty: CloudFormation không xoá được bucket còn object → dùng Lambda-backed custom resource (Custom::EmptyBucket với ServiceToken trỏ Lambda ARN); Lambda nhận event Delete, xoá hết object (kể cả version) rồi bắt buộc gửi response (cfn-response) về pre-signed S3 URL — quên gửi = stack treo tới timeout. Bucket tạo tay: dùng Resource Import (cloudformation import) — template mô tả bucket đúng cấu hình thực tế và phải có DeletionPolicy; import không tạo lại/không đổi resource, sau import chạy drift detection để xác nhận template khớp thực tế.
- Yêu cầu "golden AMI patch hàng tháng, phân phối mọi region và mọi account trong Organization, least operational overhead" — chọn gì và vì sao không tự dựng?
Xem đáp án
EC2 Image Builder: pipeline managed build → test → distribute; image recipe (base image + build/test components), schedule cron hàng tháng (hoặc trigger khi base image có version mới), distribution configuration copy AMI multi-region + share cross-account qua AWS RAM/Organizations. Build qua SSM Agent, service miễn phí (chỉ trả EC2/EBS/S3 lúc build). Tự dựng Packer + Lambda + EventBridge + script copy/share AMI cũng ra kết quả nhưng nhiều operational overhead hơn — sai keyword của đề. Image Builder cũng build được container image ra ECR.
Bài tập thực hành
Phần 1: Monitoring và Logging
-
Metric filter + alarm: tạo metric filter đếm pattern
ERRORtrong log group của một Lambda, gắn alarm ngưỡng ≥ 5 lỗi/5 phút gửi SNS email; bơm lỗi thử để verify. -
Subscription filter cross-account: tạo CloudWatch Logs destination (Kinesis) ở account B, subscription filter ở account A trỏ sang; verify log event chảy cross-account — đây là xương sống của centralized logging.
-
Config rule + timeline: bật Config recorder, deploy managed rule
encrypted-volumes; tạo EBS volume không mã hoá và xem resource timeline chuyển NON_COMPLIANT. -
X-Ray tracing: bật Active tracing trên 1 Lambda sau API Gateway, gọi vài request và đọc service map để tìm bottleneck.
Phần 2: EventBridge và Automation
-
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.
Phần 3: CI/CD và DevOps trên AWS
-
Pipeline GitHub → CodeBuild → S3: tạo CodeConnections connection tới GitHub repo cá nhân, dựng CodePipeline 3 stage (Source → Build → Deploy S3 static site); push commit và xem pipeline tự chạy.
-
Lambda canary deployment: deploy Lambda có alias
live, cấu hình CodeDeployCanary10Percent5Minuteskèm CloudWatch alarm error rate; deploy version lỗi có chủ đích và quan sát auto-rollback. -
Blue/Green ECS: với service ECS từ bài tuần 5, tạo CodeDeploy application blue/green qua ALB 2 target groups; deploy image mới và thử rollback thủ công trước khi hết thời gian chờ terminate.
Tài liệu tham khảo
- Amazon CloudWatch User Guide
- AWS CloudTrail User Guide
- AWS X-Ray Developer Guide
- VPC Flow Logs
- AWS Health User Guide
- CloudWatch Contributor Insights
- AWS Resilience Hub
- AWS Fault Injection Service
- Amazon Application Recovery Controller (ARC)
- ARC readiness check — không nhận khách mới
- Incident Manager (không nhận khách mới)
- Service Quotas — CloudWatch alarms
- Amazon EventBridge User Guide
- AWS Systems Manager
- AWS Step Functions
- AWS::CloudFormation::CustomResource — ServiceTimeout
- AWS CodePipeline User Guide
- AWS CodeBuild User Guide
- AWS CodeDeploy User Guide
- AWS CloudFormation User Guide
- CloudFormation Custom Resources
- Import existing resources into a CloudFormation stack
- EC2 Image Builder User Guide