Difficulty: Intermediate
What is a CloudFront Origin Access Identity (OAI), and how does it compare to the newer Origin Access Control (OAC)?
An Origin Access Identity (OAI) is a special CloudFront identity you grant read access to in an S3 bucket policy, so the bucket can stay private and users can fetch files only through CloudFront, not through direct S3 URLs. OAI is now the legacy approach: since 2022 AWS recommends Origin Access Control (OAC), which does the same job with SigV4-signed requests and supports more scenarios such as SSE-KMS encrypted objects.
If your React app's static build, product images or invoice PDFs sit in a public bucket, anyone can bypass CloudFront and hit bucket.s3.ap-south-1.amazonaws.com directly. That means:
Restricting the origin forces every request through the CDN, where your security and caching rules live.
s3:GetObject to the principal arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity <ID>.403 AccessDenied.With OAC, CloudFront signs each origin request with SigV4 as the cloudfront.amazonaws.com service principal, and the bucket policy uses a condition on AWS:SourceArn to allow only your specific distribution.
| Feature | OAI (legacy) | OAC (recommended) |
|---|---|---|
| SSE-KMS encrypted objects | Not supported | Supported (grant the key to CloudFront) |
| Dynamic requests (PUT, POST, DELETE) to S3 | Limited | Supported |
| All Regions, including newer opt-in Regions | No | Yes |
| Scope of access | Any distribution using that OAI | Pinned to one distribution ARN |
| Other origin types | S3 only | S3, plus Lambda function URLs and some media origins |
If you are asked about OAI in an interview, describe it, then say you would use OAC for anything new.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCloudFrontOACRead",
"Effect": "Allow",
"Principal": { "Service": "cloudfront.amazonaws.com" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-frontend-prod/*",
"Condition": {
"StringEquals": {
"AWS:SourceArn": "arn:aws:cloudfront::111122223333:distribution/E2ABCDEF123456"
}
}
}
]
}
Only requests signed by this specific distribution are allowed; any other CloudFront distribution or direct S3 request is denied.
{
"Sid": "AllowOAIRead",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity E1EXAMPLE123"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-frontend-prod/*"
}
OAI uses a special IAM-style principal; you will still see this in older stacks and should recognise it when migrating.
Origin Access Identity, Origin Access Control, S3 Bucket Policy, CloudFront, SigV4