Fix Python – Mocking boto3 S3 client method Python

I’m trying to mock a singluar method from the boto3 s3 client object to throw an exception. But I need all other methods for this class to work as normal.
This is so I can test a singular Exception test when and error occurs performing a upload_part_copy
1st Attempt
import boto3
from mock import patch

with patch(‘botocore.client.S3.upload_part_co….

Fix Python – Boto3 to download all files from a S3 Bucket

I’m using boto3 to get files from s3 bucket. I need a similar functionality like aws s3 sync
My current code is
import boto3
for key in list:
s3.download_file(‘my_bucket_name’, key[‘Key’], key[‘Key’])

This is working fine, as long as the bucket ….

Fix Python – Retrieving subfolders names in S3 bucket from boto3

Using boto3, I can access my AWS S3 bucket:
s3 = boto3.resource(‘s3’)
bucket = s3.Bucket(‘my-bucket-name’)

Now, the bucket contains folder first-level, which itself contains several sub-folders named with a timestamp, for instance 1456753904534.
I need to know the name of these sub-folders for another job I’m doing and I wonder whether I could h….

Fix Python – How to save S3 object to a file using boto3

I’m trying to do a “hello world” with new boto3 client for AWS.
The use-case I have is fairly simple: get object from S3 and save it to the file.
In boto 2.X I would do it like this:
import boto
key = boto.connect_s3().get_bucket(‘foo’).get_key(‘foo’)

In boto 3 . I can’t find a clean way to do the same thi….

Fix Python – How to specify credentials when connecting to boto3 S3?

On boto I used to specify my credentials when connecting to S3 in such a way:
import boto
from boto.s3.connection import Key, S3Connection
S3 = S3Connection( settings.AWS_SERVER_PUBLIC_KEY, settings.AWS_SERVER_SECRET_KEY )

I could then use S3 to perform my operations (in my case deleting an object from a bucket).
With boto3 all the examples I fou….

Fix Python – Save Dataframe to csv directly to s3 Python

I have a pandas DataFrame that I want to upload to a new CSV file. The problem is that I don’t want to save the file locally before transferring it to s3. Is there any method like to_csv for writing the dataframe to s3 directly? I am using boto3.
Here is what I have so far:
import boto3
s3 = boto3.client(‘s3′, aws_access_key_id=’key’, aws_secret_a….

Fix Python – How to choose an AWS profile when using boto3 to connect to CloudFront

I am using the Boto 3 python library, and want to connect to AWS CloudFront.
I need to specify the correct AWS Profile (AWS Credentials), but looking at the official documentation, I see no way to specify it.
I am initializing the client using the code:
client = boto3.client(‘cloudfront’)
However, this results in it using the default profile to co….

Fix Python – boto3 client NoRegionError: You must specify a region error only sometimes

I have a boto3 client :

But it happens on new machines, They open and close dynamically.
if endpoint is None:
if region_name is None:
# Raise a more specific error message that will give
# better guidance to the user what needs to happen.
raise NoRegionError()

Why is this happe….