samedi 29 mai 2021

How to design CDK project?

recently started working on a CDK project, Wanted to have views of y'all on how to structure it. Ill lay out what I have thought.

Will be have 2 separate packages.

  1. ApplicationCommonsPackage
  2. SpecificApplicationCDKPackage(Can be many such packages), These will depend on the ApplicationCommonsPackage

The ApplicationCommonsPackage will hold all the common logic for all our applications(till now have thought of Configs, Common constructs, factory method for creating constructs)

The latter(SpecificApplicationCDKPackage) will hold configs for the constructs and will use the factory in ApplicationCommonsPackage for creating stuff.

What do you think of using factory pattern in ApplicationCommonsPackage? One issue I am facing is that I cannot expose a common interface with a generic method(or am not able to?) for the factory. The reason being every construct requires props which are of very specific type, I cannot generalise them to any or such sort as by that will lose the niceness of typescript. So am having functions like createLambda(scope: Stack, id: string, props: LambdaProps): Function in my factory. I am not liking this structure a lot, I would have loved generic function which took the Function as an input and would have determined the type of props from it. Something like create<T>(scope: Stack, id: string, props: <U derived from T => some methodology to get this?>): T so that when I actually use this in SpecificApplicationCDKPackage like so - this.factory.create<Function>(this, 'SampleLambda', {}) I get all compile time errors for the props parameter({})

Aucun commentaire:

Enregistrer un commentaire