Get the list in the S3 bucket with Python and search with a specific Key. Output the Key name, last update date, and count number to a file.

I needed it because I needed it

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

PUBLIC_S3_BUCKET_NAME_TEST = 'Bucket name'

def access_count():
    count = 0
    with open('file.txt', 'w') as f:
        #Get a list of buckets
        S3 = boto3.resource('s3')
        S3BUCKET = S3.Bucket(PUBLIC_S3_BUCKET_NAME_TEST)

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

        print('total=' + str(count), file=f)

Recommended Posts

Get the list in the S3 bucket with Python and search with a specific Key. Output the Key name, last update date, and count number to a file.
Output the key list included in S3 Bucket to a file
Recursively get the Excel list in a specific folder with python and write it to Excel.
I want to get the file name, line number, and function name in Python 3.4
Get the value of a specific key in a list from the dictionary type in the list with Python
Get the number of specific elements in a python list
How to get the last (last) value in a list in Python
Spit out a list of file name, last modified date and character code in python3
Get the value of a specific key up to the specified index in the dictionary list in Python
How to get the date and time difference in seconds with python
How to count the number of elements in Django and output to a template
How to get a list of files in the same directory with python
How to identify the element with the smallest number of characters in a Python list?
How to count the number of occurrences of each element in the list in Python with weight
Change the standard output destination to a file in Python
It is surprisingly troublesome to get a list of the last login date and time of Workspaces
[Python scraping] Output the URL and title of the site containing a specific keyword to a text file
How to get a specific column name and index name in pandas DataFrame
The file name was bad in Python and I was addicted to import
[Cloudian # 5] Try to list the objects stored in the bucket with Python (boto3)
How to stop a program in python until a specific date and time
[Python] Get the files in a folder with Python
Use libsixel to output Sixel in Python and output a Matplotlib graph to the terminal.
[Python] Concatenate a List containing numbers and write it to an output file.
A command to specify a file with a specific name in a directory with find and mv, cp, or gzip it (linux)
Get the update date of the Python memo file.
Run the output code with tkinter, saying "A, pretending to be B" in python
[Python] Change the text color and background color of a specific keyword in print output
[Mac] A super-easy way to execute system commands in Python and output the results
It is easy to execute SQL with Python and output the result in Excel
How to get the variable name itself in python
Get the file name in a folder using glob
How to get the number of digits in Python
Output a binary dump in binary and revert to a binary file
[Python] How to output the list values in order
When I try to update the data on DynamoDB with Python (boto3), I get "ExpressionAttributeNames contains invalid key: Syntax error; key: <key name>"
When writing to a csv file with python, a story that I made a mistake and did not meet the delivery date
I tried to get the number of days of the month holidays (Saturdays, Sundays, and holidays) with python
Parse the Researchmap API in Python and automatically create a Word file for the achievement list
I also tried to imitate the function monad and State monad with a generator in Python
Get the MIME type in Python and determine the file format
Sort and output the elements in the list as elements and multiples in Python.
Developed a library to get Kindle collection list in Python
[Homology] Count the number of holes in data with Python
How to get a list of built-in exceptions in python
Get the current date and time in Python, considering the time difference
Google search for the last line of the file in Python
Try to decipher the garbled attachment file name with Python
Get date and time in specified format
Get your current location and user agent in Python
Get stock prices and create candlestick charts in Python
Recursively search for files and directories in Python and output
Get a participant's username and screen name in Slack
Change static file storage directories and URLs in Flask
How to get RGB and HSV histograms in OpenCV
Recursively get the Excel list in a specific folder with python and write it to Excel.
Process the gzip file UNLOADed with Redshift with Python of Lambda, gzip it again and upload it to S3
Determine the date and time format in Python and convert to Unixtime
Count the number of Thai and Arabic characters well in Python
Try to get a list of breaking news threads in Python.
Search the file name including the specified word and extension in the directory
[Python] How to get the first and last days of the month
Output the contents of ~ .xlsx in the folder to HTML with Python
[Python] Get the update date of a news article from HTML
Read a file in Python with a relative path from the program
[Python] How to get a value with a key other than value with Enum
Python vba to create a date string for creating a file name
Get the formula in an excel file as a string in Python