S3 with cloudfront service


Background

To ensure smooth content/video streaming all over the world, we need to place a copy of the media across servers in the world. So US users do not need to download content in UK server, they can download it more quickly in US server.

Steps

  1. Create S3 Bucket with a specific bucket name. (default is ok)
  2. Upload a video file.
  3. Create Cloudfront distirbution under Networking & Content Delivery → Web,
  4. 
    Origin Domain Name: {bucket-name}.s3.amazonaws.com
    Origin Path: 
    Enable Origin Shield: No
    Origin ID: S3-{bucket-name}
    Restrict Bucket Access: Yes
    Origin Access Identity: Create a New Identity
    Comment: access-identity-{bucket-name}.s3.amazonaws.com
    Grant Read Permissions on Bucket: Yes, Update Bucket Policy
    Viewer Protocol Policy: Redirect HTTP to HTTPS
    Cache and origin request settings: Use a cache policy and origin request policy
    SSL Certificate: Default CloudFront Certificate (*.cloudfront.net)
        
  5. Once it is created, get in your cloudfront distribution → Invalidation → Create invalidation → Edit Object Paths: /
  6. Now you will have an endpoint with a format https://{hash}.cloudfront.net/media .

References