broad-translator-40115
06/09/2022, 6:37 AMlet cachedValue = '';
exports.handler = async () => {
if (cachedValue) {
return cachedValue;
}
const newValue = await getSomeNewValue();
cachedValue = newValue;
return newValue;
}
But this doesn't seem to work with Pulumi 😬
We have a callback defined like:
let cachedValue = '';
export const handler: aws.lambda.Callback<Event, unknown> = async (event, context, callback) => {
// ...
}
And we're using it as an AppSync resolver:
const cbFunction = new aws.lambda.CallbackFunction('cb', {
runtime: 'nodejs14.x',
callback: handler,
}
const dataSource = new aws.appsync.DataSource('some-data-source', {
...
lambdaConfig: {
functionArn: cbFunction.arn,
},
});
But we cannot make this mechanism work.
The cachedValue
is refreshed on each invocation.
I know Pulumi does function serialization, which is a concept I'm still trying to wrap my head around.
Any quick tips on how to access the execution environment in a lambda like this?
(Also, yes, I'm aware it's not a reliable way to do caching, lambdas are supposed to be stateless, data is not safe, etc etc). We do have a use case for this, though. Any help would be appreciated 😁callbackFactory
field instead of callback
to scope whatever should be cached.
Thanks.