feat(decdk) prototype for declarative CDK (decdk)#1618
Merged
Conversation
added 16 commits
January 26, 2019 20:30
turn decdk to a self-contained transformer which depends on all cdk libraries to simplify usage. theoretically we would have been able to split decdk and the dependency closure, but keeping them monolithic right now is easier to work with and takes care of some issues related to resolving modules in client packages (e.g. we need to resolve transitive modules and that's annoying).
- support enums - inherit interface members - use normal jsii FQNs for package names to keep things simple
if an interface has non-serializable properties but they are optional, we can technically allow users to use the construct with the default value. this dramatically expands the set of available deconstructs.
- performs type checking - allows deserializing enums - in the future will allow deserializing IBucket-like objects -
if we see an Fn::GetAtt, we replace it with a synth-time lazy value which will resolve according to what is referenced. if GetAtt references a high level construct, the resolved value will be the value returned by a named property. otherwise, we just retain the original Fn::GetAtt. at the moment, this is only supported for strings.
a new "resourceForPath(path)" method will get or create all the resources leading to a certain path in the api model. this can be used to easily define "routes" in the api and reuse the nodes in the tree. includes a refactor of how the root resource and normal resources share implementation (through an abstract base class, dah!)
the ApiEventSource allows easily adding APIGW routes to a Lambda. upon first call, a new REST API resource will be created, and then routes will be added to it for each ApiEventSource associated with the lambda.
initial implementation for a declarative surface for serverless functions, which is based on the SAM spec. the main difference between this API and the Lambda API is that this allows defining event sources declaratively when the function is initialized.
- ECS/Fargate: one resource that synthesizes 38 - Queue with KMS encryption with auto-created key - SAM API events + dynamo table + GetAtt in Outputs - SAM with Queues: shows GetAtt for both resource and construct A script "./synth" instead of cdk.json
If a construct has a property that references another
construct, users can now use {Ref} to reference a construct
of that type that was defined in the same template.
The schema will only allow { Ref: ID }
Classes that have static methods/properties that return
a type that matches the class type can be considered "enum-like"
because they can be used like so:
lambda.Runtime.NodeJS10
or:
lambda.Code.asset('path')
We are now deconstructing these to either a string (for the property
case) or an object where the key is the method name and the value
is an map of parameter names to values.
This is actually something we can probably embed in the jsii spec,
as it is a common pattern.
To enable deconstruction, turn ContainerImage to an enum-like class. This means that the "image" property needs to accept a concrete class instead of an interface. Seems like this won't hurt the model in any way.
in order to be able to deconstruct this, we expect ctors to have only three arguments: scope,id,props. split ContainerDefinitionOptions from ContainerDefinitionProps to allow reusing them in `addContainer`. also, move the logic of "linking" the container to the task definition into the ContainerDefinition class, so that "addContainer" is pure sugar and doesn't have special behavior. otherwise, we won't be able to use it declaratively.
- ecs - lambda - pipelines(!)
sam-goodwin
reviewed
Jan 29, 2019
|
|
||
| export interface Event { | ||
| type: EventType; | ||
| properties: DynamoEvent | SnsEvent | SqsEvent | ApiEvent; |
Contributor
There was a problem hiding this comment.
You're missing Kinesis.
| this.handler.addEventSource(new events.ApiEventSource(apiEvent.method, apiEvent.path)); | ||
| break; | ||
|
|
||
| default: |
tools/decdk/README.md
Outdated
|
|
||
| ## Open issues | ||
|
|
||
| - [ ] Do we need a "ref" attribute for allowing referencing resources? |
Contributor
There was a problem hiding this comment.
What's the story for L1 and raw CFN?
added 4 commits
January 30, 2019 14:21
A partition key is a required property of DynamoDB. BREAKING CHANGE: partitionKey is now required when defining a DynamoDB table. the method "addPartitionKey" has been removed.
add SimpleTable, which is a DynamoDB table with a default partition key of "ID: string". SimpleTable extends from Table and support all features.
If a property accepts an interface type, deCDK will identify all types
that implement it and will formulate a JSON schema that allows users
to instantiate these types.
For example lambda IEventSource:
"events": [
{
"DynamoEventSource": {
"table": { "Ref": "Table" },
"props": { "startingPosition": "TrimHorizon" }
}
},
{ "ApiEventSource": { "method": "GET", "path": "/hello" } },
{ "ApiEventSource": { "method": "POST", "path": "/hello" } },
{ "SnsEventSource": { "topic": { "Ref": "MyTopic" } } }
]
sam-goodwin
reviewed
Feb 5, 2019
| * an `Fn::GetAtt`. | ||
| */ | ||
| function deconstructGetAtt(stack: cdk.Stack, id: string, attribute: string) { | ||
| new cdk.Token(() => { |
added 8 commits
February 11, 2019 22:19
and fix "api" event source
eladb
pushed a commit
that referenced
this pull request
Feb 12, 2019
Minor changes to the ECS APIs so that they can be instantiated via a declarative template (see deCDK #1618). Merge `IContainerImage` and the base `ContainerImage` into an abstract class so it's now an "enum-like" class with static methods. It also improves discoverability for all other users and more aligned with how other constructs expose union types (e.g. `lambda.Code`). Normalize the ctor of `ContainerDefinition` to "scope, id, props" so that it can be instantiated as a deCDK resource.
4 tasks
eladb
pushed a commit
that referenced
this pull request
Feb 13, 2019
Minor changes to the ECS APIs so that they can be instantiated via a declarative template (see deCDK #1618). Merge `IContainerImage` and the base `ContainerImage` into an abstract class so it's now an "enum-like" class with static methods. It also improves discoverability for all other users and more aligned with how other constructs expose union types (e.g. `lambda.Code`). Normalize the ctor of `ContainerDefinition` to "scope, id, props" so that it can be instantiated as a deCDK resource.
added 5 commits
February 13, 2019 11:46
rix0rrr
commented
Feb 13, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A prototype for a tool that reads CloudFormation-like JSON/YAML templates which can contain both normal CloudFormation resources (AWS::S3::Bucket) and also reference AWS CDK resources (@aws-cdk/aws-s3.Bucket).
See README for details.
Pull Request Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.