Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I use variables as part of my bucket path with s3 boto client?

At the moment Im trying to upload to a bucket with the variables as the path name using the boto s3 client and here are the variables I have defined:

var1 = A
var2 = B
var3 = C

I am uploading to the bucket like this:

client.upload_file('myfile.jpeg', 'bucket', 'directory/{var1}/{var2}/{var3}')

However the lambda function I am using is actually creating the variables as part of the file path. How can I actually use the values of var1,var2 and var3? My expected output is this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

directory/A/B/C

and my current output is this:

directory/{var1}/{var2}/{var3}

Thanks

>Solution :

Use Python’s f strings:

client.upload_file('myfile.jpeg', 'bucket', f'directory/{var1}/{var2}/{var3}')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading