Bỏ qua tới nội dung
CloudDojo
Phần 3/6 · 8 phút

Tập trung log bằng CloudWatch Logs và metric filter

0/11
Từ khóa của phần nàyChọn một từ để xem nghĩa trước khi đọc

EC2 instance trong Auto Scaling group có thể bị terminate bất cứ lúc nào, và log lưu trên instance bị mất theo; log cần được gửi tới CloudWatch Logs để lưu trữ tập trung.

Auto Scaling group của MFTECH scale với tần suất cao, gần như mỗi ngày đều có instance mới thay thế. Một người dùng báo lỗi thanh toán xảy ra hai ngày trước, nhưng instance liên quan đã bị terminate. Trong một sự cố khác, một access key bị lộ được dùng để gọi API liên tục vào ban đêm. Hai sự cố có chung giải pháp: chuyển log ra khỏi instance và để CloudWatch xử lý log.

Lỗi thanh toán lúc 14:02 hai ngày trước, trên i-web3
Auto Scaling groupKỹ sưi-web3đã terminate hôm quai-web9instance mới, không có lỗiCloudWatch Logslog group /mftech/web

Chọn tình huống, sau đó chọn nút chạy. Thay đổi cấu hình và chạy lại để so sánh.

Xem nhật ký của nhà máy bị dỡ được giữ lại, và sổ ghi API biến lệnh gọi trái phép thành cảnh báo.

Trail gửi event tới một S3 bucket, và có thể gửi thêm tới CloudWatch Logs và EventBridge; Kinesis không nằm trong các đích này. CloudTrail gửi log trung bình khoảng 5 phút sau lệnh gọi API (thời gian này không được đảm bảo). Ngưỡng của alarm trong tình huống trên đã được xác định trước (số lệnh gọi bị AccessDenied), do đó metric filter và alarm là cơ chế trực tiếp nhất.

CloudTrail Insights giải quyết bài toán khác, khi chưa biết trước ngưỡng: Insights phân tích management event và data event trong quá khứ để xác lập baseline của tốc độ gọi API và tỷ lệ lỗi API, sau đó sinh Insights event khi hoạt động hiện tại lệch khỏi baseline. Insights tính phí riêng; lần đầu bật trên một trail, CloudTrail có thể mất tới 36 giờ mới bắt đầu gửi Insights event. Insights event cũng có thể được gửi vào CloudWatch Logs cùng với các event khác của trail.

Một yêu cầu khác liên quan tới vị trí triển khai: MFTECH mở rộng sang mảng ví điện tử, và quy định bắt buộc dữ liệu cùng workload phải nằm trong on-premises data center của công ty. Đội kỹ thuật vẫn cần Kubernetes do AWS quản lý, cùng IAM và CloudWatch như trên cloud. Giải pháp là AWS Outposts: AWS lắp đặt Outpost tại on-premises site của khách hàng, mở rộng hạ tầng, dịch vụ, API và công cụ của AWS tới đó; EC2, EBS, ECS, RDS và Amazon EKS chạy tại chỗ, còn AWS vận hành và giám sát capacity này như một phần của Region. Direct Connect và Local Zone vẫn đặt workload trên hạ tầng của AWS; Snowball Edge là thiết bị chuyển dữ liệu và xử lý tại biên, và hiện không còn cung cấp cho khách hàng mới.

Ghi nhớ:
  • Log phải được chuyển ra khỏi instance trước khi instance bị terminate: cài đặt CloudWatch agent để gửi log lên CloudWatch Logs.
  • Cảnh báo gần thời gian thực về API call bất thường: CloudTrail gửi vào CloudWatch Logs, metric filter đếm lỗi, alarm gửi thông báo qua SNS.
  • Đích của trail: S3, CloudWatch Logs, EventBridge (không có Kinesis).
  • Phát hiện tốc độ gọi API hoặc tỷ lệ lỗi lệch khỏi baseline mà không cần đặt ngưỡng: CloudTrail Insights (tính phí riêng).
  • Dữ liệu bắt buộc lưu tại chỗ nhưng vẫn cần dịch vụ AWS: Outposts.
