I am working on a Node.js app deployment on Elastic beanstalk. Deployment goes well. EB Health is on OK status. Logs show server runs successfully. But when I run my frontend application deployed on S3, I get CORS error. I have set CORS on S3 as follows
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"DELETE"
],
"AllowedOrigins": [
"http://udagram-tauseef.s3-website-us-east-1.amazonaws.com"
],
"ExposeHeaders": [
"x-amz-server-side-encryption",
"x-amz-request-id",
"x-amz-id-2"
],
"MaxAgeSeconds": 3000
}
]
And here's code for CORS in backend application.
const corsOptions = {
origin: '*',
optionsSuccessStatus: 200,
}
app.use(cors(corsOptions))
Bucket Policy that I'm using
{
"Version": "2012-10-17",
"Id": "BucketPolicy",
"Statement": [
{
"Sid": "AllAccess",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::mydemos3bucket",
"arn:aws:s3:::mydemos3bucket/*"
]
},
{
"Sid": "eb-ad78f54a-f239-4c90-adda-49e5f56cb51e",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::000246328708:role/aws-elasticbeanstalk-ec2-role"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::mydemos3bucket/resources/environments/logs/*"
},
{
"Sid": "eb-af163bf3-d27b-4712-b795-d1e33e331ca4",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::000246328708:role/aws-elasticbeanstalk-ec2-role"
},
"Action": [
"s3:ListBucket",
"s3:ListBucketVersions",
"s3:GetObject",
"s3:GetObjectVersion"
],
"Resource": [
"arn:aws:s3:::mydemos3bucket",
"arn:aws:s3:::mydemos3bucket/resources/environments/*"
]
},
{
"Sid": "eb-58950a8c-feb6-11e2-89e0-0800277d041b",
"Effect": "Deny",
"Principal": {
"AWS": "*"
},
"Action": "s3:DeleteBucket",
"Resource": "arn:aws:s3:::mydemos3bucket"
}
]
}
Also tried app.use(cors())
Here is the link to last EB Log file.
But still I am unable to get it resolved.
Here's an ss of error.
I have configured everything following documentation. But I'm stuck on this issue. Do I have to do something on EB? Or should I update CORS policy on S3 Bucket? Please let me know if I need to add more details to the question.
EDIT:
Here are network response headers on the API.
And here too, if you wanna see the OPTIONS header.