How to make an Amazon S3 bucket read-only? - Big Data In Real World

How to make an Amazon S3 bucket read-only?

How to specify join hints with Spark 3.0?
February 5, 2021
How to convert RDD to DataFrame and Dataset in Spark?
February 10, 2021
How to specify join hints with Spark 3.0?
February 5, 2021
How to convert RDD to DataFrame and Dataset in Spark?
February 10, 2021

In this post we are going to create a S3 policy to make the S3 bucket read-only. We will be denying all users access to create or remove objects in the bucket.

Creating a policy with policy generator

AWS provides a user friendly tool to create policies. Based on the selected options, the tool will generate a policy in JSON format.

Here we are creating a Deny policy for all Principals. Under Actions we select PutObject and DeleteObject. Make sure to add the ARN correct bucket name – arn:aws:s3:::hirw-test-bucket/* . In this example we are protecting hire-test-bucket.
aws-s3-policy-generator

Click generate policy and copy the JSON.

aws-s3-policy-generator-json

Go back to the AWS S3 console and open the bucket. 

aws-s3-bucket-permissions

Paste the JSON under Bucket Policy by clicking Edit.
aws-s3-bucket-policy

Check bucket permissions

Currently we have only one file in the hirw-test-bucket 

[osboxes@wk1 ~]$ aws s3 ls s3://hirw-test-bucket

2020-11-18 19:05:41         26 test-file

Let’s try to upload an object and recursively remove objects from the bucket. As you can both operations get an “Access Denied”

[osboxes@wk1 ~]$ aws s3 cp test-file2 s3://hirw-test-bucket

upload failed: ./test-file2 to s3://hirw-test-bucket/test-file2 
An error occurred (AccessDenied) when calling the PutObject operation: Access Denied

[osboxes@wk1 ~]$ aws s3 rm --recursive s3://hirw-test-bucket

delete failed: s3://hirw-test-bucket/test-file 
An error occurred (AccessDenied) when calling the DeleteObject operation: Access Denied

[osboxes@wk1 ~]$ aws s3 ls s3://hirw-test-bucket

2020-11-18 19:05:41         26 test-file

 

Big Data In Real World
Big Data In Real World
We are a group of Big Data engineers who are passionate about Big Data and related Big Data technologies. We have designed, developed, deployed and maintained Big Data applications ranging from batch to real time streaming big data platforms. We have seen a wide range of real world big data problems, implemented some innovative and complex (or simple, depending on how you look at it) solutions.

Comments are closed.

How to make an Amazon S3 bucket read-only?
This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.

Hadoop In Real World is now Big Data In Real World!

X