Cloudian is fully compatible with S3, so it's convenient to use the AWS SDK! Last time tried to display the created bucket in various patterns with Python (boto3).
This time, I would like to create a new object storage bucket in Python (boto3).
Create a new bucket in Object Storage/Cloudian.
In the following example, only the bucket name (Bucket = ‘pythonbucket1’) to be created is set in the argument of create_bucket (), and all attribute values are created using the default.
test1.py
import boto3
client = boto3.client(
's3',
endpoint_url='https://xxx.yyy.com'
)
#Create a new bucket
client.create_bucket(Bucket='pythonbucket1')
{'ResponseMetadata': {'RequestId': '9dad4484-0e30-1dbc-a754-06bdfcde1d5e',
'HostId': '3d5c05376530a2eb49e3e90576f83c5b',
'HTTPStatusCode': 200,
'HTTPHeaders': {'date': 'Mon, 14 Dec 2020 01:51:29 GMT',
'x-amz-request-id': '9dad4484-0e30-1dbc-a754-06bdfcde1d5e',
'location': 'http://pythonbucket1.s3-region1.admin-tech.tokyo',
'x-amz-id-2': '3d5c05376530a2eb49e3e90576f83c5b',
'content-length': '0',
'server': 'CloudianS3'},
'RetryAttempts': 0},
'Location': 'http://pythonbucket1.s3-region1.admin-tech.tokyo'}
Since list_buckets () returns a great deal of information, we will narrow down the output and display it in the following examples.
In the following example, the bucket is created by setting the bucket name (Bucket ='pythonbucket1') to be created and the ACL (ACL ='public-read') of that bucket in the argument of create_bucket ().
test2.py
import boto3
client = boto3.client(
's3',
endpoint_url='https://xxx.yyy.com'
)
#Create a new bucket
client.create_bucket(
ACL='public-read',
Bucket='pythonbucket1'
)
{'ResponseMetadata': {'RequestId': '9dad4487-0e30-1dbc-a754-06bdfcde1d5e',
'HostId': '3d5c05376530a2eb49e3e90576f83c5b',
'HTTPStatusCode': 200,
'HTTPHeaders': {'date': 'Mon, 14 Dec 2020 01:51:30 GMT',
'x-amz-request-id': '9dad4487-0e30-1dbc-a754-06bdfcde1d5e',
'location': 'http://pythonbucket1.s3-region1.admin-tech.tokyo',
'x-amz-id-2': '3d5c05376530a2eb49e3e90576f83c5b',
'content-length': '0',
'server': 'CloudianS3'},
'RetryAttempts': 0},
'Location': 'http://pythonbucket1.s3-region1.admin-tech.tokyo'}
In the following example, the bucket name (Bucket ='bucket2') and bucket ACL (ACL ='private') to be created in the argument of create_bucket (), and the location constraint (CreateBucketConfiguration = {'LocationConstraint':'region1'). }) Is set to create a bucket.
test3.py
import boto3
client = boto3.client(
's3',
endpoint_url='https://xxx.yyy.com'
)
#Create a new bucket
client.create_bucket(
ACL='private',
Bucket='pythonbucket1',
CreateBucketConfiguration={
'LocationConstraint': 'region1'
}
)
{'ResponseMetadata': {'RequestId': '9dad448a-0e30-1dbc-a754-06bdfcde1d5e',
'HostId': '3d5c05376530a2eb49e3e90576f83c5b',
'HTTPStatusCode': 200,
'HTTPHeaders': {'date': 'Mon, 14 Dec 2020 01:51:31 GMT',
'x-amz-request-id': '9dad448a-0e30-1dbc-a754-06bdfcde1d5e',
'location': 'http://pythonbucket1.s3-region1.admin-tech.tokyo',
'x-amz-id-2': '3d5c05376530a2eb49e3e90576f83c5b',
'content-length': '0',
'server': 'CloudianS3'},
'RetryAttempts': 0},
'Location': 'http://pythonbucket1.s3-region1.admin-tech.tokyo'}
The CreationDate returned by the datetime type is formatted and output for easy viewing using strftime () included in the Python standard module.
I tried to create a new bucket with various patterns in Python (boto3).
Next time, I would like to operate object storage/Cloudian in various ways with Python.
Recommended Posts