Create Bucket Policy in AWS S3 Bucket with Python Last Updated : 28 Mar, 2023 Comments Improve Suggest changes Like Article Like Report Bucket policy of s3 bucket means permission and action which can be applied on the particular bucket. AWS S3 has an optional policy that can be used to restrict or grant access to an S3 bucket resource. It is important to note that bucket policies are defined in JSON format. For creating a bucket policy in python we will follow the below steps: Step 1: The first step for creating a bucket policy is we need to import python SDK boto3. This will provide methods to us by that we can access the resources of the AWS. And for the policy string dumping, we need to also import JSON. import json import boto3Step 2: The Second step will be we need to create a policy string. Policy string is a key-value pair dictionary. In which the first key will be the Version. And the second key will be the statement in the statement first key will be the sid which will store how to type the policy we want to add. And the second key will be the Effect which will store the access status and the third key will be the permission which will store who have permission to access and the fourth key will be an action which will what type of operation we can perform and the last parameter in this Resource on which we will apply this policy. Example: bucket_policy = { "Version": "2012-10-17", "Statement": [ { "Sid": "AddPerm", "Effect": "Allow", "Principal": "*", "Action": ["s3:*"], "Resource": ["arn:aws:s3:::gfgbucket/*"] } ] } Step 3: The third step will need to convert the bucket policy string in JSON. json.dumps(bucket_policy) Step 4: The fourth step will be for putting bucket policy to the bucket we need to call put_bucket_policy() function .this function will take the first parameter the bucket name and the second parameter will be the policy string. put_bucket_policy(Bucket,policy) Step 5: The last step will be to go to AWS->S3->Bucket->Permission->Bucket policy and verify. Complete code: Python3 import json import boto3 s3_client=boto3.client('s3') BUCKET_NAME='gfgbucket' def create_bucket_policy(): bucket_policy = { "Version": "2012-10-17", "Statement": [ { "Sid": "AddPerm", "Effect": "Allow", "Principal": "*", "Action": ["s3:*"], "Resource": ["arn:aws:s3:::gfgbucket/*"] } ] } policy_string = json.dumps(bucket_policy) s3_client().put_bucket_policy( Bucket=BUCKET_NAME, Policy=policy_string ) Output: Comment C cse1604310056 Follow 0 Improve C cse1604310056 Follow 0 Improve Article Tags : Cloud Computing Explore Cloud Computing Tutorial 10 min read Basics Of Cloud ComputingIntroduction to Cloud Computing 10 min read History of Cloud Computing 4 min read Evolution of Cloud Computing 6 min read Characteristics of Cloud Computing 2 min read Advantages of Cloud Computing 8 min read Architecture of Cloud Computing 6 min read Cloud Computing Infrastructure 3 min read Cloud Management in Cloud Computing 6 min read What is Cloud Storage? 15 min read Real World Applications of Cloud Computing 6 min read Cloud Deployment ModelsCloud Deployment Models 12 min read Types of Cloud Computing 12 min read Difference Between Public Cloud and Private Cloud 6 min read Public Cloud vs Private Cloud vs Hybrid Cloud 7 min read Cloud Service ModelsCloud Based Services 11 min read Platform As A Service (PaaS) and its Types 11 min read Software As A Service (SaaS) 2 min read SaaS, PaaS and IaaS 4 min read Cloud VirtualizationVirtualization in Cloud Computing and Types 6 min read Difference between Cloud Computing and Virtualization 4 min read Pros and Cons of Virtualization in Cloud Computing 5 min read Data Virtualization 9 min read Hardware Based Virtualization 5 min read Server Virtualization 3 min read Types of Server Virtualization in Computer Network 4 min read Network Virtualization in Cloud Computing 4 min read Operating system based Virtualization 5 min read Cloud Service ProviderAmazon Web Services (AWS) Tutorial 9 min read Microsoft Azure Tutorial 13 min read Google Cloud Platform Tutorial 8 min read Advanced Concepts of CloudOn Premises VS On Cloud 3 min read Differences between Cloud Servers and Dedicated Servers 4 min read Cloud Networking 4 min read Server Consolidation in Cloud Computing 6 min read Hypervisor Security in Cloud Computing 5 min read Cloud Computing Security 5 min read Security Issues in Cloud Computing 5 min read 7 Privacy Challenges in Cloud Computing 5 min read Security Threats in Implementing SaaS of Cloud Computing 6 min read Multitenancy in Cloud computing 2 min read Middleware in Grid Computing 2 min read Difference between Cloud Computing and Grid Computing 4 min read Scalability and Elasticity in Cloud Computing 4 min read Cloud Bursting vs Cloud Scaling 7 min read Automated Scaling Listener in Cloud Computing 4 min read Difference Between Multi-Cloud and Hybrid Cloud 5 min read Difference Between Cloud Computing and Fog Computing 3 min read Overview of Multi Cloud 10 min read Service level agreements in Cloud computing 6 min read Overview of Everything as a Service (XaaS) 5 min read Resource Pooling Architecture in Cloud Computing 3 min read Load balancing in Cloud Computing 6 min read Overview of Desktop as a Service (DaaS) 5 min read IoT and Cloud Computing 6 min read Container as a Service (CaaS) 5 min read Principles of Cloud Computing 3 min read Resiliency in Cloud Computing 4 min read Serverless Computing 3 min read Like