First time using AWS S3 here. I've been trying to figure this out the entire week but I just can't get my Django + NGINX site to display both my CSS and uploaded images from S3. I'm probably missing something but I just don't know exactly. I've looked into this, this, and this but I'm still unable to get things running.
I have a Bucket Policy and a CORS Config in my bucket maybe you can take a look. What I have so far:
- My site works fine only without any CSS or other static files like images
- CSS and image file URLs are correct. They all direct to my S3 bucket.
- Image uploading has no problem saving to S3
- To test, accessing each CSS/image manually from the browser returns the standard AccessDenied page from S3
- I have an IAM role with the
AmazonS3FullAccess
policy applied to my EC2 instance - All public access is blocked in my bucket
My Bucket Policy
For testing purposes, I created a user with AmazonS3FullAccess
along with the role. Not sure if that's necessary...
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::<NUMBERS>:role/<MYEC2ROLE>",
"arn:aws:iam::<NUMBERS>:role/<MYUSER>",
]
},
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::<MYBUCKET>",
"arn:aws:s3:::<MYBUCKET>/*"
]
}
]
}
My CORS Configuration
My gut tells me this is not needed. Or maybe I'm just hungry...
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<ExposeHeader>ETag</ExposeHeader>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Was there anything else I was supposed to do? I'll continue reading up on this and maybe figure it out.