Search code examples
pythonamazon-web-servicesaws-lambdaboto3

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:

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}')