I'm using boto3 to download files from s3, and i'm trying to unpack the values from bucket.objects.all() iteration:
bucket = boto3.Session(profile_name='default').resource('s3').Bucket(bucket_name)
for (bucket_name, key) in zip(bucket.objects.all()):
print(bucket_name, key)
But this is returning the following error:
ValueError: not enough values to unpack (expected 2, got 1)
What I'm doing wrongly?
You can try this part instead of zip(bucket.objects.all()):
map(lambda x: (x.bucket_name, x.key), bucket.objects.all())
the function map allows to apply the function lambda (first parameter) to each members of the second parameter
bucket.objects.all() which returns a list of ObjectSummary.
map returns a list you can loop
The lambda returns a tuple of 2 values so that you can unpack them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With