Skip to content

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

@Warren-Byron

Description

@Warren-Byron

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions