Skip to content

Commit

Permalink
feat: no more generated attribute types in CFN layer (L1) (#1489)
Browse files Browse the repository at this point in the history
Now that we can represent attributes as native strings and string lists,
this covers the majority of resource attributes in CloudFormation.

This change:

* String attributes are represented as `string` (like before).
* String list attribute are now represented as `string[]`.
* Any other attribute types are represented as `cdk.Token`.

Attributes that are represented as Tokens as of this change:

* amazonmq has a bunch of `Integer` attributes (will be solved by #1455)
* iot1click has a bunch of `Boolean` attributes
* cloudformation has a JSON attribute
* That's all.

A few improvements to cfn2ts:

* Auto-detect cfn2ts scope from package.json so it is more self-contained
  and doesn't rely on cdk-build-tools to run.
* Added a "cfn2ts" npm script to all modules so it is now possible
  to regenerate all L1 via "lerna run cfn2ts".
* Removed the premature optimization for avoiding code regeneration
  (it saved about 0.5ms).

Fixes #1406

BREAKING CHANGE: any `CfnXxx` resource attributes that represented a list of strings are now typed as `string[]`s (via #1144). Attributes that represent strings, are still typed as `string` (#712) and all other attribute types are represented as `cdk.Token`.
  • Loading branch information
Elad Ben-Israel committed Jan 8, 2019
1 parent 17eddd1 commit 4d6d5ca
Show file tree
Hide file tree
Showing 94 changed files with 297 additions and 184 deletions.
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,22 @@ Here are a few useful commands:
evaluate only the rule specified [awslint README](./tools/awslint/README.md)
for details on include/exclude rule patterns.

### cfn2ts

This tool is used to generate our low-level CloudFormation resources
(L1/`CfnFoo`). It is executed as part of the build step of all modules in the
AWS Construct Library.

The tool consults the `cdk-build.cloudformation` key in `package.json` to
determine which CloudFormation namespace this library represents (e.g.
`AWS::EC2` is the namespace for `aws-ec2`). We maintain strict 1:1 relationship
between those.

Each module also has an npm script called `cfn2ts`:

* `npm run cfn2ts`: generates L1 for a specific module
* `lerna run cfn2ts`: generates L1 for the entire repo

## Development Workflows

### Full clean build
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/alexa-ask/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"pkglint": "pkglint -f",
"test": "cdk-test",
"watch": "cdk-watch",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "Alexa::ASK"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-amazonmq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"pkglint": "pkglint -f",
"test": "cdk-test",
"watch": "cdk-watch",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::AmazonMQ"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-apigateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::ApiGateway"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-applicationautoscaling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::ApplicationAutoScaling"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-appstream/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"pkglint": "pkglint -f",
"test": "cdk-test",
"watch": "cdk-watch",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::AppStream"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-appsync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::AppSync"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-athena/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"keywords": [
"aws",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup

// use delayed evaluation
const machineImage = props.machineImage.getImage(this);
const userDataToken = new cdk.Token(() => cdk.Fn.base64((machineImage.os.createUserData(this.userDataLines))));
const userDataToken = new cdk.Token(() => cdk.Fn.base64((machineImage.os.createUserData(this.userDataLines)))).toString();
const securityGroupsToken = new cdk.Token(() => this.securityGroups.map(sg => sg.securityGroupId));

const launchConfig = new CfnLaunchConfiguration(this, 'LaunchConfig', {
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-autoscaling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::AutoScaling"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-autoscalingplans/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::AutoScalingPlans"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-batch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::Batch"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-budgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::Budgets"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-certificatemanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::CertificateManager"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-cloud9/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::Cloud9"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-cloudformation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::CloudFormation"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-cloudfront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::CloudFront"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-cloudtrail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"test": "cdk-test",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::CloudTrail"
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export class Dashboard extends Construct {
// This is a bug in CloudFormation, but we don't want CDK users to have a bad
// experience. We'll generate a name here if you did not supply one.
// See: https://github.com/awslabs/aws-cdk/issues/213
const dashboardName = (props && props.dashboardName) || new Token(() => this.generateDashboardName());
const dashboardName = (props && props.dashboardName) || new Token(() => this.generateDashboardName()).toString();

this.dashboard = new CfnDashboard(this, 'Resource', {
dashboardName,
dashboardBody: new Token(() => {
const column = new Column(...this.rows);
column.position(0, 0);
return CloudFormationJSON.stringify({ widgets: column.toJson() });
})
}).toString()
});
}

Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::CloudWatch"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-codebuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::CodeBuild"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-codecommit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::CodeCommit"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-codedeploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::CodeDeploy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class GitHubSourceAction extends actions.SourceAction {
new CfnWebhook(this, 'WebhookResource', {
authentication: 'GITHUB_HMAC',
authenticationConfiguration: {
secretToken: props.oauthToken,
secretToken: props.oauthToken.toString(),
},
filters: [
{
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-codepipeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::CodePipeline"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-cognito/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::Cognito"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::Config"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-datapipeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::DataPipeline"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-dax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::DAX"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-directoryservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::DirectoryService"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-dlm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"pkglint": "pkglint -f",
"test": "cdk-test",
"watch": "cdk-watch",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::DLM"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-dms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::DMS"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-dynamodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::DynamoDB"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-ec2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::EC2"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-ecr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::ECR"
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class TaskDefinition extends cdk.Construct {
const taskDef = new CfnTaskDefinition(this, 'Resource', {
containerDefinitions: new cdk.Token(() => this.containers.map(x => x.renderContainerDefinition())),
volumes: new cdk.Token(() => this.volumes),
executionRoleArn: new cdk.Token(() => this.executionRole && this.executionRole.roleArn),
executionRoleArn: new cdk.Token(() => this.executionRole && this.executionRole.roleArn).toString(),
family: this.family,
taskRoleArn: this.taskRole.roleArn,
requiresCompatibilities: [
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-ecs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::ECS"
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-efs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"integ": "cdk-integ",
"pkglint": "pkglint -f",
"package": "cdk-package",
"awslint": "cdk-awslint"
"awslint": "cdk-awslint",
"cfn2ts": "cfn2ts"
},
"cdk-build": {
"cloudformation": "AWS::EFS"
Expand Down
Loading

0 comments on commit 4d6d5ca

Please sign in to comment.