Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access Denied Error When Applying S3 Bucket Policy in Lesson 01 - Solution Provided #2

Open
Warren-Byron opened this issue Jul 19, 2024 · 0 comments

Comments

@Warren-Byron
Copy link

Warren-Byron commented Jul 19, 2024

Problem

I am referring to this page: https://github.com/fourTheorem/serverless-ecommerce-workshop/tree/main/lessons/01-deploying-the-frontend

When I tried to run this command under the "Bucket policies" section:

aws s3api put-bucket-policy --bucket $FRONTEND_BUCKET --policy file://policy.json

I encountered the following error:

An error occurred (AccessDenied) when calling the PutBucketPolicy operation: Access Denied

Analysis

The error indicates that the operation was denied due to access control restrictions on the S3 bucket. This typically happens when the bucket has public access policies that block changes to bucket policies.

Fix

To resolve this issue, I had to disable the BlockPublicPolicy setting on the S3 bucket. The following command was used to update the bucket's public access block configuration:

aws s3api put-public-access-block --bucket $FRONTEND_BUCKET --public-access-block-configuration "BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"

After running the above command, I was able to successfully execute the original put-bucket-policy command without encountering the Access Denied error.

Additional Note

The command also ensures that "Block all public access" is turned off for all four settings, which is required before the pages are served.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant