https://pulumi.com logo
#typescript
Title
# typescript
m

mammoth-art-6111

03/08/2022, 5:41 PM
anyone else run into issues re: function serialization and using a pulumi ComponentResource? i refactored a lambda/API gateway setup to be composed in a ComponentResource and now when the function is serialized, it omits all of the member functions required to do the job
the only function that was serialized was the one passed directly to
CallbackFunction
but all functions it referenced were not serialized
^ that's basically the constructor that assigns a member function to the Callback Function
i figured out a workaround; you've gotta create a service object with the functions you want to use in the callback, instantiate it, and then pass it to
aws.lambda.CallbackFunction
as an arrow function w/ the service object instance caught in the closure
idk if that would be easy for others to figure out, took me a while
m

miniature-musician-31262

03/08/2022, 10:09 PM
That’s interesting — I would’ve found this surprising, too. Glad you found a way through it. I wonder if there’s something about
webhookCallback
specifically that got in the way somehow, because this, at least for me, seems to work:
and with a
lambda.CallbackFunction
, I also see
someFunc
serialized into the Lambda:
… so I wonder what happened there. 🤔
m

mammoth-art-6111

03/08/2022, 10:11 PM
yeah. also curious. it was using
this.someFunc
, it was another member function of the instance
m

miniature-musician-31262

03/08/2022, 10:18 PM
aha, so you saw something like this?
m

mammoth-art-6111

03/08/2022, 10:54 PM
yes, exactly
m

miniature-musician-31262

03/08/2022, 11:59 PM
nice, ok. seems like this is either a bug or something that needs to be documented — will report back!
m

mammoth-art-6111

03/09/2022, 3:20 PM
lmk!
m

miniature-musician-31262

03/10/2022, 12:24 AM
Ended up filing this, as I think it may be a bug — or at least need better documentation! https://github.com/pulumi/pulumi/issues/9168
m

mammoth-art-6111

03/10/2022, 3:56 PM
yeah, i wonder if it's possible to serialize in that situation at all. i believe the "instance" or object created from the object prototype exists at the time that the function assignment occurs, but i'm not sure it's simply a matter of capturing everything in the closure and i'm not sure how you would make the serializer aware a particular closure was a "constructor" (since it's syntax sugar/ it's really just another function)
3 Views