boto3 - S3 Flashcards

1
Q

🤝 クライアントの作成

A

client = boto3.client(‘s3’,
region_name=’ap-northeast-1’,
aws_access_key_id = ‘ご自身のkey_id’,
aws_secret_access_key = ‘ご自身のaccess_key’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

🧺 S3へバケットの作成

A

client.create_bucket(Bucket=’任意のバケット名’,
CreateBucketConfiguration={‘LocationConstraint’: ‘ap-northeast-1’})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

❌ S3上の不要バケット削除方法

A

client.delete_bucket(Bucket=’任意のバケット名’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

⬆️ ローカルデータをS3上の指定したバケットにアップする方法

A

response = client.upload_file(file_name, bucket, object_name, ExtraArgs=args)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

⬆️ S3上のバケット内に複数のデータをアップしたい場合

A

import glob
files = glob.glob(‘data/*’)

for file in files:
response = client.upload_file(file_name, bucket, object_name, ExtraArgs=args)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

⬇️ S3上のバケットからローカルへデータをダウンロードする方法

A

s3 = boto3.resource(‘s3’)
list(s3.buckets.all())
client.list_buckets()
bucket = s3.Bucket(‘バケット名’)
files = list(bucket.objects.all())

for file in files:
client.download_file(‘バケット名’, file.key, file.key)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly