https://pulumi.com logo
#python
Title
# python
h

hallowed-fireman-90476

01/04/2024, 2:58 AM
#python Is anyone facing issue in converting output to string using str() or f"", i am getting error using both the option in latest pulumi version
g

green-stone-37839

01/04/2024, 6:47 PM
can you show some example code?
h

hallowed-fireman-90476

01/05/2024, 2:41 PM
@green-stone-37839 thanks for the response.
bucket = root_bucket.bucket.apply(lambda bk: f"{bk}")
isn't the
bucket
variable should be string but still it refer as output type
g

green-alligator-4238

01/06/2024, 2:27 PM
Works ok for me: o_bucket_name = my_bucket.bucket.apply(lambda bk: f”MyBucket:{bk}“) v3.100.0 on Mac(Sonoma 14.2.1)
h

hallowed-fireman-90476

01/07/2024, 12:55 AM
Thanks @green-alligator-4238 for the reply. am using same mac and pulumi version as well. Are you able to print using print statement or log.info the
o_bucket_name
g

green-alligator-4238

01/07/2024, 6:16 PM
@hallowed-fireman-90476 - I can get basic text in log.info, but no luck yet with simply logging something as simple as a created bucket name…. I’m/We’re clearly missing something, but this is a real disappointment - why should this be so complicated…? Needing lambda for accessing computed data is bad enough, but why is a simple ‘print’ so difficult…?
Also very disappointed in the quality of error messages - very poor - no idea where the problem could be coming from…
Found it: o_bucket_name = my_bucket.bucket.apply(lambda bk: f”MyBucket:{bk}“) o_bucket_name.apply(lambda v: log.info(f”Log:{v}“)) • I the above ‘v’ can be used as / is a normal string value. • Output will be in the Diagnostics section Still getting my head around Pulumi concepts etc, but it looks like the bucket name comes from the provider/API, not from state, hence the need for the lambda call to go get the info (but I hope I’m wrong). Also, at a very high level, it would appear you ‘drive Pulumi with Python’ rather than write Python code that includes Pulumi, but again, hope I’m wrong - early days yet… In the above, o_bucket_name is an output object that needs to go get the bucket name via lambda, even though you’ve already done a lambda on the name - not the anticipated behaviour of a string of “MyBucket:${bucket_name}“. Good luck!
print() works the same way as log.info, but as an output at the end, as per normal Python.
h

hallowed-fireman-90476

01/08/2024, 10:53 AM
@green-alligator-4238 i am also beginner to Pulumi, the combination of Output and Lambda in Python throws me off.