Part 3/6 · 8 phút

Centralizing logs with CloudWatch Logs and metric filters

0/12
Từ khóa của phần nàyChọn một từ để xem nghĩa trước khi đọc

EC2 instances in an Auto Scaling group can be terminated at any time, and logs stored on an instance are lost with it; logs must be sent to CloudWatch Logs for central storage.

MFTECH’s Auto Scaling group scales very frequently, with new instances replacing old ones almost every day. A user reports a payment error that happened two days ago, but the instance involved has already been terminated. In another incident, a leaked access key was used to call APIs continuously at night. Both incidents share a solution: move logs off the instance and let CloudWatch process them.

Lỗi thanh toán lúc 14:02 hai ngày trước, trên i-web3
Auto Scaling groupKỹ sưi-web3đã terminate hôm quai-web9instance mới, không có lỗiCloudWatch Logslog group /mftech/web

Chọn tình huống, sau đó chọn nút chạy. Thay đổi cấu hình và chạy lại để so sánh.

Xem nhật ký của nhà máy bị dỡ được giữ lại, và sổ ghi API biến lệnh gọi trái phép thành cảnh báo.

A trail delivers events to an S3 bucket, and can also deliver them to CloudWatch Logs and EventBridge; Kinesis is not one of these destinations. CloudTrail delivers logs within an average of about 5 minutes of an API call (this time is not guaranteed). The alarm threshold in the scenario above is known in advance (the number of calls denied with AccessDenied), so a metric filter and an alarm are the most direct mechanism.

CloudTrail Insights solves a different problem, for when the threshold is not known in advance: Insights analyzes past management and data events to establish a baseline of API call rates and API error rates, then generates Insights events when current activity deviates from the baseline. Insights is charged separately; after Insights is enabled on a trail for the first time, CloudTrail may take up to 36 hours to begin delivering Insights events. Insights events can also be sent to CloudWatch Logs together with the trail’s other events.

Another requirement concerns the deployment location: MFTECH is expanding into e-wallets, and regulations require the data and workloads to stay in the company’s on-premises data center. The engineering team still needs AWS-managed Kubernetes, along with IAM and CloudWatch as in the cloud. The solution is AWS Outposts: AWS installs an Outpost at the customer’s on-premises site, extending AWS infrastructure, services, APIs and tools there; EC2, EBS, ECS, RDS and Amazon EKS run on premises, while AWS operates and monitors this capacity as part of the Region. Direct Connect and Local Zones still place workloads on AWS infrastructure; Snowball Edge is a device for data transfer and edge processing, and it is no longer available to new customers.

Ghi nhớ:
  • Logs must be moved off an instance before it is terminated: install the CloudWatch agent to send logs to CloudWatch Logs.
  • Near-real-time alerts on unusual API calls: CloudTrail sends to CloudWatch Logs, a metric filter counts the errors, an alarm notifies through SNS.
  • Trail destinations: S3, CloudWatch Logs, EventBridge (not Kinesis).
  • Detect API call rates or error rates that deviate from a baseline without setting a threshold: CloudTrail Insights (charged separately).
  • Data that must stay on premises but still needs AWS services: Outposts.

Kiểm tra nhanh

Trả lời để ghi nhận đã đọc phần này. Câu trả lời sai sẽ được nhắc ôn lại vào những ngày sau.

Người dùng báo lỗi thanh toán xảy ra hai ngày trước, nhưng EC2 instance liên quan trong Auto Scaling group đã bị terminate cùng log. Cách ngăn tình trạng này?
Đội bảo mật cần cảnh báo gần thời gian thực khi số lệnh gọi API bị AccessDenied vượt một ngưỡng đã biết. Chọn gì?

Đã trả lời 0/2 câu