-
Notifications
You must be signed in to change notification settings - Fork 222
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
feat(concepts): "scope" instead of "parent" #1
Conversation
Shift the conceptual mental model to talk about the scope hierarchy instead of a tree with parents and children. See aws/aws-cdk#1444
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, i love the decision to call the parents scopes.
|
||
The low-level resources are automatically generated from the [AWS CloudFormation Resource Types Reference](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html). Low-level constructs are named `CfnXyz` (where "Xyz" represents the name of the resource) and provide direct, one-to-one access to how a resource is synthesized in the CloudFormation template produced by your CDK app. Using low-level resources require explicit configuration of all resource properties, IAM policies and requires deep understanding of the details. | ||
|
||
High-level resources are hand-written by AWS and offer a rich, intent-based API for using AWS services. They offer the same functionality as the low-level resources but encode much of the details, boilerplate and glue-logic required in order to use AWS. High-level resources offer convenient defaults and additional knowledge about the inner workings of the AWS resources they represent\. In general, you will be able to express your intent without worrying about the details too much, and the correct resources and configuration will automatically be defined for you\. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought-provoking example such as granting access/enabling encryption etc. ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me noodle this.
}); | ||
``` | ||
|
||
Avoid specifying physical names\. Instead, let AWS CloudFormation generate names for you\. Use attributes, such as `bucket.bucketName`, to discover the generated names\. | ||
In general it's recommended to avoid specifying physical names\. Instead, let AWS CloudFormation generate names for you\. Use attributes, such as `bucket.bucketName`, to discover the generated names\. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we mention how discovered names maps to cloud formation functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe in the CloudFormation topic?
``` | ||
|
||
In almost all cases, you should pass the keyword `this` for the `parent` argument, because you will generally initialize new constructs in the context of the parent construct\. Any descriptive string will do for the `name` argument, and an in\-line object for the set of properties\. | ||
The first argument to every construct is always the scope in which it is created, and will almost always be simply `this` because most constructs will be defined within the current scope. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps clarify that 'current scope' means within the constructor or method of another construct. Might be confusing to new-comers without sample code. Or expand the example to include the outer scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to explain scope. It's a fundamental programming concept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of agree with @sam-goodwin - maybe we could say something like "...defined within the current scope, which is normally the initializer (constructor) or a method of some construct defined in your app".
Something like that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a fundamental programming concept, but it is ambiguous in this context since we are just now introducing them to the CDK's implementation of scopes. For example, will a novice understand that the scope is also a construct?
|
||
``` | ||
Scopes enable constructs to be composed together to form higher-level abstractions by enabling the framework to group them together into logical units, allocate globally unique identifiers and allow them to consult __context information__ such as the region in which it is going to be deployed into, which AZs are available for my account, etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduce the scope hierarchy? You haven't described how they are grouped together, only implied it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added an earlier explanation.
}); | ||
``` | ||
|
||
**Note** | ||
Associating the construct to its parent as part of initialization is necessary because the construct occasionally needs contextual information from its parent, such as to which the region the stack is deployed\. | ||
The `construct.node` property can be used to interact with the construct's node representation: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're introducing the concept of a 'node' before explicitly describing the tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reworded the intro.
|
||
The AWS CDK includes two different levels of constructs: | ||
This composition of constructs also means you can easily create sharable constructs, and make changes to any construct and have those changes available to consumers as shared class libraries\. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you should briefly define the 'scope hierarchy'/'construct tree' here to explain the encapsulation and composability. Having the High/Low level explanation in between seems out of order to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some more explanatory text.
|
||
## Construct Names<a name="constructs_EVER"></a> | ||
Every construct in a CDK app must have an **id** unique within the scope in which the construct is defined. IDs are used to find constructs in the construct hierarchy, and to allocate logical IDs so that AWS CloudFormation can keep track of the generated resources\. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First mention of the hierarchy is here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scope and hierarchy are fundamental concepts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They still need to be explained in the context of the CDK in my mind.
I've incorporated the comments into the docs and will refresh shortly. |
As soon as a release with 1444 is published, I'll update the docs. |
@Doug-AWS can you please make sure you also incorporate @sam-goodwin's comments? |
Yes, I've got most of them incorporated. |
Shift the conceptual mental model to talk about the scope
hierarchy instead of a tree with parents and children.
See aws/aws-cdk#1444
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.