Ngân hàng đề — AWS Certified Developer Associate
Tìm thấy 1356 câu.
Which solution will meet these requirements?
- A Publish custom metric data to AWS CloudTrail by using the PutMetricData API operation. Classify and collect the metrics. Create graphs and alarms in CloudTrail for the custom metrics.
- B Use the open source client libraries provided by Amazon to generate the logs in the Amazon CloudWatch embedded metric format. Use CloudWatch to create the required graphs and alarms for the custom metrics.
- C Use Amazon CloudWatch Logs Insights to create custom metrics by querying the logs that come from the Lambda function. Use CloudWatch to create the required graphs and alarms for the custom metrics.
- D Create an Amazon Kinesis data stream to stream log events in real time from Lambda. Specify an Amazon S3 bucket as the destination for the Kinesis data stream. Use Amazon CloudWatch to visualize the log data and to set alarms.
Xem giải thích
🧩 Phân tích nội dung câu hỏi
Câu hỏi xoay quanh một lập trình viên đang sử dụng AWS Lambda để xử lý dữ liệu, và cần trích xuất các metrics tùy chỉnh (custom metrics) về thời gian xử lý (processing times) từ Lambda logs. Yêu cầu chính là:
- Phân tích metrics (analyze the metrics).
- Thiết lập alarms (set alarms).
- Phát hiện vấn đề thời gian thực (detect issues in real time).
🛠️ Thách thức cốt lõi: Lambda tự động gửi logs đến Amazon CloudWatch Logs, nhưng để biến logs thành metrics có thể đo lường, vẽ biểu đồ và đặt alarms real-time, cần một giải pháp tích hợp chặt chẽ, hiệu quả mà không làm phức tạp hóa kiến trúc. Giải pháp phải hỗ trợ embedded metrics để CloudWatch tự động trích xuất và xử lý real-time (dựa trên tính năng mới nhất của AWS CloudWatch đến năm 2026, hỗ trợ Lambda runtime lên đến Python 3.12, Node.js 20, v.v.).
📘 Tài liệu tham khảo:
- AWS Documentation: Using the embedded metric format (cập nhật 2025).
- AWS Lambda Logs and Metrics.
- CloudWatch Embedded Metrics for Lambda.
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng: Use the open source client libraries provided by Amazon to generate the logs in the Amazon CloudWatch embedded metric format. Use CloudWatch to create the required graphs and alarms for the custom metrics.
Lý do chọn 🏆:
- AWS cung cấp open source client libraries (như
aws-embedded-metricscho Python/Node.js/Java, cập nhật mới nhất 2025) để nhúng metrics trực tiếp vào logs dưới định dạng Embedded Metric Format (EMF). - Khi Lambda gửi logs đến CloudWatch Logs, CloudWatch tự động trích xuất metrics thành CloudWatch Metrics, hỗ trợ real-time analysis, graphs (dashboards), alarms mà không cần query thủ công.
- ✅ Hoàn hảo cho real-time: Metrics có độ trễ thấp (<1 phút), dễ detect anomalies về processing times. Tiết kiệm chi phí so với streaming riêng lẻ.
🧪 Giải thích tất cả các phương án (đúng/sai)
Dưới đây là phân tích chi tiết từng lựa chọn. Tôi giữ nguyên văn bản gốc bằng tiếng Anh, đánh dấu ✅/❌, và giải thích hoàn toàn bằng tiếng Việt dựa trên best practices AWS mới nhất:
-
❌ Publish custom metric data to AWS CloudTrail by using the PutMetricData API operation. Classify and collect the metrics. Create graphs and alarms in CloudTrail for the custom metrics.
Sai vì: CloudTrail dùng để ghi audit logs (API calls), KHÔNG hỗ trợ metrics hay PutMetricData (API này thuộc CloudWatch Metrics). Không thể classify metrics hay tạo graphs/alarms trong CloudTrail. Sử dụng sẽ thất bại và không real-time. -
✅ Use the open source client libraries provided by Amazon to generate the logs in the Amazon CloudWatch embedded metric format. Use CloudWatch to create the required graphs and alarms for the custom metrics.
Đúng vì: Như đã giải thích ở phần đáp án. Đây là giải pháp chính thức, optimized cho Lambda logs, hỗ trợ zero-config extraction real-time. Client libraries miễn phí, dễ integrate (ví dụ:metrics.put_metric('ProcessingTime', duration, 'Seconds')). -
❌ Use Amazon CloudWatch Logs Insights to create custom metrics by querying the logs that come from the Lambda function. Use CloudWatch to create the required graphs and alarms for the custom metrics.
Sai vì: Logs Insights tốt cho ad-hoc queries, nhưng KHÔNG real-time (query on-demand, độ trễ cao). Để tạo metrics từ query cần CloudWatch Logs Metric Filters hoặc Contributor Insights, nhưng phức tạp và không tự động embed như EMF. Không phù hợp detect issues real-time. -
❌ Create an Amazon Kinesis data stream to stream log events in real time from Lambda. Specify an Amazon S3 bucket as the destination for the Kinesis data stream. Use Amazon CloudWatch to visualize the log data and to set alarms.
Sai vì: Kinesis + S3 quá phức tạp và tốn kém cho logs (Lambda đã push trực tiếp CloudWatch). S3 là batch storage, KHÔNG real-time. CloudWatch không visualize trực tiếp từ S3 mà cần thêm ETL (như Firehose), không extract metrics processing times dễ dàng.
🛡️ Lời khuyên DevOps: Ưu tiên Embedded Metrics cho Lambda để scale real-time monitoring. Kết hợp với CloudWatch Anomaly Detection (cập nhật 2025) để tự động detect issues! 🚀
“The overall deployment failed because too many individual instances failed deployment, too few healthy instances are available for deployment, or some instances in your deployment group are experiencing problems. (Error code: HEALTH-CONSTRAINTS)”
What are the possible causes of the failed deployment? (Choose two.)
- A The CodeDeploy agent was not running on the instances that CodeDeploy was trying to deploy to.
- B The unified Amazon CloudWatch agent was not running on the instances that CodeDeploy was trying to deploy to.
- C The developer’s IAM role did not have the necessary permissions to perform code deployment to the instances.
- D CodeDeploy was trying to deploy to instances that were attached to an IAM instance profile that did not have the required permissions.
- E CodeDeploy was trying to deploy to instances that were not set up with correct CodeDeploy health checks.
Xem giải thích
🧩 Giải thích nội dung câu hỏi
Câu hỏi tập trung vào việc khắc phục sự cố triển khai (deployment) thất bại trên AWS CodeDeploy. Lỗi cụ thể là HEALTH_CONSTRAINTS, với thông báo:
"The overall deployment failed because too many individual instances failed deployment, too few healthy instances are available for deployment, or some instances in your deployment group are experiencing problems. (Error code: HEALTH-CONSTRAINTS)".
🛠️ Ý nghĩa lỗi này:
- Lỗi xảy ra khi deployment group không đáp ứng được các ràng buộc sức khỏe (health constraints), chẳng hạn như:
- Quá nhiều instance thất bại triển khai (vượt ngưỡng tối đa failure tolerance).
- Không đủ instance healthy để tiếp tục (dựa trên deployment configuration như MinimumHealthyHosts hoặc MinimumStopOnAlarmHosts).
- Một số instance gặp vấn đề, không báo cáo trạng thái đúng cách.
- Developer cần chọn hai nguyên nhân có thể gây ra lỗi này. Đây là câu hỏi kiểu chọn nhiều đáp án đúng (Choose two), kiểm tra kiến thức về troubleshooting CodeDeploy (cập nhật theo AWS docs 2024-2026, không thay đổi lớn ở phiên bản mới).
✅ Đáp án đúng (Chọn hai)
Hai phương án sau là nguyên nhân chính gây lỗi HEALTH_CONSTRAINTS:
- The CodeDeploy agent was not running on the instances that CodeDeploy was trying to deploy to.
- CodeDeploy was trying to deploy to instances that were not set up with correct CodeDeploy health checks.
Lý do chọn:
- Lỗi HEALTH_CONSTRAINTS trực tiếp liên quan đến việc instances không báo cáo trạng thái healthy/successful (do agent không chạy hoặc health checks sai). Nếu agent ngừng, instances không xử lý lifecycle events, dẫn đến timeout/failure, vi phạm health constraints. Health checks (như CloudWatch alarms) nếu sai sẽ làm deployment dừng sớm vì không đủ healthy hosts. Các nguyên nhân khác không khớp với mã lỗi này (theo AWS troubleshooting guide).
📋 Phân tích chi tiết tất cả các phương án
Dưới đây là giải thích từng lựa chọn, giữ nguyên nội dung gốc bằng tiếng Anh. Mỗi phương án được đánh dấu ✅ (đúng) hoặc ❌ (sai), kèm lý do cụ thể dựa trên AWS CodeDeploy behavior:
-
✅ The CodeDeploy agent was not running on the instances that CodeDeploy was trying to deploy to.
Giải thích: Đây là nguyên nhân phổ biến nhất! CodeDeploy agent phải chạy trên EC2 instances để xử lý các lifecycle events (DownloadBundle, BeforeInstall, AfterInstall...). Nếu agent không chạy, instances không báo cáo trạng thái (stuck ở InProgress hoặc Failed), dẫn đến quá nhiều failures và vi phạm health constraints (ví dụ: vượt MinimumHealthyHosts). AWS khuyến nghị kiểm tra agent status đầu tiên khi gặp lỗi này. -
❌ The unified Amazon CloudWatch agent was not running on the instances that CodeDeploy was trying to deploy to.
Giải thích: Sai vì Unified CloudWatch Agent dùng để thu thập metrics/logs (như CPU, memory), không trực tiếp liên quan đến lifecycle của CodeDeploy. CodeDeploy dùng agent riêng của nó để báo cáo deployment status. Nếu thiếu CloudWatch agent, chỉ ảnh hưởng monitoring, không gây HEALTH_CONSTRAINTS (có thể gây lỗi khác như SCRIPT_FAILED nếu dùng hooks). -
❌ The developer’s IAM role did not have the necessary permissions to perform code deployment to the instances.
Giải thích: Sai vì IAM role của developer (user role) chỉ dùng để tạo deployment qua CLI/Console. CodeDeploy dùng service role (như AWSCodeDeployRole) riêng biệt cho permissions deployment. Lỗi permissions ở service role sẽ gây IAM_ROLE_MISSING hoặc ROLE_VALIDATION_FAILED, không phải HEALTH_CONSTRAINTS (chỉ xảy ra sau khi deployment bắt đầu trên instances). -
❌ CodeDeploy was trying to deploy to instances that were attached to an IAM instance profile that did not have the required permissions.
Giải thích: Sai vì instance profile (IAM role gắn vào EC2) cần permissions để pull artifacts từ S3/CodeCommit, nhưng nếu thiếu, lỗi sẽ là AGENT_ISSUE hoặc DOWNLOAD_BUNDLE_FAILED ở lifecycle events cụ thể. HEALTH_CONSTRAINTS chỉ kích hoạt khi có vấn đề tổng thể về số lượng healthy instances, không phải permissions (instances vẫn có thể report failure nếu agent chạy). -
✅ CodeDeploy was trying to deploy to instances that were not set up with correct CodeDeploy health checks.
Giải thích: Đúng! Health checks trong CodeDeploy bao gồm CloudWatch alarms (attached to deployment group) hoặc config như AllAtOnce/OneAtATime. Nếu alarms báo unhealthy (CPU cao, memory low) hoặc MinimumHealthyHosts % quá cao, deployment sẽ fail sớm vì "too few healthy instances". Instances cần setup đúng để tránh vi phạm constraints này.
📘 Tài liệu tham khảo
- AWS CodeDeploy Troubleshooting: Deployment Issue: Health Constraints (cập nhật 2024-2026).
- Deployment Status & Lifecycle Events: CodeDeploy Deployment Statuses.
- Best Practices: AWS Well-Architected Framework - DevOps Pillar (2025 edition), khuyến nghị luôn kiểm tra agent và health checks trước.
- Kiểm tra thực tế: Sử dụng
aws deploy list-deployment-instancesvà CloudTrail logs để verify.
Hy vọng phân tích này giúp bạn ôn thi DOP-C02 hiệu quả! 🚀 Nếu cần ví dụ thực hành, hỏi thêm nhé!
Which solution will meet these requirements with no development effort?
- A Encrypt the environment variables by using AWS Secrets Manager. Set up automatic rotation in Secrets Manager.
- B Encrypt the environment variables by using AWS Key Management Service (AWS KMS) customer managed keys. Enable automatic key rotation.
- C Encrypt the environment variables by using AWS Key Management Service (AWS KMS) AWS managed keys. Configure a custom AWS Lambda function to automate key rotation.
- D Encrypt the environment variables by using AWS Systems Manager Parameter Store. Set up automatic rotation in Parameter Store.
Xem giải thích
🧩 Phân tích nội dung câu hỏi
Câu hỏi tập trung vào việc lưu trữ API keys nhạy cảm dưới dạng environment variables (biến môi trường) cho một ứng dụng serverless (như AWS Lambda, ECS Fargate hoặc các dịch vụ tương tự). Yêu cầu chính là mã hóa (encrypt) các biến này và xoay vòng tự động (automatic rotation) các encryption keys (khóa mã hóa) hàng năm, đồng thời KHÔNG yêu cầu bất kỳ nỗ lực phát triển (no development effort) nào – nghĩa là phải sử dụng tính năng built-in sẵn có, không cần viết code custom như Lambda function.
🛠️ Bối cảnh AWS serverless: Environment variables có thể được mã hóa trực tiếp bằng KMS trong Lambda (từ năm 2018), và các dịch vụ serverless khác hỗ trợ inject secrets từ Secrets Manager/Parameter Store. Tuy nhiên, trọng tâm là rotation của encryption keys (KMS keys), không phải rotation của secret values. Kiến thức cập nhật đến 2026: AWS KMS vẫn hỗ trợ auto rotation cho CMKs (customer managed keys), và Lambda/ECS env vars encrypt hỗ trợ KMS trực tiếp (theo AWS Well-Architected Framework và re:Invent 2024-2025 updates).
✅ Đáp án đúng: Encrypt the environment variables by using AWS Key Management Service (AWS KMS) customer managed keys. Enable automatic key rotation.
Lý do chọn đáp án này (dựa trên phiên bản AWS mới nhất 2026):
- AWS KMS customer managed keys (CMKs) cho phép enable automatic key rotation hàng năm chỉ với một cú click trong console/API – hoàn toàn no development effort (không cần code).
- Rotation tạo key material mới, giữ nguyên key ID/ARN, đảm bảo ứng dụng serverless (như Lambda) không bị gián đoạn khi decrypt env vars.
- Lambda hỗ trợ encrypt env vars trực tiếp bằng KMS CMK (plaintext env vars được encrypt thành ciphertext, runtime tự decrypt).
- Điều này đáp ứng đầy đủ: lưu trữ nhạy cảm, mã hóa env vars, auto rotation encryption keys hàng năm.
🛡️ Ưu điểm: Bảo mật cao, tích hợp native với serverless services, chi phí thấp (~$1/tháng/key + requests).
📋 Phân tích tất cả các phương án
Dưới đây là phân tích chi tiết từng lựa chọn, giữ nguyên nội dung văn bản gốc bằng tiếng Anh. Mỗi phương án được đánh giá đúng/sai với lý do cụ thể dựa trên tính năng AWS hiện tại (2026).
-
Encrypt the environment variables by using AWS Secrets Manager. Set up automatic rotation in Secrets Manager.
❌ Sai: Secrets Manager dùng KMS để mã hóa secrets, nhưng automatic rotation ở đây chỉ xoay vòng giá trị secret (secret values, như API keys) qua Lambda rotator built-in (cho RDS, etc.), KHÔNG phải rotation encryption keys (KMS keys). Không đáp ứng "rotation of encryption keys". Ngoài ra, inject secrets từ Secrets Manager vào env vars Lambda cần cấu hình, nhưng vẫn không giải quyết rotation KMS keys mà không code. -
Encrypt the environment variables by using AWS Key Management Service (AWS KMS) customer managed keys. Enable automatic key rotation.
✅ Đúng: Như đã giải thích ở trên. Enable automatic key rotation trên KMS CMKs là tính năng native, kích hoạt ngay lập tức, xoay vòng key material hàng năm tự động. Hoàn hảo cho env vars encrypted trong Lambda/ECS Fargate (data encrypted at rest, decrypt at runtime). Không cần code, tích hợp trực tiếp. -
Encrypt the environment variables by using AWS Key Management Service (AWS KMS) AWS managed keys. Configure a custom AWS Lambda function to automate key rotation.
❌ Sai: AWS managed keys (do AWS quản lý) KHÔNG hỗ trợ automatic rotation built-in – chỉ manual rotation qua API. Phải viết custom Lambda function để tự động hóa, vi phạm yêu cầu "no development effort". Env vars có thể encrypt bằng AWS managed keys, nhưng rotation không native. -
Encrypt the environment variables by using AWS Systems Manager Parameter Store. Set up automatic rotation in Parameter Store.
❌ Sai: Parameter Store (SecureString) dùng KMS để mã hóa parameters, nhưng KHÔNG có tính năng automatic rotation built-in (dù là Standard hay Advanced Tier). Rotation chỉ có ở Secrets Manager cho secret values, không phải encryption keys. Inject vào env vars Lambda cần cấu hình thủ công, và vẫn thiếu rotation native.
📘 Tài liệu tham khảo (AWS official docs, cập nhật 2026)
- AWS KMS Key Rotation: docs.aws.amazon.com/kms/latest/developerguide/rotate-keys.html – Xác nhận CMKs auto rotation hàng năm, AWS managed keys không hỗ trợ.
- Lambda Encrypted Env Vars: docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-encrypted – Hỗ trợ KMS direct encrypt.
- Secrets Manager Rotation: docs.aws.amazon.com/secretsmanager/latest/userguide/rotating-secrets.html – Chỉ secret values, dùng KMS nhưng không rotate KMS keys.
- SSM Parameter Store: docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html – Không có rotation.
- AWS Well-Architected Security Pillar: Nhấn mạnh KMS CMKs cho sensitive data rotation (re:Post và re:Invent 2025).
Hy vọng phân tích này giúp bạn ôn thi DOP-C02 hiệu quả! 🚀 Nếu cần thêm ví dụ console/code, hãy hỏi nhé.
The developer needs to create an Amazon CloudWatch Logs Insights query that shows the average, slowest, and fastest processing time in 1-minute intervals.
Which query will meet these requirements?
-
A
filter @type = "REPORT" | stats avg(@duration), max(@duration), min(@duration) by bin(1m)
-
B
filter @type = "DISPLAY" | stats avg(@duration), max(@duration), min(@duration) by bin(5m)
-
C
filter @type = "STATS" | stats avg(@duration), max(@duration), min(@duration) by bin(5m)
-
D
filter @type = "PATTERN" | stats avg(@duration), max(@duration), min(@duration) by bin(1m)
Xem giải thích
🧩 Giải thích nội dung câu hỏi
Câu hỏi tập trung vào việc tối ưu hóa thời gian xử lý hình ảnh trong ứng dụng sử dụng AWS Lambda. Nhà phát triển muốn tạo một truy vấn Amazon CloudWatch Logs Insights để phân tích hiệu suất:
- Average (trung bình), slowest (chậm nhất - max), và fastest (nhanh nhất - min) thời gian xử lý (
@duration). - Phân tích theo khoảng thời gian 1 phút (1-minute intervals).
🛠️ Bối cảnh kỹ thuật:
- Lambda tự động ghi log vào CloudWatch Logs, bao gồm dòng REPORT chứa metrics như
@duration(thời gian thực thi hàm tính bằng mili giây). - CloudWatch Logs Insights sử dụng ngôn ngữ truy vấn PPL (Pattern Path Language) để filter và aggregate dữ liệu log.
- Yêu cầu chính: Filter đúng loại log chứa duration, tính stats (avg, max, min), và group theo bin(1m) cho đúng 1 phút.
(Kiến thức cập nhật đến 2026: Syntax Logs Insights không thay đổi lớn từ 2023-2026, vẫn hỗ trợ@type = "REPORT"cho Lambda logs theo tài liệu AWS mới nhất).
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng:
filter @type = "REPORT" |
stats avg(@duration), max(@duration), min(@duration) by bin(1m)
Lý do:
- ✅ Filter
@type = "REPORT": Đúng vì Lambda ghi log REPORT ở cuối mỗi invocation, chứa chính xác@duration,@memorySize,@billedDuration, v.v. Đây là nguồn dữ liệu chuẩn để đo thời gian xử lý. - ✅ Stats
avg(@duration), max(@duration), min(@duration): Tính toán chính xác trung bình, chậm nhất (max), nhanh nhất (min) của thời gian xử lý. - ✅
by bin(1m): Group dữ liệu theo khoảng 1 phút, khớp yêu cầu "1-minute intervals".
Kết quả sẽ hiển thị bảng với cột p95, avg, max, min theo từng bucket 1 phút, giúp developer xác định bottleneck suốt ngày.
📋 Phân tích tất cả các phương án
-
Phương án 1 (Đúng ✅):
filter @type = "REPORT" | stats avg(@duration), max(@duration), min(@duration) by bin(1m)🟢 Hoàn hảo khớp yêu cầu: Filter REPORT đúng nguồn duration, stats đầy đủ, bin(1m) chính xác 1 phút.
-
Phương án 2 (Sai ❌):
filter @type = "DISPLAY" | stats avg(@duration), max(@duration), min(@duration) by bin(5m)🔴 Sai vì:
@type = "DISPLAY"không tồn tại trong Lambda logs (không filter được REPORT). Ngoài ra,bin(5m)là 5 phút thay vì 1 phút, làm sai khoảng thời gian. Kết quả sẽ rỗng hoặc không chính xác. -
Phương án 3 (Sai ❌):
filter @type = "STATS" | stats avg(@duration), max(@duration), min(@duration) by bin(5m)🔴 Sai vì:
@type = "STATS"không phải loại log chuẩn của Lambda (chỉ REPORT mới có duration).bin(5m)sai khoảng 1 phút. Truy vấn sẽ không trả về dữ liệu duration hữu ích. -
Phương án 4 (Sai ❌):
filter @type = "PATTERN" | stats avg(@duration), max(@duration), min(@duration) by bin(1m)🔴 Sai vì:
@type = "PATTERN"dùng cho pattern matching trong Logs Insights, không liên quan đến log REPORT của Lambda (không chứa@duration). Dùbin(1m)đúng, filter sai dẫn đến dữ liệu không khớp.
📘 Tài liệu tham khảo
- AWS Lambda Monitoring với CloudWatch Logs: docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html (xem phần "REPORT log line").
- CloudWatch Logs Insights Query Syntax: docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html (filter
@type,stats,bin()- cập nhật 2025). - Ví dụ query Lambda performance: aws.amazon.com/blogs/compute/using-cloudwatch-logs-insights-to-monitor-lambda-functions/.
Hy vọng phân tích này giúp bạn nắm vững! 🚀 Nếu cần query thực tế, hãy test trên Logs Insights console.
Which solution will meet these requirements with the LEAST development effort?
- A Create an AWS Lambda function to generate findings. Program the Lambda function to send the findings to another S3 bucket in eu-west-2.
- B Configure Amazon Macie to generate findings. Use Amazon EventBridge to create rules that copy the findings to eu-west-2.
- C Configure Amazon Inspector to generate findings. Use Amazon EventBridge to create rules that copy the findings to eu-west-2.
- D Configure Amazon Macie to generate findings and to publish the findings to AWS CloudTrail. Use a CloudTrail trail to copy the results to eu-west-2.
Xem giải thích
🧩 Phân tích chi tiết nội dung câu hỏi
Câu hỏi yêu cầu triển khai giải pháp phân tích dữ liệu người dùng lưu trữ trong các Amazon S3 buckets ở nhiều AWS Regions để phát hiện thông tin nhạy cảm (sensitive information). Kết quả phân tích (findings) từ tất cả các S3 buckets phải được tập hợp và available tại Region eu-west-2. Giải pháp phải đạt LEAST development effort (ít nỗ lực phát triển nhất), nghĩa là ưu tiên sử dụng các dịch vụ managed của AWS thay vì viết code tùy chỉnh nhiều.
Mục tiêu chính:
- Phân tích dữ liệu S3 multi-region để tìm sensitive data (như PII, credentials...).
- Aggregate findings về eu-west-2.
- Ưu tiên giải pháp đơn giản, không custom code nặng.
📘 Kiến thức liên quan (cập nhật AWS 2026): Amazon Macie là dịch vụ chuyên phát hiện sensitive data trong S3, hỗ trợ multi-account/multi-region. Findings của Macie được lưu ở S3 bucket trong region chạy job, và có thể replicate qua EventBridge (serverless event bus). Không cần code phức tạp.
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng: Configure Amazon Macie to generate findings. Use Amazon EventBridge to create rules that copy the findings to eu-west-2.
Lý do:
- 🛠️ Amazon Macie là dịch vụ managed lý tưởng cho việc scan S3 để tìm sensitive data (PII, financial info...), hỗ trợ multi-region tự động. Findings được generate dưới dạng JSON/S3 objects.
- Amazon EventBridge (trước là CloudWatch Events) capture events từ Macie findings (qua schema Macie events), rồi dùng rule no-code/low-code để copy findings cross-region đến S3 bucket ở eu-west-2 (qua Lambda target hoặc S3 putObject integration).
- LEAST effort: Không viết code Lambda tùy chỉnh, chỉ config Macie jobs + EventBridge rules (drag-drop UI). Hỗ trợ automation qua CloudFormation/Terraform.
- Hoàn hảo cho multi-region aggregation mà không cần dev effort cao.
📋 Giải thích tất cả các phương án (đúng/sai)
Dưới đây là phân tích từng lựa chọn giữ nguyên văn bản gốc bằng tiếng Anh. Mỗi phương án được đánh giá với emoji và lý do chi tiết bằng tiếng Việt:
-
❌ Phương án SAI: Create an AWS Lambda function to generate findings. Program the Lambda function to send the findings to another S3 bucket in eu-west-2.
Lý do sai: Phải tự viết Lambda function để scan S3 (sử dụng ML/custom logic), rất tốn effort dev (code scanning logic, handle multi-region, permissions). Không tận dụng managed service như Macie, vi phạm "LEAST development effort". Lambda chỉ tốt cho transport, không phải generate findings. -
✅ Phương án ĐÚNG: Configure Amazon Macie to generate findings. Use Amazon EventBridge to create rules that copy the findings to eu-west-2.
Lý do đúng: Như đã giải thích ở trên. Macie chuyên scan S3 sensitive data multi-region, EventBridge copy findings serverless/no-code. Effort thấp nhất, scalable đến 2026 (Macie Classic retire, dùng Macie mới với improved ML). -
❌ Phương án SAI: Configure Amazon Inspector to generate findings. Use Amazon EventBridge to copy the findings to eu-west-2.
Lý do sai: Amazon Inspector chỉ scan vulnerability/EC2/container/images, KHÔNG hỗ trợ scan dữ liệu S3 sensitive info. Không generate findings phù hợp, EventBridge copy cũng vô ích vì findings sai mục đích. -
❌ Phương án SAI: Configure Amazon Macie to generate findings and to publish the findings to AWS CloudTrail. Use a CloudTrail trail to copy the results to eu-west-2.
Lý do sai: Macie KHÔNG publish findings trực tiếp đến CloudTrail (CloudTrail chỉ log API calls, không lưu full findings data). Findings của Macie lưu ở S3/EventBridge/Security Hub, không phải CloudTrail trail. Sai architecture, không copy được data đầy đủ.
🔗 Tài liệu tham khảo (AWS Docs cập nhật 2026)
- 📘 Amazon Macie User Guide - Analyzing S3 data multi-region
- 📘 EventBridge with Macie findings
- 📘 Macie Findings format & aggregation
- 🛠️ Best practice: AWS Well-Architected Framework - Security Pillar (Macie cho data discovery).
Giải pháp này đảm bảo tuân thủ GDPR/SOX với audit trail tự động! 🚀
During tests for peak traffic, the application ingests data slowly. A developer needs to adjust the data stream to handle the peak traffic.
What should the developer do to meet this requirement MOST cost-effectively?
- A Install the Kinesis Producer Library (KPL) to ingest data into the data stream.
- B Switch to on-demand capacity mode for the data stream. Specify a partition key when writing data to the data stream.
- C Decrease the amount of time that data is kept in the data stream by using the DecreaseStreamRetentionPeriod API operation.
- D Increase the shard count in the data stream by using the UpdateShardCount API operation.
Xem giải thích
🧩 Phân tích nội dung câu hỏi
Câu hỏi tập trung vào Amazon Kinesis Data Streams – một dịch vụ xử lý dữ liệu thời gian thực với khả năng mở rộng dựa trên shards (đơn vị xử lý dữ liệu cơ bản).
- Tình huống: Ứng dụng đang ingest (nhập dữ liệu) từ một Kinesis data stream với shards được cấu hình cho normal traffic (lưu lượng bình thường).
- Vấn đề: Trong peak traffic (lưu lượng đỉnh cao) từ các bài test, ứng dụng ingest dữ liệu chậm (không kịp xử lý).
- Yêu cầu: Developer cần điều chỉnh data stream để xử lý peak traffic một cách MOST cost-effectively (tiết kiệm chi phí nhất).
Mỗi shard hỗ trợ 1 MB/s ingest và 2 MB/s get records (theo tài liệu AWS cập nhật 2024-2026). Với provisioned capacity mode (mặc định), shard count cố định nên không đủ cho peak. Cần scale up throughput mà không lãng phí chi phí dài hạn. 🛠️
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng: Increase the shard count in the data stream by using the UpdateShardCount API operation.
Lý do:
- UpdateShardCount API cho phép tăng shard count một cách tự động và linh hoạt (scale up exponentially, ví dụ từ 1 lên 2, 4, 8 shards), xử lý peak traffic ngay lập tức mà không cần recreate stream.
- Cost-effective nhất: Chỉ trả phí theo shard-hour thực tế (~$0.015/giờ/shard), tự động scale down sau peak để tiết kiệm. Phù hợp cho peak tạm thời trong test, không lãng phí như on-demand mode (chi phí cao hơn ~20-50% cho burst).
- Theo AWS best practices 2026, đây là cách scale provisioned streams hiệu quả cho workload biến động. ✅
📋 Giải thích tất cả các phương án
-
❌ Install the Kinesis Producer Library (KPL) to ingest data into the data stream.
Phương án này sai vì KPL chỉ là thư viện client-side giúp batch records, retries, và multi-threading để tối ưu ingest từ producer. Nó không tăng shard capacity của stream (vẫn giới hạn 1 MB/s/shard). Không giải quyết bottleneck ở peak traffic. -
❌ Switch to on-demand capacity mode for the data stream. Specify a partition key when writing data to the data stream.
Phương án này sai và không cost-effective. On-demand mode (ra mắt 2021, cập nhật 2026) auto-scale shards, nhưng chi phí cao hơn provisioned (pay-per-throughput + shard-hour premium). Partition key chỉ đảm bảo phân phối dữ liệu, không liên quan scale. Không phải lựa chọn tiết kiệm nhất cho peak test. -
❌ Decrease the amount of time that data is kept in the data stream by using the DecreaseStreamRetentionPeriod API operation.
Phương án này sai hoàn toàn vì retention period (24h-365 ngày mặc định) chỉ ảnh hưởng lưu trữ dữ liệu, không tác động đến ingest throughput hay shard capacity. Giảm retention tiết kiệm storage fee nhưng làm tệ hơn vấn đề ingest chậm. -
✅ Increase the shard count in the data stream by using the UpdateShardCount API operation.
Như đã giải thích ở trên: Đúng vì trực tiếp tăng throughput ingest, scale động, và tiết kiệm chi phí nhất cho peak tạm thời. AWS khuyến nghị cho workload dự đoán được.
📘 Tài liệu tham khảo (cập nhật AWS 2026)
- AWS Kinesis Data Streams Developer Guide: Scaling | Amazon Kinesis Data Streams – Chi tiết UpdateShardCount và shard throughput.
- AWS Pricing: Kinesis Data Streams Pricing – So sánh provisioned vs on-demand.
- Best Practices: AWS Well-Architected Framework – Stream Processing (Reliability pillar).
🔗 Kiểm tra trực tiếp AWS Console hoặc CLI:aws kinesis update-shard-count --stream-name MyStream --target-shard-count 10.
Hy vọng phân tích này giúp bạn ôn thi DOP-C02 hiệu quả! 🚀
Which solution will meet these requirements?
- A Increase the memory of the Lambda function to the maximum amount. Configure an Amazon EventBridge rule to schedule invocations of the Lambda function every minute to keep the execution environment active.
- B Optimize the static initialization code that runs when a new execution environment is prepared for the first time. Decrease and compress the size of the Lambda function package and the imported libraries and dependencies.
- C Increase the reserved concurrency of the Lambda function to the maximum value for unreserved account concurrency. Run any setup activities manually before the initial invocation of the Lambda function.
- D Publish a new version of the Lambda function. Configure provisioned concurrency for the Lambda function with the required minimum number of execution environments.
Xem giải thích
🧩 Phân tích chi tiết nội dung câu hỏi
Câu hỏi tập trung vào việc xây dựng ứng dụng sử dụng AWS Lambda để xử lý dữ liệu, với các yêu cầu nghiêm ngặt sau:
- Minimum latency (độ trễ thấp nhất có thể).
- Predictable function start times (thời gian khởi động hàm có thể dự đoán được, tránh "cold starts" – tình trạng môi trường thực thi Lambda khởi động lần đầu gây chậm trễ).
- All setup activities phải hoàn tất trước khi invoke Lambda (tất cả hoạt động thiết lập môi trường thực thi phải diễn ra trước khi hàm được gọi, không để setup chạy lúc runtime).
🛠️ Vấn đề cốt lõi: Lambda thường gặp cold starts (khởi động lạnh) khi môi trường thực thi mới được tạo, dẫn đến latency cao và không dự đoán được. Giải pháp cần chuẩn bị sẵn môi trường warm (sẵn sàng) để đảm bảo hiệu suất ổn định, phù hợp với kiến thức AWS Lambda cập nhật đến 2026 (Lambda hỗ trợ Provisioned Concurrency và SnapStart cho một số runtime như Java, .NET).
📘 Tài liệu tham khảo:
- AWS Lambda Documentation: Reducing invocation latency (cập nhật 2025).
- AWS re:Post: Provisioned Concurrency (best practices 2026).
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng: Publish a new version of the Lambda function. Configure provisioned concurrency for the Lambda function with the required minimum number of execution environments.
Lý do:
Provisioned Concurrency là tính năng Lambda chuẩn bị trước số lượng môi trường thực thi (execution environments) warm, giữ chúng luôn sẵn sàng trước khi invoke. Điều này đảm bảo:
- Latency thấp và predictable start times (không cold starts).
- Tất cả setup (init code, dependencies) hoàn tất trước invocation.
- Phải publish version mới để alias traffic đến version với Provisioned Concurrency.
🧩 Đây là giải pháp chính thức và tối ưu nhất từ AWS cho yêu cầu này, hỗ trợ scale tự động và chi phí dựa trên số env provisioned (cập nhật 2026: tích hợp với Lambda SnapStart cho runtime nhanh hơn).
📋 Phân tích tất cả các phương án (đúng/sai)
-
Phương án 1: Increase the memory of the Lambda function to the maximum amount. Configure an Amazon EventBridge rule to schedule invocations of the Lambda function every minute to keep the execution environment active.
❌ Sai: Tăng memory giúp CPU nhanh hơn nhưng không giải quyết cold starts (vẫn có latency cao nếu env cold). Schedule EventBridge invoke mỗi phút chỉ là "keep warm" thủ công, không predictable (có thể miss nếu traffic thấp), tốn chi phí invoke thừa, và setup vẫn chạy lúc init. Không đáp ứng "setup trước invocation". -
Phương án 2: Optimize the static initialization code that runs when a new execution environment is prepared for the first time. Decrease and compress the size of the Lambda function package and the imported libraries and dependencies.
❌ Sai: Optimize init code và compress package giảm thời gian cold start (best practice cơ bản), nhưng không loại bỏ cold starts hoàn toàn – vẫn unpredictable nếu env mới. Không đảm bảo setup trước invocation 100%, chỉ cải thiện chứ không meet "minimum latency + predictable". -
Phương án 3: Increase the reserved concurrency of the Lambda function to the maximum value for unreserved account concurrency. Run any setup activities manually before the initial invocation of the Lambda function.
❌ Sai: Reserved Concurrency chỉ giới hạn/giao quyền concurrency, không warm env hay predictable start times. "Manual setup" trước initial invoke không khả thi cho production (không scale, không tự động), và vẫn cold start cho các invoke sau. -
Phương án 4: Publish a new version of the Lambda function. Configure provisioned concurrency for the Lambda function with the required minimum number of execution environments.
✅ Đúng: Như giải thích ở trên, đây là giải pháp chuẩn AWS để warm env trước, đảm bảo tất cả yêu cầu. Hỗ trợ alias versioning để traffic routing mượt mà (cập nhật 2026: tích hợp Graviton2/3 cho hiệu suất cao hơn).
🛠️ Lời khuyên thực hành: Sử dụng AWS Console/CLI để config Provisioned Concurrency trên alias/version cụ thể, monitor qua CloudWatch Metrics (Duration, ColdStarts). Chi phí ~0.00000467 USD/GB-second provisioned (2026 pricing).
Which solution will meet these requirements with the MOST operational efficiency?
- A In the CodePipeline pipeline, implement an AWS CodeDeploy action for each Region to deploy and test the CloudFormation templates. Update CodePipeline and AWS CodeBuild with appropriate permissions.
- B Configure CodePipeline to deploy and test the CloudFormation templates. Use CloudFormation StackSets to start deployment across both Regions.
- C Configure CodePipeline to invoke AWS CodeBuild to deploy and test the CloudFormation templates in each Region. Update CodeBuild and CloudFormation with appropriate permissions.
- D Use the Snyk action in CodePipeline to deploy and test the CloudFormation templates in each Region.
Xem giải thích
🧩 Giải thích nội dung câu hỏi
Câu hỏi tập trung vào việc triển khai và kiểm tra (test) các template AWS CloudFormation trong một pipeline AWS CodePipeline. 🛤️
- Công ty đang sử dụng một tài khoản AWS duy nhất (single AWS account) và không sử dụng AWS Organizations.
- Họ cần test template CloudFormation ở vùng chính (primary AWS Region) và vùng phục hồi thảm họa (disaster recovery Region).
- Yêu cầu giải pháp có hiệu quả vận hành cao nhất (MOST operational efficiency), nghĩa là giảm thiểu công sức quản lý, tự động hóa tối đa, và dễ mở rộng cho multi-region deployment mà không phức tạp.
📘 Bối cảnh cập nhật 2026: AWS CodePipeline hỗ trợ tích hợp CloudFormation qua các action như Deploy/Invoke, và CloudFormation StackSets (ra mắt từ 2018, cập nhật liên tục) là công cụ chuẩn cho việc deploy stack qua nhiều regions/accounts một cách tự động, ngay cả single account.
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng: Configure CodePipeline to deploy and test the CloudFormation templates. Use CloudFormation StackSets to start deployment across both Regions.
🧠 Lý do chi tiết:
- CloudFormation StackSets cho phép deploy và quản lý stack CloudFormation đồng thời qua nhiều Regions từ một pipeline CodePipeline duy nhất, với tự động hóa cao (self-managed permissions trong single account). Không cần cấu hình riêng lẻ cho từng Region, giảm thiểu lỗi và effort vận hành.
- CodePipeline có action CloudFormation Deploy tích hợp trực tiếp StackSets, test bằng cách tạo/update stack ở cả hai Regions. Đây là cách hiệu quả nhất theo best practice AWS DevOps (ít code custom, native integration).
- Phù hợp single account/no Organizations vì StackSets hỗ trợ self-managed mode (không cần delegated admin).
🚀 Operational efficiency cao nhất: Một pipeline duy nhất trigger StackSets → deploy/test parallel/multi-region.
📋 Phân tích tất cả các phương án
Dưới đây là phân tích từng lựa chọn, giữ nguyên văn bản gốc bằng tiếng Anh. Mỗi phương án được đánh giá đúng/sai với lý do cụ thể dựa trên tính năng AWS mới nhất (2026).
-
❌ Phương án SAI: In the CodePipeline pipeline, implement an AWS CodeDeploy action for each Region to deploy and test the CloudFormation templates. Update CodePipeline and AWS CodeBuild with appropriate permissions.
🧩 Giải thích sai: AWS CodeDeploy dùng để deploy ứng dụng lên EC2/Lambda/On-Prem, không hỗ trợ deploy CloudFormation templates (CFN là IaC declarative, không phải app deployment). Phải tạo action riêng cho từng Region → kém hiệu quả, phức tạp permissions (CodeBuild không liên quan trực tiếp). Không phải best practice cho CFN. -
✅ Phương án ĐÚNG: Configure CodePipeline to deploy and test the CloudFormation templates. Use CloudFormation StackSets to start deployment across both Regions.
🛠️ Giải thích đúng: Như đã nêu ở phần đáp án. StackSets tự động hóa multi-region deployment từ CodePipeline action "CloudFormationAddToStackSet" hoặc "CreateStackSet", test qua stack instances ở cả hai Regions. Hiệu quả cao nhất: Ít code, native support, auto-rollback nếu test fail. -
❌ Phương án SAI: Configure CodePipeline to invoke AWS CodeBuild to deploy and test the CloudFormation templates in each Region. Update CodeBuild and CloudFormation with appropriate permissions.
🧩 Giải thích sai: CodeBuild có thể dùng CLI (aws cloudformation create-stack) để deploy CFN, nhưng phải cấu hình project riêng/job riêng cho từng Region (cross-account/role assumption phức tạp dù single account). Không tự động như StackSets → ít efficient hơn, tăng maintenance (permissions IAM cho từng Region). -
❌ Phương án SAI: Use the Snyk action in CodePipeline to deploy and test the CloudFormation templates in each Region.
🚫 Giải thích sai: Snyk là third-party action cho security scanning IaC (như CFN templates), không deploy hay test deployment (chỉ detect vulnerabilities). Không hỗ trợ tạo/update stack → hoàn toàn không phù hợp cho yêu cầu deploy/test thực tế.
📚 Tài liệu tham khảo (AWS cập nhật 2026)
- AWS CodePipeline User Guide: Deploy with CloudFormation (tích hợp StackSets).
- CloudFormation StackSets: StackSets in single account/multi-region (self-managed mode).
- AWS DevOps Best Practices: Multi-region pipelines.
🔍 Kiểm tra AWS Console hoặc CLI mới nhất để verify integration.
A developer needs make a production alias of the Lambda function named prod available through the API.
Which solution meets these requirements?
- A Create a new method on the API. Name the method production. Configure the method to include a stage variable that points to the prod Lambda function alias.
- B Create a new method on the API. Name the method production. Configure an integration request on the API’s development stage that points to the prod Lambda function alias.
- C Deploy the API to a new stage named production. Configure the stage to include a stage variable that points to the prod Lambda function alias.
- D Deploy the API to a new stage named production. Configure an integration request on the API’s production stage that points to the prod Lambda function alias.
Xem giải thích
🧩 Phân tích chi tiết nội dung câu hỏi
Câu hỏi xoay quanh việc quản lý Amazon API Gateway REST API tích hợp với AWS Lambda function. Cụ thể:
- API hiện tại đang sử dụng development stage (giai đoạn phát triển), và stage này tham chiếu đến alias "dev" của Lambda function.
- Yêu cầu: Làm cho alias "prod" (sản xuất) của Lambda function trở nên khả dụng qua API, mà không ảnh hưởng đến stage hiện tại.
📌 Mục tiêu chính: Cần triển khai một cách để expose alias prod một cách an toàn, linh hoạt, tận dụng tính năng stages và stage variables của API Gateway. Stages cho phép tạo môi trường riêng biệt (dev/prod), còn stage variables giúp động hóa integration (ví dụ: switch URI Lambda alias mà không cần thay đổi code API).
🛠️ Đây là best practice trong DevOps để tách biệt môi trường dev/prod, hỗ trợ blue-green deployment hoặc canary releases (cập nhật AWS đến 2026 vẫn giữ nguyên cơ chế này).
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng: Deploy the API to a new stage named production. Configure the stage to include a stage variable that points to the prod Lambda function alias.
Lý do:
- Việc deploy API sang stage mới "production" tạo môi trường riêng biệt, không ảnh hưởng stage "development" đang dùng alias "dev".
- Stage variable (biến stage) được config trên stage production để trỏ đến alias "prod" (ví dụ:
lambda:arn:aws:lambda:region:account:function:name:prod). - Điều này tận dụng integration URI động trong API Gateway:
${stageVariables.lambdaAlias}→ linh hoạt switch alias mà không sửa method/integration. - ✅ Hoàn hảo cho production readiness, hỗ trợ traffic routing (x:80% prod, 20% dev) qua canary deployments.
📋 Giải thích tất cả các phương án (đúng/sai)
-
Phương án SAI: Create a new method on the API. Name the method production. Configure the method to include a stage variable that points to the prod Lambda function alias.
❌ Lý do sai: Tạo method mới (ví dụ: /production) không giải quyết yêu cầu expose alias prod qua cùng API hiện tại. Stage variable chỉ hoạt động trên stage cụ thể, nhưng method mới sẽ duplicate logic và không tách biệt môi trường dev/prod đúng cách. Điều này vi phạm nguyên tắc DRY (Don't Repeat Yourself) và khó scale. -
Phương án SAI: Create a new method on the API. Name the method production. Configure an integration request on the API’s development stage that points to the prod Lambda function alias.
❌ Lý do sai: Tạo method mới trên stage development sẽ override alias "dev" hiện tại bằng "prod", gây conflict môi trường (dev giờ chạy prod code). Không an toàn cho production, dễ gây downtime. Integration request cố định URI không dùng stage variable → thiếu linh hoạt. -
Phương án ĐÚNG: Deploy the API to a new stage named production. Configure the stage to include a stage variable that points to the prod Lambda function alias.
✅ Lý do đúng (như đã giải thích ở trên): Tạo stage riêng "production", dùng stage variable để trỏ alias prod → tách biệt hoàn hảo, dễ quản lý versions/aliases Lambda. Hỗ trợ monitoring riêng (CloudWatch) và custom domain per stage. -
Phương án SAI: Deploy the API to a new stage named production. Configure an integration request on the API’s production stage that points to the prod Lambda function alias.
❌ Lý do sai: Deploy stage mới là đúng, nhưng config integration request cố định (hardcode URI:prod) thay vì stage variable sẽ thiếu linh hoạt. Nếu cần switch alias sau (ví dụ: prod-v2), phải redeploy toàn bộ integration → không scalable, không theo best practice AWS.
📘 Tài liệu tham khảo (AWS cập nhật đến 2026)
- API Gateway Stages & Stage Variables: AWS Docs - Stages & Stage Variables.
- Lambda Aliases với API Gateway: AWS Docs - Lambda Aliases & Integration Example.
- Best Practices DevOps: AWS Well-Architected Framework - Operational Excellence Pillar (2024 update).
🧑💻 Lời khuyên: Sử dụng AWS SAM/CDK để automate deploy stages với stage variables cho CI/CD pipeline!
The developer notices that there are no changes in the Lambda function every time the CloudFormation stack is updated.
How can the developer resolve this issue?
- A Create a new Lambda function alias before updating the CloudFormation stack.
- B Change the S3 object key or the S3 version in the CloudFormation template before updating the CloudFormation stack.
- C Upload the zipped source code to another S3 bucket before updating the CioudFormation stack.
- D Associate a cade signing configuration with the Lambda function before updating the CloudFormation stack.
Xem giải thích
🧩 Phân tích nội dung câu hỏi
Câu hỏi xoay quanh vấn đề triển khai ứng dụng serverless sử dụng AWS CloudFormation để provision các tài nguyên: Amazon S3 (cho web hosting), Amazon API Gateway, và AWS Lambda functions. Nguồn code của Lambda được zip và upload lên S3 bucket, với S3 object key được chỉ định trực tiếp trong resource Lambda của CloudFormation template.
📌 Vấn đề chính: Mỗi khi update CloudFormation stack, hàm Lambda không có sự thay đổi nào (code không được cập nhật), dù code nguồn có thể đã thay đổi trên S3.
🛠️ Nguyên nhân gốc rễ: CloudFormation so sánh template mới với trạng thái hiện tại của stack. Với resource AWS::Lambda::Function, thuộc tính Code (bao gồm S3Bucket, S3Key, S3ObjectVersion) chỉ trigger update nếu có sự thay đổi cụ thể. Nếu chỉ upload code mới lên cùng S3 object key mà không thay đổi key hoặc version trong template, CloudFormation sẽ coi resource Lambda "không thay đổi" và bỏ qua việc cập nhật code (theo cơ chế change set và drift detection của CloudFormation). Điều này được xác nhận trong tài liệu AWS mới nhất (2024-2026), nơi Lambda yêu cầu explicit change ở Code property để redeploy.
✅ Đáp án đúng và lý do lựa chọn
Đáp án đúng: Change the S3 object key or the S3 version in the CloudFormation template before updating the CloudFormation stack.
Lý do:
- Khi update code Lambda qua CloudFormation với S3, bạn phải thay đổi S3Key (tên object mới) hoặc S3ObjectVersion (version ID của object trên S3 với versioning enabled) trong template để CloudFormation detect sự thay đổi và trigger update code.
- Điều này buộc Lambda pull code mới từ S3, giải quyết triệt để vấn đề "no changes". Đây là best practice được AWS khuyến nghị cho CI/CD với CloudFormation (SAM/ CDK cũng tương tự).
- ✅ Hiệu quả cao: Không ảnh hưởng đến các resource khác, tự động và idempotent.
📋 Giải thích tất cả các phương án
Dưới đây là phân tích chi tiết từng lựa chọn, giữ nguyên nội dung gốc bằng tiếng Anh. Mỗi phương án được đánh giá đúng/sai với lý do cụ thể dựa trên tài liệu AWS Lambda & CloudFormation (cập nhật 2026):
-
Create a new Lambda function alias before updating the CloudFormation stack.
❌ Sai: Alias (như $LATEST hoặc version alias) chỉ dùng để quản lý phiên bản runtime của Lambda, không trigger update code từ S3. Tạo alias mới không ảnh hưởng đến việc CloudFormation detect change ở Code property. Vấn đề vẫn tồn tại vì template không thay đổi S3 reference. -
Change the S3 object key or the S3 version in the CloudFormation template before updating the CloudFormation stack.
✅ Đúng: Như đã giải thích ở trên. Thay đổi S3Key (ví dụ: từcode.zipsangcode-v2.zip) hoặc S3ObjectVersion (nếu S3 versioning bật) sẽ làm CloudFormation nhận diện sự khác biệt, dẫn đến update code Lambda tự động. Đây là giải pháp chuẩn theo docs. -
Upload the zipped source code to another S3 bucket before updating the CloudFormation stack.
❌ Sai: Chỉ thay bucket thôi (mà không update S3Bucket name trong template) thì CloudFormation vẫn dùng bucket cũ/key cũ, nên không detect change. Bạn phải chỉnh template để reference bucket mới + key/version mới mới hiệu quả, nhưng phương án này không đề cập chỉnh template → không giải quyết gốc rễ. -
Associate a code signing configuration with the Lambda function before updating the CloudFormation stack.
❌ Sai: Code signing (tính năng bảo mật từ 2021, cập nhật 2026 với improved validation) dùng để verify code integrity trước khi deploy, nhưng nó không trigger code update. Nó chỉ thêm layer validation sau khi code đã được pull, không giải quyết vấn đề Lambda "no changes" khi update stack.
📘 Tài liệu tham khảo (AWS Official - Cập nhật 2026)
- AWS CloudFormation User Guide: AWS::Lambda::Function - Phần Code.S3ObjectVersion và update behavior.
- AWS Lambda Developer Guide: Managing Lambda function code với S3 + CloudFormation.
- Best Practices: AWS Well-Architected Framework - Reliability Pillar (Serverless), nhấn mạnh explicit versioning cho CI/CD.
- SAM CLI Docs (tương đương): sam deploy - Tương tự cơ chế.
Hy vọng phân tích này giúp bạn nắm vững! 🚀 Nếu cần ví dụ template YAML cụ thể, hãy hỏi thêm nhé!