- Newest
- Most votes
- Most comments
The error you're encountering suggests there's an issue with your Cognito Identity Pool configuration, which is typically used for authentication and authorization in AWS. Even though you mentioned you're not using AWS Authentication, it appears that your application is still trying to use Cognito for some operations.
To resolve this issue and enable file uploads to your S3 bucket from your website, you'll need to take the following steps:
-
Check your Amplify configuration: Review your Amplify project settings to ensure you haven't inadvertently enabled Cognito or authentication features you don't intend to use.
-
Configure CORS for your S3 bucket: Enable Cross-Origin Resource Sharing (CORS) on your S3 bucket to allow requests from your domain. This is crucial for allowing file uploads from your website.
-
Set up appropriate IAM roles: Create an IAM role with the necessary permissions to access your S3 bucket. This role should have policies that allow actions like s3:PutObject for file uploads.
-
Use pre-signed URLs: Instead of direct uploads to S3, generate pre-signed URLs on your server and use these for file uploads from the client-side. This method is more secure and doesn't require exposing your AWS credentials in the frontend.
-
Update your frontend code: Modify your React app to use the pre-signed URLs for uploads instead of trying to interact with Cognito or S3 directly.
-
Check CloudFront settings: If you're using CloudFront, ensure that your distribution is correctly configured to work with your S3 bucket, including proper Origin Access Identity (OAI) or Origin Access Control (OAC) settings.
By following these steps, you should be able to resolve the Cognito error and successfully implement file uploads to your S3 bucket from your website. Remember to always use secure methods for handling file uploads and never expose AWS credentials in your frontend code.
Sources
Access Denied for CloudFront to S3 | AWS re:Post
S3/Cloudfront & OAC: Access denied when accessing path other than index site | AWS re:Post
Cloudfront URL giving me AccessDenied error. | AWS re:Post
answered 2 years ago
Relevant content
asked 3 years ago
