- Newest
- Most votes
- Most comments
The root cause of your AccessDenied error is likely a combination of factors related to cross-account and cross-region access. Let's break down the issues:
-
Cross-account access: Your CodeBuild project is in Account A, but you're trying to access a bucket in Account B. The bucket policy you've shown only allows access from Account A, which is correct, but there might be additional steps needed.
-
Cross-region access: Your CodeBuild project is in Region A, but you're trying to access a bucket in Region B. This isn't directly causing the issue, but it's important to note.
-
Bucket policy: The policy you've shown is allowing access, but it might not be the complete policy. Make sure there are no conflicting statements in the full policy.
-
KMS encryption: If the bucket is using AWS KMS for encryption (SSE-KMS), you'll need to grant the CodeBuild role permissions to use the KMS key as well.
-
S3 Block Public Access: This setting is correct and shouldn't interfere with your cross-account access.
To resolve this issue:
-
Ensure the CodeBuild role in Account A has the necessary permissions to access the S3 bucket in Account B. This includes both S3 actions and KMS actions if KMS encryption is used.
-
In the bucket policy in Account B, make sure you're using the correct ARN for the CodeBuild role. Double-check that the account number and role name are correct.
-
If using KMS encryption, add a policy to the KMS key in Account B that allows the CodeBuild role from Account A to use the key.
-
Verify that there are no VPC endpoint policies or other network configurations that might be restricting access.
-
When using the AWS CLI in your CodeBuild project, ensure you're using the correct credentials. The error message suggests that the CLI might not be using the CodeBuild role's credentials.
By addressing these points, you should be able to resolve the AccessDenied error and successfully sync files across accounts and regions.
Sources
Community | AWS Cross Account S3 Access Through Lambda Functions
Troubleshoot 403 Access Denied error in Amazon S3 | AWS re:Post
cross-account permissions for S3 bucket access | AWS re:Post
Relevant content
asked a year ago
