Skip to content

CloudFront Access Denied

0

After I deployed my react app with aws amplify, I added domain name using Route 53. But I am not able to upload image/file to s3 bucket. I am receiving this error message "POST https://cognito-identity.us-east-2.amazonaws.com/ 400 (Bad Request), Uncaught (in promise) InvalidIdentityPoolConfigurationException: Invalid identity pool configuration. Check assigned IAM roles for this pool" . I am not using AWS Authentication. Why am I getting this error? How can I upload a file to s3 bucket from my domain name (website)? Any comments or answers?Enter image description here

1 Answer
0

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.