Tạo S3

Tạo S3 bucket

  1. Truy cập S3 console tại https://console.aws.amazon.com/s3/
    • Chọn General purpose buckets
    • Chọn Create bucket Create S3
  2. Trong General configuration:
    • AWS Region: cùng Region với EC2 instance
    • Bucket type: General purpose
    • Bucket namespace: Account Regional namespace (recommended)
    • Bucket name prefix: cloudfront-lab Create S3

      AWS thêm hậu tố vào prefix, nên tên bucket sẽ là cloudfront-lab-<account-id>-<region>-an.

  3. Giữ mặc định:
    • Block Public Access settings for this bucket: giữ chọn Block all public access
    • Bucket Versioning: Disable Create S3

      Bucket giữ ở chế độ private. Ở phần 3, bạn cấp quyền cho CloudFront truy cập bucket.

  4. Giữ các mặc định còn lại và chọn Create bucket:
    • Default encryption: Server-side encryption with Amazon S3 managed keys (SSE-S3)
    • Bucket Key: Enable Create S3

Tải lên index.html

  1. Trên máy tính, tạo file index.html với nội dung sau:
<!DOCTYPE html>
<html lang="en">
  <body>
    <table border="1" width="100%">
      <thead>
        <tr>
          <td><h1>CloudFront Lab</h1></td>
        </tr>
      </thead>
      <tfoot>
        <tr>
          <td>Immersion Days - Edge Services - Module 1</td>
        </tr>
      </tfoot>
      <tbody>
        <tr>
          <td>Response sent by API</td>
        </tr>
      </tbody>
      <tbody>
        <tr>
          <td>
            <iframe src="/api" style="width: 100%; height: 100%"></iframe>
          </td>
        </tr>
      </tbody>
    </table>
  </body>
</html>
  1. Trong S3 console, mở bucket. Tại tab Objects, chọn Upload. Create S3
  2. Chọn Add files, chọn index.html, sau đó chọn Upload. Create S3
  3. Kiểm tra trang Upload: status. Create S3
  4. Chọn index.html và sao chép Object URL. Create S3
  5. Mở Object URL trong tab mới. S3 trả về AccessDenied vì bucket chặn truy cập public. Đây là kết quả mong đợi: ở các phần sau bạn truy cập file qua CloudFront. Create S3