- Newest
- Most votes
- Most comments
Creating Level 2 (L2) constructs in the AWS Cloud Development Kit (CDK) involves several key steps and best practices:
-
Extend the Construct class: L2 constructs should directly extend the Construct class from the CDK library.
-
Abstract L1 constructs: L2 constructs are abstractions of L1 constructs, providing a higher-level, more intuitive API. They should call their corresponding L1 constructs in their constructors upon instantiation.
-
Provide default properties: Implement common property settings as defaults, often conditional in nature, to simplify the configuration process for users.
-
Use TypeScript types, interfaces, and enums: Leverage TypeScript's type system to define the structure of data and configurations, making the construct more robust and easier to use.
-
Implement helper methods: Create methods that allow for easier manipulation of resource configurations after instantiation.
-
Consider static methods: Use static methods to provide easier ways to reference imported resources.
-
Create helper classes: For more complex use cases, develop helper classes that offer the full capabilities of a TypeScript class.
-
Implement best practices: Ensure your L2 construct implements AWS best practices and common patterns for the specific service or resource it represents.
-
Document thoroughly: Provide clear and comprehensive documentation for your construct, including usage examples and explanations of any default behaviors.
-
Test extensively: Write unit tests and integration tests to ensure your construct behaves as expected in various scenarios.
-
Consider reusability: Design your L2 construct to be as reusable as possible, allowing for easy customization without sacrificing simplicity.
-
Follow CDK conventions: Adhere to the naming conventions and coding standards used in the official CDK library for consistency.
When developing L2 constructs, it's beneficial to study existing L2 constructs in the CDK library to understand common patterns and best practices. Additionally, consider contributing your L2 constructs back to the CDK community if they solve a common use case.
Remember that L2 constructs should provide a balance between abstraction and flexibility, making it easier for users to work with AWS resources while still allowing for customization when needed.
Sources
Developing CDK Constructs | AWS re:Post
Layer 2 constructs - AWS Prescriptive Guidance
Best practices - AWS Prescriptive Guidance
You can follow below guidance for creating L2 Contructs: https://docs.aws.amazon.com/prescriptive-guidance/latest/aws-cdk-layers/layer-2.html
The contributing document may be helpful to keep in mind when developing. https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md It is a good idea to see what other developers are doing in terms of development. https://constructs.dev/search?q=&cdk=aws-cdk&cdkver=2&sort=downloadsDesc&offset=0&tags=community
Relevant content
asked 3 years ago
asked 4 years ago
asked 2 years ago
