Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(guidelines): guidance on which constructs are included in the CDK #13218

Merged
merged 10 commits into from
Mar 2, 2021
123 changes: 123 additions & 0 deletions DESIGN_GUIDELINES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
# AWS Construct Library Design Guidelines

- [AWS Construct Library Design Guidelines](#aws-construct-library-design-guidelines)
- [API Design](#api-design)
- [What's Included](#what-s-included)
njlynch marked this conversation as resolved.
Show resolved Hide resolved
- [Modules](#modules)
- [Construct Class](#construct-class)
- [Construct Interface](#construct-interface)
- [Owned vs. Unowned Constructs](#owned-vs-unowned-constructs)
- [Abstract Base](#abstract-base)
- [Props](#props)
- [Types](#types)
- [Defaults](#defaults)
- [Flat](#flat)
- [Concise](#concise)
- [Naming](#naming)
- [Property Documentation](#property-documentation)
- [Enums](#enums)
- [Unions](#unions)
- [Attributes](#attributes)
- [Configuration](#configuration)
- [Prefer Additions](#prefer-additions)
- [Dropped Mutations](#dropped-mutations)
- [Factories](#factories)
- [Imports](#imports)
- [“from” Methods](#-from--methods)
- [From-attributes](#from-attributes)
- [Roles](#roles)
- [Resource Policies](#resource-policies)
- [VPC](#vpc)
- [Grants](#grants)
- [Metrics](#metrics)
- [Events](#events)
- [Connections](#connections)
- [Integrations](#integrations)
- [State](#state)
- [Physical Names - TODO](#physical-names---todo)
- [Tags](#tags)
- [Secrets](#secrets)
- [Project Structure](#project-structure)
- [Code Organization](#code-organization)
- [Implementation](#implementation)
- [General Principles](#general-principles)
- [Construct IDs](#construct-ids)
- [Errors](#errors)
- [Input Validation](#input-validation)
- [Avoid Errors If Possible](#avoid-errors-if-possible)
- [Never Catch Exceptions](#never-catch-exceptions)
- [Post Validation](#post-validation)
- [Attached Errors/Warnings](#attached-errors-warnings)
- [Tokens](#tokens)
- [Documentation](#documentation)
- [Inline Documentation](#inline-documentation)
- [Readme](#readme)
- [Testing](#testing)
- [Unit tests](#unit-tests)
- [Integration tests](#integration-tests)
- [Versioning](#versioning)
- [Naming & Style](#naming---style)
- [Naming Conventions](#naming-conventions)
- [Coding Style](#coding-style)

The AWS Construct Library is a rich class library of CDK constructs which
represent all resources offered by the AWS Cloud and higher-level constructs for
achieving common tasks.
Expand Down Expand Up @@ -56,6 +116,69 @@ allows the library to be used from all supported programming languages. jsii
poses restrictions on language features that cannot be idiomatically represented
in target languages.

## What's Included

The AWS CDK includes the AWS Construct Library, which contains constructs
representing AWS resources.
njlynch marked this conversation as resolved.
Show resolved Hide resolved

The AWS Construct Library has three different levels of constructs, beginning
njlynch marked this conversation as resolved.
Show resolved Hide resolved
with low-level constructs, which we call _CFN Resources_ (or L1, short for
"level 1") or Cfn (short for CloudFormation) resources. These constructs
njlynch marked this conversation as resolved.
Show resolved Hide resolved
eladb marked this conversation as resolved.
Show resolved Hide resolved
directly represent all resources available in AWS CloudFormation. CFN Resources
are periodically generated from the AWS CloudFormation Resource
Specification. They are named **Cfn**_Xyz_, where _Xyz_ is name of the
resource. For example, CfnBucket represents the AWS::S3::Bucket AWS
CloudFormation resource. When you use Cfn resources, you must explicitly
configure all resource properties, which requires a complete understanding of
the details of the underlying AWS CloudFormation resource model.

The next level of constructs, L2, also represent AWS resources, but with a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth mentioning that L2 resources interact with other CloudFormation resources only via other L2s, never via L1s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely worth capturing somewhere in this doc, but I'm not sure if this is the right section. Maybe under the Props section, or Implementation, depending on if we're talking about the public surface area or implementation details?

higher-level, intent-based API. They provide similar functionality, but provide
the defaults, boilerplate, and glue logic you'd be writing yourself with a CFN
Resource construct. AWS constructs offer convenient defaults and reduce the need
njlynch marked this conversation as resolved.
Show resolved Hide resolved
to know all the details about the AWS resources they represent, while providing
convenience methods that make it simpler to work with the resource. For example,
the s3.Bucket class represents an Amazon S3 bucket with additional properties
njlynch marked this conversation as resolved.
Show resolved Hide resolved
and methods, such as bucket.addLifeCycleRule(), which adds a lifecycle rule to
njlynch marked this conversation as resolved.
Show resolved Hide resolved
the bucket.

Examples of behaviors that an L2 commonly include:

- Modeling of the underlying L1 properties
njlynch marked this conversation as resolved.
Show resolved Hide resolved
- Methods for adding related resources (e.g., adding an event notification to
an S3 bucket).
njlynch marked this conversation as resolved.
Show resolved Hide resolved
- Modeling of permissions and resource policies
- Modeling of metrics

In addition to the above, some higher-order L2s may introduce more complex and
njlynch marked this conversation as resolved.
Show resolved Hide resolved
helpful functionality, either part of the original L2 itself, or as part of a
separate construct. The most common form of these L2s are integration constructs
that model interactions between different services (e.g., SNS publishing to SQS,
CodePipeline actions that trigger Lambda functions).

The third level of abstraction present within the CDK are what we designate as
njlynch marked this conversation as resolved.
Show resolved Hide resolved
"L2.5s": a step above the L2s in terms of abstraction, but not quite at the
level of complete patterns or applications. These constructs still largely
focus on a single logical resource -- in constrast to "patterns" which combine
multiple resources -- but are customized for a specific common usage scenario of
an L2.
njlynch marked this conversation as resolved.
Show resolved Hide resolved

L2.5 constructs will be considered for inclusion in the CDK if they...

- cover a common usage scenario that can be used by a significant portion of
the community;
- provide significant ease of use over the base L2 (via usage-specific defaults
or convenience methods);
njlynch marked this conversation as resolved.
Show resolved Hide resolved
- simplify or enable another L2 within the CDK

The CDK also currently includes some even higher-level constructs, which we call
patterns. These constructs often involve multiple kinds of resources and are
njlynch marked this conversation as resolved.
Show resolved Hide resolved
designed to help you complete common tasks in AWS or represent entire
applications. These patterns are typically difficult to design to be
one-size-fits-all and are best suited to be published as separate libraries,
rather than included directly in the CDK. The patterns that currently exist in the
CDK will be removed in the next CDK major version (CDKv2).

## API Design

### Modules
Expand Down