0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PythonでS3バケット内の一覧を取得し、特定のKeyで検索 Key名と最終更新日、カウント数をファイルに出力

Posted at

所用で必要になったので

# -*- coding: utf-8 -*-
import boto3

PUBLIC_S3_BUCKET_NAME_TEST = 'バケット名'

def access_count():
    count = 0
    with open('file.txt', 'w') as f:
        # バケットの一覧取得
        S3 = boto3.resource('s3')
        S3BUCKET = S3.Bucket(PUBLIC_S3_BUCKET_NAME_TEST)

        for obj in S3BUCKET.objects.all():
            if '検索名' in obj.key:
                count += 1
                print(count, obj.key, obj.last_modified, file=f)

        print('total=' + str(count), file=f)
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?