https://pulumi.com logo
#general
Title
# general
e

early-analyst-76866

11/15/2022, 7:51 AM
Hey team, I am new to Pulumi and I am stuck on one usecase where I want to show the user the actual property value in my stack trace. My current stack output is this:
Copy code
Current stack outputs (1):
                              OUTPUT  VALUE
                                               vid     vpc-0515230c3d5f949a8
I am able to reference my stack using
stack_ref = pulumi.StackReference("PulumiPlay-dev")
but I am not sure how to print the value of vid now. I have tried using the
get_output
method but it is not returning anything.
e

echoing-dinner-19531

11/15/2022, 11:35 AM
stack_ref.get_output("vid") should return it
s

stocky-restaurant-98004

11/15/2022, 1:00 PM
Or if you want the value from the command line:
pulumi stack output vid
e

early-analyst-76866

11/15/2022, 3:06 PM
I followed the automation API tutorial: https://github.com/pulumi/automation-api-examples/blob/main/python/inline_program/main.py In a different python file I am running this code:
Copy code
import pulumi

stack_ref = pulumi.StackReference("inline_s3_project/dev")
obj = {"website_url": stack_ref.get_output("website_url").apply(
    lambda s3_url: "https://" + s3_url
)}
print(obj)
The output that I am getting still shows me the object and not the value:
Copy code
{'website_url': <pulumi.output.Output object at 0x109f9f2b0>}
e

echoing-dinner-19531

11/15/2022, 3:07 PM
Oh that's because
apply
always returns an Output object. If you did that print inside the apply function it would print the string value
Also
Output.format("https://{0}", stack_ref.get_output("website_url"))
is probably a nicer way to do this rather than an apply
e

early-analyst-76866

11/15/2022, 3:10 PM
I tried running this too. This is just giving me an empty response.
Copy code
import pulumi

stack_ref = pulumi.StackReference("inline_s3_project/dev")
obj = {"website_url": stack_ref.get_output("website_url").apply(
    lambda s3_url: f"https:// + {print(s3_url)}"
)}
Print is not working for me.
e

echoing-dinner-19531

11/15/2022, 5:37 PM
That's not how print is meant to work:
Copy code
stack_ref = pulumi.StackReference("inline_s3_project/dev")
obj = {"website_url": stack_ref.get_output("website_url").apply(
    lambda s3_url: f"https:// + {s3_url}"
)}
obj["website_url"].apply(lambda s: print(s))
I'd expect that to print out the url