Tạo dữ liệu mẫu

Tạo dữ liệu mẫu

Trong bước này, chúng ta sẽ cấu hình Kinesis Data Generator (KDG) để tạo ra các dữ liệu mẫu và đẩy chúng vào Amazon Data Firehose. KDG là công cụ dựa trên web giúp đơn giản hóa việc gửi dữ liệu thử nghiệm tới Kinesis stream/Firehose.

Kinesis Data Generator yêu cầu một Amazon Cognito user pool để xác thực. Chúng ta sẽ triển khai một CloudFormation stack để tự động thiết lập Cognito và tạo URL đăng nhập KDG.

Cấu hình Amazon Cognito cho Kinesis Data Generator

  1. Truy cập AWS Management Console.

    • Tìm CloudFormation.
    • Chọn CloudFormation.

    Tìm CloudFormation

  2. Trong giao diện CloudFormation.

    • Chọn Stacks.
    • Chọn Create stack.
    • Chọn With new resources (standard).

    Tạo Stack

  3. Tải file cognito-setup.yaml từ First Cloud AI Journey.

    • Sử dụng phím tắt Ctrl + S để Save.
  4. Trong giao diện Create stack.

    • Chọn Choose an existing template.
    • Chọn Upload a template file.
    • Chọn Choose file.
    • Chọn cognito-setup.yaml.
    • Chọn Next.

    Upload Template

  5. Trong giao diện Specify stack details.

    • Stack name, nhập Kinesis-Data-Generator-Cognito-User.
    • Cấu hình các tham số Kinesis Data Generator Cognito Configuration:
      • Create demo Cognito user, chọn true.
      • Demo username, nhập kdguser.
      • Demo password, nhập password bạn muốn sử dụng.
    • Chọn Next.

    Chi tiết Stack

  6. Trong giao diện Configure stack options.

    • Chọn I acknowledge that AWS CloudFormation might create IAM resources.
    • Chọn Next.

    Xác nhận IAM

  7. Trong giao diện Review and create.

    • Xem lại các tùy chọn tạo stack.
    • Chọn Submit.

    Submit Stack

  8. Đợi khoảng 3 phút để hoàn thành tạo stack.

    • Chọn Kinesis-Data-Generator-Cognito-User stack.
    • Chọn Events để xem quá trình khởi tạo.
    • Trạng thái sẽ hiển thị CREATE_IN_PROGRESS.

    Stack đang tạo

  9. Sau khi stack được tạo thành công.

    • Trạng thái sẽ chuyển sang CREATE_COMPLETE.
    • Bạn có thể xem Latest deployment timeline.

    Stack tạo xong

  10. Trong giao diện Stack.

    • Chọn Kinesis-Data-Generator-Cognito-User stack.
    • Chọn Outputs.
    • Tìm KinesisDataGeneratorUrl và click vào URL.

    Outputs KDG URL

  11. Trong giao diện Amazon Kinesis Data Generator.

    • Nhập Username: kdguser.
    • Nhập Password.
    • Chọn Sign In.

    Đăng nhập KDG

  12. Nếu Kinesis Data Generator hiển thị lỗi cấu hình, quay lại CloudFormation tab Outputs.

    • Sao chép các giá trị UserPoolClientId và UserPoolId.

    Chi tiết Outputs

  13. Cuộn lên trong tab Outputs để xem đầy đủ 6 giá trị output.

    • Ghi nhận các giá trị IdentityPoolId, KinesisDataGeneratorUrl và các giá trị khác.

    Toàn bộ Outputs

  14. Trong Amazon Kinesis Data Generator, chọn Configure.

    • Nhập các giá trị Cognito configuration từ CloudFormation Outputs.
    • Chọn Save Changes.

    Cấu hình KDG

  15. Sau khi cấu hình và đăng nhập thành công.

    • Region, chọn region nơi bạn tạo Delivery stream (ví dụ: ap-southeast-1).
    • Stream/delivery stream, chọn Firehose stream của bạn.
    • Records per second, nhập 2000.
    • Chọn Template 1.

    Cài đặt KDG

  16. Nhập đoạn mã sau vào editor Template 1:

    {
      "uuid": "{{random.uuid}}",
      "device_ts": "{{date.utc("YYYY-MM-DD HH:mm:ss.SSS")}}",
      "device_id": {{random.number(50)}},
      "device_temp": {{random.weightedArrayElement(
        {"weights":[0.30, 0.30, 0.20, 0.20],"data":[32, 34, 28, 40]}
      )}},
      "track_id": {{random.number(30)}},  
      "activity_type": {{random.weightedArrayElement(
            {
                "weights": [0.1, 0.2, 0.2, 0.3, 0.2],
                "data": ["\"Running\"", "\"Working\"", "\"Walking\"", "\"Traveling\"", "\"Sitting\""]
            }
        )}}
    }
    
    • Sau đó, chọn Send data.

    Gửi dữ liệu

  17. Sau khi gửi khoảng ~ 100,000 messages.

    • Bạn có thể chọn Stop Sending Data to Kinesis.

    Dừng gửi

  18. Kiểm tra đảm bảo dữ liệu đã đi tới S3. Truy cập AWS Management Console.

    • Tìm S3.
    • Chọn S3.

    Tìm S3

  19. Trong giao diện S3.

    • Chọn Bucket.
    • Chọn S3 bucket của bạn.

    Chọn Bucket

  20. Trong giao diện Bucket.

    • Chọn folder data.

    Folder data

  21. Chọn folder raw2026 bên trong folder data.

    • Bạn sẽ thấy các folder raw2026/ và reference_data/.

    Folder raw data

  22. Dữ liệu đã được gửi thành công tới S3.

    • Bạn có thể thấy các file Firehose stream bên trong folder.

    Dữ liệu trong S3