- Newest
- Most votes
- Most comments
Based on the error message and the information provided, it appears that the issue is related to VPC endpoint policies rather than the IAM role permissions. The error specifically mentions "because no VPC endpoint policy allows the s3:PutBucketCORS action". This suggests that your ECS task is running in a VPC with an S3 VPC endpoint, and the endpoint policy is not allowing the PutBucketCORS action.
To resolve this issue, you need to:
-
Locate the S3 VPC endpoint being used by your ECS task.
-
Check the policy attached to this VPC endpoint. It should include permissions for the s3:PutBucketCORS action.
-
Modify the VPC endpoint policy to allow the required S3 actions, including PutBucketCORS. Here's an example of how the policy might look:
{ "Statement": [ { "Action": [ "s3:PutBucketCORS", "s3:PutBucketWebsite", "s3:CreateBucket", "s3:PutObject", "s3:GetObject", "s3:ListBucket", "s3:DeleteObject" ], "Effect": "Allow", "Resource": "*", "Principal": "*" } ] }Make sure to include all the S3 actions that your application needs to perform.
-
After updating the VPC endpoint policy, it may take a few minutes for the changes to propagate.
-
If you're still experiencing issues after updating the VPC endpoint policy, you may need to restart your ECS tasks to ensure they pick up the new permissions.
Remember, when using VPC endpoints, both the IAM role permissions and the VPC endpoint policy need to allow the required actions. The IAM role permissions you've set look correct, so focusing on the VPC endpoint policy should resolve the issue.
Sources
Troubleshoot issues with Amazon ECS connection to Amazon S3 | AWS re:Post
Troubleshoot permissions issues in Amazon ECS | AWS re:Post
Using IAM roles with Amazon ECS tasks - Amazon Elastic Container Service
answered 2 years ago
There are couple of things you can check.
- VPC endpoint policy as mentioned in previous answer - you can allow all actions and confirm if it works.
- S3 bucket policy - check if the bucket policy is allowing this permission.
## bucket policy
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowECS",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::{AccountId}:role/my-role"
},
"Action": [
"s3:PutBucketCORS",
"s3:PutBucketWebsite",
"s3:CreateBucket",
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::my-bucket-{AccountId}/*"
"arn:aws:s3:::my-bucket-{AccountId}/*"
]
}
]
}
Also, why are you updating CORS from ECS? I suspect it's a one off setup and therefore you can just have the setup in S3 directly.
Relevant content
asked 4 years ago

So I set my principal in the VPC endpoint policy to
{"AWS": "arn:aws:iam::000000000:role/myapp_staging_task"}, but it doesn't not allow it.myapp_staging_taskis the task for the ECS task running in the container. However, if I just usePrincipal: "*"it works. I'm getting awfully tired of buggering around with the policy so I'm inclined to just take the W and move on. So why's it not working?