DEV Community

Hidetaka Okamoto for AWS Community Builders

Posted on • Originally published at wp-kyoto.net

7 1

When you suffer from the "API: s3:PutBucketPolicy Access Denied" error while creating a new S3 bucket, how can we resolve it?

Due to changing the default configuration of Amazon S3, we need to add the blockPublicAccess attribute to the CDK project.

What error did I see?

When I tried to create a new Amazon S3 bucket for hosting a new website:

    const websiteBucket = new Bucket(this, 'SonikStaticAssets', {
      websiteIndexDocument: 'index.html',
      publicReadAccess: true,
    });

I met the following CloudFormation error.

CdkSonikAppStack: deploying... [1/1]
CdkSonikAppStack: creating CloudFormation changeset...
10:08:29 PM | CREATE_FAILED        | AWS::S3::BucketPolicy       | SonikStaticAssetsPolicy8AA45F84
API: s3:PutBucketPolicy Access Denied


 ❌  CdkSonikAppStack failed: Error: The stack named CdkSonikAppStack failed to deploy: UPDATE_ROLLBACK_COMPLETE: API: s3:PutBucketPolicy Access Denied

Add the blockPublicAccess attributes to resolve this issue.

To avoid this error, we need to add the blockPublicAccess: BlockPublicAccess.BLOCK_ACLS attributes.

    const websiteBucket = new Bucket(this, 'SonikStaticAssets', {
      websiteIndexDocument: 'index.html',
      publicReadAccess: true,
      blockPublicAccess: BlockPublicAccess.BLOCK_ACLS,
    });

Referenced

Top comments (0)

Create a simple OTP system with AWS Serverless cover image

Create a simple OTP system with AWS Serverless

Implement a One Time Password (OTP) system with AWS Serverless services including Lambda, API Gateway, DynamoDB, Simple Email Service (SES), and Amplify Web Hosting using VueJS for the frontend.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay