This post will go through the steps of setting up a S3 origin in an AWS CloudFront distribution for a bucket created in a different AWS account. You will need access to the CloudFront distribution as well as the S3 bucket. This may be useful when your CloudFront distribution needs to access data hosted by other teams within your organization.
Steps in AWS CloudFront (account A)
- Navigate to the CloudFront distribution in the AWS console
- Create Origin
- Origin Domain Name: <bucket-name>.s3.<aws-region>.amazonaws.com
- Restrict Bucket Access: Yes
- Origin Access Identity: Create a New Identity or Use an Existing Identity (will need the Origin Access ID later for the S3 bucket policy)
- Grant Read Permissions on Bucket: No, I Will Update Permissions
Steps in AWS S3 (account B)
- Navigate to the S3 bucket named <bucket-name> in the AWS console
- Click on Permissions tab
- Edit Bucket Policy
- Add the following policy
"AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity <ORIGIN_ACCESS_ID_IN_CLOUDFRONT_STEP_5>"
After you have followed all the steps above, you can set up a behavior in the CloudFront distribution that routes requests to the S3 origin. Then, you should be able to access objects in the S3 bucket created in AWS account B through the CloudFront distribution behavior created in AWS account A.