CDK construct level1 Vs level2


Hi team,

I want to automate the creation of our Cognito user pool with CDK,

I would like to know what is the recommended CDK level to use for codifying: CDK level1 using cfnxxx or CDK level2?

Since I read it's better to avoid using level1 (cfnResources) whenever possible.

It's easier for me to use CDK level 1 (low level of abstraction)

Since I use AWS CLI to get the JSON spec of my resource (via AWS CLI get/describe command),

aws cognito-idp describe-user-pool --user-pool-id cognito_id > myUserPoolSpec.json --profile test

I can then do 1x1 property mappings from the generated JSON to the cfnResource construct.

(since I have everything I need in the generated JSON via AWS CLI.)

If level 2 CDK is recommended instead of level 1, is there a way/tool that can help me find the equivalent of attributes from cfnResource/my JSON file with CDK level 2 construct props?

2 Answers

You can use L1 constructs instead of L2 and sometimes it is an easier approach. There are resources that don't have a corresponding L2 construct and in such cases, it is easier to use L1 constructs. Reviewing the construct best practices, there is nothing specifically for L1 vs. L2. Often, L2 constructs make it easier to deploy multiple resources within a single construct.

Speaking of getting attributes, you can take a look at the package source code or run cdk synth to generate a CloudFormation template to identify resources/parameters.

answered 3 months ago

The higher Construct level you go, the more abstraction you will see ie. more parameters are pre-defined in the underlying Construct Resources so it is easier for you to create a resource.

No particular best practice that I know of, but you can see more L1 Construct options rather than L2.

Here you go for reference:

profile picture
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions