Hi,
i have been trying out the new provider framework for custom resources and am very pleased with it. However currently, for every custom resource a new provider lambda function is generated in the stack.
I want to call a custom resource around 50 times. This results in my custom resource function deployed once (singleton) and 50 provider functions being deployed, 1 for each custom resource call.
Looking at the code only 3 things change in each of these provider functions.
It would be great if the provider function could be implemented as a singleton, passing these parameters in the payload instead. This would cut down on the lambda functions created drastically.
This is a :rocket: Feature Request
We can definitely add some sugar to make it easier to implement a provider as a singleton, but it is fairly easy to implement yourself. Here's the pattern:
class MyProvider extends Construct {
public static getOrCreate(scope: Construct) {
const stack = Stack.of(scope);
const id = 'unique-id-of-provider-so-it-doesnt-conflict-with-others';
return stack.node.tryGetChild(id) as MyProvider || new MyProvider(stack, id);
}
public readonly provider: cr.Provider;
constructor(scope: Construct, id: string) {
super(scope, id);
this.provider = new cr.Provider(this, 'MyProvider', { ... });
}
}
Let me know if this is helpful
Thank you, yes it was. I was able to implement a singleton provider with this.
Most helpful comment
We can definitely add some sugar to make it easier to implement a provider as a singleton, but it is fairly easy to implement yourself. Here's the pattern:
Let me know if this is helpful