I thought that the result of the call to apply is another Output object?
m
miniature-musician-31262
02/04/2023, 12:59 AM
Yes — the result of the call to
apply
is an
Output[T]
, but within the callback that’s passed to apply, you can work with the raw `T`:
Copy code
bucket = s3.Bucket('my-bucket')
def compare(a, b):
if a == b:
print("match")
else:
print("no match")
bucket.id.apply(lambda id: compare(id, "some-string"))
👍 1
miniature-musician-31262
02/04/2023, 1:20 AM
You can also do something like this, which can be a little nicer to work with:
Copy code
bucket = s3.Bucket('my-bucket')
some_known_value = "foo"
# Capture the result as an Output[bool].
is_match = bucket.id.apply(lambda id: id == some_known_value)
# Use its apply() to work with the result.
is_match.apply(lambda m: print("Match!" if m else "No match."))
No matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.