-
-
Save AnilPothula/d1f635028d3a62a8a653971da47a97f6 to your computer and use it in GitHub Desktop.
AWS Simple-Storage-Service (S3) objects list and export to csv.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import boto3 | |
| import pandas | |
| AWS_ACCESS_KEY_ID = 'YOUR_AWS_ACCESS_KEY_ID' | |
| AWS_SECRET_ACCESS_KEY = 'YOUR_AWS_SECRET_ACCESS_KEY' | |
| # connect to s3 | |
| s3 = boto3.client( | |
| 's3', | |
| aws_access_key_id=AWS_ACCESS_KEY_ID, | |
| aws_secret_access_key=AWS_SECRET_ACCESS_KEY, | |
| ) | |
| listOfObject = [] | |
| resp = s3.list_objects_v2(Bucket='your-bucket-name') | |
| for obj in resp['Contents']: | |
| listOfObject.append(obj['Key']) | |
| print(obj['Key']) | |
| #print(listOfObject) | |
| #listDataFrame = pandas.DataFrame(listOfObject) | |
| #listDataFrame.to_csv('list.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment