This message was deleted.
# general
s
This message was deleted.
c
that's the (rough) desired end state - but I'm not sure how to get there from the callbackfactory:
Thanks in advance!
g
callbackFactory
creates a callback function, it is used to build the global state of the function during cold starts like initializing clients that will reuse resources. The type system should have an error there for returning true instead of a
Callback<E, R>
If you don't need to initialize anything use
callback
instead of
callbackFactory
c
@green-school-95910 got it. so callbackfactory is for cases where I want to run logic at "pulumi up" time to initialize something prior to the deployment? What would be the approach to get the output I pasted in the first screenshot?
g
No it is logic run on the lambda, but not for every request, just to initialize global values, like instantiating a grpc client or a s3 client:
Copy code
new aws.lambda.CallbackFunction("foo", {
  callbackFactory: () => {
    const s3 = new AWS.S3();
    return async (event) => {
      // ... save event details on S3 ...
    };
  },
);
The value that you want would depend on where is that
accessMeFromTheCallback
value.
1
c
trying that out. Thanks Luiz
g
If it is an
Output
from somewhere else you don't need the factory:
Copy code
// Defined from other resources somewhere
const accessMeFromTheCallback: Output<string>

new aws.lambda.CallbackFunction("foo", {
  callback: async (event) => {
    // .get() is required here to extract the string
    // from the `Output` instance
    console.log(accessMeFromTheCallback.get());
  };
);
If you just need it to be global on the function you use the same as I did for
s3
on the example above of
callbackFactory
c
I think that worked! 👍 thanks Luiz! Related question - a bunch of lambda SaaS services work by wrapping the handler function (like Rookout):
Would it be possible to use the same mechanism for doing that? or is there a different approach for wrapping the handler?
g
You can do that on the factory
Copy code
new aws.lambda.CallbackFunction("foo", {
  callbackFactory: () => rookout.wrap(async (event) => {
    // ...
  });
);
c
perfect! Thanks a whole bunch @green-school-95910! Much appreciated!
g
You are welcome! 🙂
c
just popping in to say hi, @chilly-magazine-6129. we worked together at MSFT. 🙂
partypus 8bit 1
c
👋 hey Alex! 😄 small world. ❤️