TL;DR
- AWS Well-Architected Framework có 6 pillar mặc định: Operational Excellence, Security, Reliability, Performance, Cost, Sustainability. Custom lens cho phép bạn thêm pillar/question riêng cho tổ chức — ví dụ “Vietnam compliance”, “FinServ regulation”, “Internal architecture standard”.
- aws-samples/custom-lens-wa-hub (~1.6k star) cung cấp template + CloudFormation deploy pattern + ví dụ lens (FinTech, ML, DevOps). Đây là điểm bắt đầu thay vì viết JSON từ scratch.
- Định nghĩa qua JSON schema: lens có
pillars→questions→choices→helpfulResource/improvementPlan. Một lens nhỏ (5 question) viết được trong nửa ngày, lens đầy đủ (40+ question) cần 2-3 tuần.- Use case Vietnam: encode Thông tư 09/2020 và Nghị định 53/2022 thành câu hỏi review — data residency, log retention, encryption at rest, cross-border data transfer. Auditor đọc được output.
- Lens pair tốt với AWS Security Maturity Model: SMM là roadmap, lens là measurement. SMM trả lời “làm gì tiếp”, lens trả lời “đang ở đâu”.
- Deploy qua CloudFormation
AWS::WellArchitected::Lensrồi share cross-account bằngShareLensRequestAPI. Một lens deploy trong management account, share cho mọi workload account.- Đừng làm lens cho mọi thứ: chỉ build khi có 5+ workload cần review cùng tiêu chí, hoặc khi compliance regulator cần thấy review document có format chuẩn.
Vì sao custom lens, không phải Confluence checklist
Mọi security team đã từng có lúc maintain Excel/Confluence “security review checklist”. 80 câu hỏi, mỗi project mới build phải đi qua, đánh dấu Yes/No/Partial. Sau 18 tháng, file trở thành mê cung — chẳng ai biết version nào current, mỗi BU có file riêng, audit hỏi “show me your review history” thì im lặng.
AWS Well-Architected Tool là phiên bản managed của Excel đó. Custom lens là tính năng cho phép bạn nhúng checklist của tổ chức vào tool đó. Khi review workload, anh kiến trúc thấy cùng UI/UX với 6 pillar AWS, scroll xuống thấy pillar custom của bạn, đi qua từng câu hỏi. Output JSON trace lại — audit-ready.
Tôi build 2 custom lens trong 18 tháng vừa qua — một cho compliance Việt Nam (Thông tư 09, Nghị định 53, Luật An ninh mạng), một cho “FinServ data lifecycle” cho khách hàng fintech. Bài này note lại quy trình.
Anatomy của một lens — JSON schema bốn tầng
Một lens là một file JSON theo schema AWS định nghĩa (AWS doc Lens Format Specification). Bốn tầng:
Lens
└── Pillar (1..N)
└── Question (1..N)
└── Choice (1..N)
├── HelpfulResource (link doc)
└── ImprovementPlan (link doc)
Ví dụ tối thiểu — lens “Vietnam data residency”:
{
"schemaVersion": "2021-11-01",
"name": "VN Data Residency Lens",
"description": "Compliance lens for Vietnamese data localization regulations (Decree 53/2022, Circular 09/2020).",
"pillars": [
{
"id": "vn_data_residency",
"name": "Data Residency",
"questions": [
{
"id": "VN_DR_01",
"title": "Personal data of Vietnamese citizens is stored in-country",
"description": "Decree 53/2022 requires personal data of VN citizens collected by domestic services to be stored in Vietnam.",
"choices": [
{
"id": "VN_DR_01_A",
"title": "All personal data resides in ap-southeast-1 (Singapore)",
"helpfulResource": {
"displayText": "Decree 53/2022 Article 26",
"url": "https://thuvienphapluat.vn/..."
}
},
{
"id": "VN_DR_01_B",
"title": "Personal data resides in a Vietnam-based region or local cloud (VNG, Viettel IDC, FPT) mirrored from AWS",
"improvementPlan": {
"displayText": "Multi-region architecture for VN data",
"url": "https://example.com/vn-data-arch.html"
}
},
{
"id": "VN_DR_01_C",
"title": "No personal VN data is processed in this workload (out of scope)",
"default": false
},
{
"id": "none",
"title": "None of these"
}
],
"riskRules": [
{ "condition": "VN_DR_01_A || VN_DR_01_B || VN_DR_01_C", "risk": "NONE" },
{ "condition": "default", "risk": "HIGH" }
]
}
]
}
]
}
riskRules là điểm tinh tế. Nó tính risk dựa trên choice user select — NONE/MEDIUM/HIGH. Default rule risk: HIGH áp dụng khi không match rule trên — quan trọng vì lens là fail closed mặc định.
aws-samples/custom-lens-wa-hub — đừng viết JSON tay
Repo aws-samples/custom-lens-wa-hub cung cấp:
- Template lens cho domain thường gặp: FinTech, IoT, ML, DevOps, Healthcare
- CloudFormation stack deploy lens vào management account
- Share automation cho cross-account
- Validation script check JSON schema trước khi deploy
Quy trình recommend:
git clone https://github.com/aws-samples/custom-lens-wa-hub
cd custom-lens-wa-hub
# Copy template gần với use case
cp lenses/financial-services.json lenses/vn-compliance.json
# Sửa nội dung — đổi pillar, question theo yêu cầu
vim lenses/vn-compliance.json
# Validate schema
python3 scripts/validate-lens.py lenses/vn-compliance.json
# Deploy
aws cloudformation deploy \
--stack-name vn-compliance-lens \
--template-file template.yaml \
--parameter-overrides LensFile=lenses/vn-compliance.json
Template CloudFormation chính là AWS::WellArchitected::Lens:
Resources:
VnLens:
Type: AWS::WellArchitected::Lens
Properties:
LensJSON: !Sub |
${LensContent}
Tags:
- Key: Owner
Value: SecArch
- Key: Compliance
Value: VN-Decree53
LensJSON là string nội dung lens. CloudFormation tự ImportLens API call, lens ở trạng thái DRAFT. Trước khi cho user review thực tế, gọi PublishLens để chuyển sang PUBLISHED.
Share lens cross-account — quan trọng cho multi-account
Lens nằm trong account nào tạo nó. Để workload account khác dùng được, phải ShareLens:
aws wellarchitected create-lens-share \
--lens-alias arn:aws:wellarchitected:ap-southeast-1:111122223333:lens/abc123 \
--shared-with 444455556666
# Hoặc share toàn org
aws wellarchitected create-lens-share \
--lens-alias arn:aws:wellarchitected:ap-southeast-1:111122223333:lens/abc123 \
--shared-with arn:aws:organizations::111122223333:organization/o-xyz
Best practice: lens ở central security account (account quản lý SCP, Config, GuardDuty). Workload account chỉ consume — không tạo lens riêng. Lý do — tránh fragmentation. Khi audit hỏi “show me the lens”, có một câu trả lời duy nhất.
Use case: encode Việt Nam regulation
Đây là phần làm tôi thấy custom lens có giá trị thật. Encode Thông tư 09/2020 (NHNN — bảo mật cho ngân hàng) và Nghị định 53/2022 (data localization) thành lens.
Pillar “Vietnam Compliance” của tôi có 4 question chính:
Question 1: Data localization. Personal data VN có ở region nào? Choice mapping:
- A: ap-southeast-1 + thỏa thuận xử lý dữ liệu xuyên biên giới đăng ký với Bộ Công an
- B: Mirror sang local cloud (VNG/Viettel IDC/FPT)
- C: Workload không xử lý dữ liệu cá nhân VN
Risk HIGH nếu workload xử lý PII VN mà không có A hoặc B.
Question 2: Log retention. Theo Thông tư 09, log access tới hệ thống ngân hàng giữ tối thiểu 24 tháng. Question:
- A: CloudWatch Logs export sang S3 với object lock retention 730 ngày
- B: Tự host log archive (Elasticsearch/Loki) với policy retention 730 ngày
- C: Không có log retention
Bài aws-cloudtrail-deep-dive có chi tiết kỹ thuật, ở đây lens chỉ check Yes/No.
Question 3: Encryption. Mọi service xử lý PII phải encrypt at-rest và in-transit. AWS service mặc định ổn (KMS, TLS), nhưng câu hỏi forces team xác nhận. Choice:
- A: KMS CMK riêng cho từng workload, key policy giới hạn
- B: AWS-managed key (alias/aws/…)
- C: Không encryption
Risk HIGH nếu C.
Question 4: Cross-border data transfer. Khi nào dữ liệu ra khỏi VN (CDN cache, S3 replication)? Choice ép user khai báo cụ thể flow.
Lens deploy. Mỗi workload mới phải đi qua review. Output trong AWS Well-Architected Tool có dạng PDF generate được — gửi cho compliance officer làm evidence.
Pair với AWS Security Maturity Model
Bài tôi viết trước về AWS Security Maturity Model v2 nói về 74 control xếp 4 phase. SMM trả lời câu hỏi “làm gì tiếp”. Custom lens trả lời câu hỏi “đo lường thế nào”.
Cách tôi link hai cái:
SMM v2 control → lens question
SCP-Block-Region (SMM Quick Wins #3)
→ lens question "Workload restrict region tới ap-southeast-1 và us-east-1?"
KMS-Customer-Managed-Key (SMM Foundational #12)
→ lens question "Mọi PII workload dùng customer-managed KMS key?"
Data-Perimeter (SMM Optimized #62)
→ lens question "Resource policy có aws:ResourceOrgID/aws:PrincipalOrgID guard?"
Architecture review chạy lens → gap → reference SMM phase tương ứng → roadmap fix. Workflow này tôi áp dụng cho team platform 2 năm — đo được tăng từ 38% câu hỏi pass lên 84%.
Edit lens sau khi published — phải tạo version mới
Cạm bẫy đầu tiên người mới dùng: lens đã PUBLISHED không edit được nội dung. Phải tạo version mới:
# Tạo draft từ lens hiện có
aws wellarchitected get-lens \
--lens-alias <lens-arn> \
--lens-version "1.0" > current.json
# Sửa JSON
vim current.json
# Update lens (tạo draft mới)
aws wellarchitected import-lens \
--json-string file://current.json
# Publish version mới
aws wellarchitected create-lens-version \
--lens-alias <lens-arn> \
--lens-version "2.0" \
--is-major-version
Workload đã review bằng version 1.0 không tự upgrade sang 2.0 — user phải manually upgrade trong console. Lý do — câu hỏi mới có thể require thêm input.
Lens không phải nơi cho mọi thứ
Tôi đã thấy team đề xuất “build lens cho Slack notification policy”, “build lens cho commit message format”. Đây là sai chỗ. Lens cho architectural review — quyết định lớn, mỗi workload review 1-2 lần/năm. Nếu thứ cần check mỗi PR/deploy, dùng tool khác:
| Cần | Tool đúng |
|---|---|
| Per-PR code style/security | linter (eslint, gosec, hardeneks ở CI) |
| Per-deploy config check | AWS Config + custom rule |
| Per-account guardrail | SCP + Control Tower |
| Per-workload architecture | Custom lens |
| Per-org compliance posture | Audit Manager, Security Hub |
Lens đắt — review tốn 2-4 tiếng kiến trúc sư. Đừng dùng nó để check Slack URL có HTTPS không.
Bottom line
Custom lens là cách formalize architecture review trong tổ chức multi-account. Đối với team có 10+ workload, làm regulated industry (banking, healthcare), hay đơn giản muốn version-control checklist review thay vì Excel — đây là tính năng AWS đã có sẵn, miễn phí, audit-friendly. Quan trọng nhất với tôi: nó tách phần “what to review” khỏi phần “how to track review”. Phần đầu thuộc security/platform team. Phần sau là Well-Architected Tool managed. Sau 2 lens + 18 tháng, audit gần nhất giảm 40% thời gian collect evidence vì review history đã chuẩn format. Đây là ROI cụ thể khó argue được.
Checklist trước production
- Pillar/question đã review bởi compliance officer + 2 senior kiến trúc sư
- Risk rule fail-closed (default risk HIGH), không phải fail-open
- Lens validate qua
scripts/validate-lens.pykhông lỗi - CloudFormation stack deploy trong central security account, không phải workload account
- Lens share với toàn AWS Organization (qua org ARN, không liệt kê từng account)
- Mỗi question có
helpfulResourcelink tới internal doc — không link doc dead -
improvementPlanlink tới ticket template/runbook cụ thể - Test review trên 1 workload pilot trước khi rollout
- Version control lens JSON trong git, PR-based review thay đổi
- Document quy trình upgrade lens version cho workload đã review
- Pair với SMM phase mapping table check-in repo
- Schedule lens review quý 1 lần (regulation đổi, AWS service mới)
Cạm bẫy thường gặp
1. Đặt lens trong workload account. Workload account không share được lens (chỉ central account hoặc Organization root). Resource tạo nhầm chỗ, không cleanup được nếu account đóng cửa.
2. Quá nhiều choice cho mỗi question. AWS doc giới hạn ~15 choice/question. Quá nhiều = user pick bừa. Giữ 4-6 choice là sweet spot.
3. Choice không mutually exclusive. Ví dụ “có KMS CMK + có envelope encryption” — hai choice overlap, user không biết tick cái nào. Refactor sang AND/OR explicit hoặc tách thành 2 question.
4. Không có default: true choice. Một question phải có 1 default — nếu user skip, fall back về choice nào? Nếu không khai báo, lens validate sẽ fail.
5. Update lens nhưng quên create-lens-version. Update chỉ tạo draft, không user nào thấy. Phải publish version mới.
6. Share lens nhưng quên IAM permission wellarchitected:GetLens cho consumer account. Lens share thành công về API nhưng user vào console không thấy. Cần policy wellarchitected:* cho IAM role review.
Tham chiếu
- aws-samples/custom-lens-wa-hub
- Well-Architected Lens Format Specification
- Well-Architected Tool API — ImportLens/ShareLens
- AWS::WellArchitected::Lens CloudFormation resource
- Nghị định 53/2022/NĐ-CP — Quy định chi tiết Luật An ninh mạng
- Thông tư 09/2020/TT-NHNN — An toàn hệ thống thông tin trong hoạt động ngân hàng