1
1

More than 1 year has passed since last update.

【AWS】boto3を使ってS3でフォルダを作成する方法

Posted at

boto3を使ってS3でフォルダを作成する方法です。(備忘録として)

import boto3 #boto3インポート

dir = 'hoge/fuga/'  #ディレクトリパス
bucket_name='your_buket_name' #S3のバケット名
s3 = boto3.client('s3')
result = s3.list_objects(Bucket=bucket_name, Prefix=dir) #ディレクトリを変数に

if not "Contents" in result: # ディレクトリがない場合はContents というキーが存在しない。これを使えば存在判定ができる。
  s3.put_object(Bucket=bucket_name, Key=dir)  #ディレクトリ作成 

 参考にした記事

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1