Skip to content

Commit 1efc835

Browse files
authored
Merge pull request HarshCasper#216 from sameersrivastava13/master
solved HarshCasper#193 added : python script to create s3 bucket
2 parents e1d4299 + 86a25f5 commit 1efc835

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

Aws/Readme.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# How do I create an S3 Bucket?
2+
3+
Before you can upload data to Amazon S3, you must create a bucket in one of the AWS Regions to store your data.
4+
After you create a bucket, you can upload an unlimited number of data objects to the bucket.
5+
6+
The AWS account that creates the bucket owns it. By default, you can create up to 100 buckets in each of your AWS accounts.
7+
If you need additional buckets, you can increase your account bucket quota to a maximum of 1,000 buckets by submitting a service quota increase.
8+
For information about how to increase your bucket quota, see AWS Service Quotas in the AWS General Reference.
9+
10+
## To create a bucket using python
11+
12+
Step 1 : Install boto3 library
13+
14+
A low-level client representing Amazon Simple Storage Service (S3):
15+
16+
Step 2 :
17+
18+
The following operations are related to CreateBucket :
19+
20+
PutObject
21+
DeleteBucket
22+
23+
See also: [Documentation](https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html)
24+
25+
Examples
26+
27+
The following example creates a bucket. The request specifies an AWS region where to create the bucket.
28+
29+
`import boto3`
30+
31+
`client = boto3.client('s3')`
32+
33+
`response = client.create_bucket(
34+
Bucket='examplebucket',
35+
CreateBucketConfiguration={
36+
'LocationConstraint': 'eu-west-1',
37+
}
38+
)`
39+
40+

Aws/createS3Bucket.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import boto3
2+
import os
3+
import datetime
4+
5+
6+
class s3Bucket:
7+
def __init__(self, bucketName: str) -> None:
8+
self.bucketName = bucketName
9+
10+
def createS3Bucket(self):
11+
try:
12+
client = boto3.client("s3")
13+
client.create_bucket(
14+
ACL="private",
15+
Bucket=self.bucketName,
16+
CreateBucketConfiguration={"LocationConstraint": "us-west-1"},
17+
)
18+
except Exception as err:
19+
print(err)
20+
else:
21+
print("S3 bucket creation Successful!")
22+
23+
24+
if __name__ == "__main__":
25+
date = datetime.datetime.now()
26+
current_time = "{}{}{}".format(date.month, date.day, date.year)
27+
bucketName = "yourName{}".format(current_time)
28+
obj = s3Bucket(bucketName)
29+
obj.createS3Bucket()

0 commit comments

Comments
 (0)