Introducere în AWS Boto în Python
Maksim Pecherskiy
Data Engineer
df = pd.read_csv('https://gid-staging.potholes.csv')

Descărcați fișierul
s3.download_file(
Filename='potholes_local.csv',
Bucket='gid-staging',
Key='2019/potholes_private.csv')
Citiți de pe disc
pd.read_csv('./potholes_local.csv')
Utilizați '.get_object()'
obj = s3.get_object(Bucket='gid-requests', Key='2019/potholes.csv')
print(obj)

Obțineți obiectul
obj = s3.get_object(
Bucket='gid-requests',
Key='2019/potholes.csv')
Citiți StreamingBody în Pandas
pd.read_csv(obj['Body'])
Exemplu
https://?AWSAccessKeyId=12345&Signature=rBmnrwutb6VkJ9hE8Uub%2BBYA9mY%3D&Expires=1557624801
Încărcați un fișier
s3.upload_file(
Filename='./potholes.csv',
Key='potholes.csv',
Bucket='gid-requests')
Generați URL pre-semnat
share_url = s3.generate_presigned_url(
ClientMethod='get_object',
ExpiresIn=3600,
Params={'Bucket': 'gid-requests','Key': 'potholes.csv'}
)
Deschideți în Pandas
pd.read_csv(share_url)
# Create list to hold our DataFrames df_list = []# Request the list of csv's from S3 with prefix; Get contents response = s3.list_objects( Bucket='gid-requests', Prefix='2019/')# Get response contents request_files = response['Contents']
# Iterate over each object for file in request_files: obj = s3.get_object(Bucket='gid-requests', Key=file['Key'])# Read it as DataFrame obj_df = pd.read_csv(obj['Body'])# Append DataFrame to list df_list.append(obj_df)
# Concatenate all the DataFrames in the list df = pd.concat(df_list)# Preview the DataFrame df.head()

Descărcați, apoi deschideți
s3.download_file()
Deschideți direct
s3.get_object()
Generați URL pre-semnat
s3.generate_presigned_url()
Generați folosind .format()
'https://{bucket}.{key}'
Generați folosind .get_presigned_url()
'https://?AWSAccessKeyId=12345&Signature=rBmnrwutb6VkJ9hE8Uub%2BBYA9mY%3D&Expires=1557624801'
Introducere în AWS Boto în Python