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

[BREAKING] Move @aws-cdk/resources classes into L2 packages #264

Merged
merged 6 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ rm -rf $BUILD_INDICATOR
export PATH=node_modules/.bin:$PATH

echo "============================================================================================="
echo "boostrapping..."
lerna bootstrap --reject-cycles
echo "building..."
lerna exec --stream "npm run build"
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this build symlinks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, lerna bootstrap will have done that at the install.sh step. I can duplicate the bootstrap command, though if you feel it's better... It's incredibly cheap to run.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should automatically run ./install.sh is node_modules doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already do (L4-6 in build.sh).


echo "============================================================================================="
echo "testing..."
lerna run test --stream
lerna run --stream test

touch $BUILD_INDICATOR

Expand Down
97 changes: 97 additions & 0 deletions create_missing_libraries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Use hyphens in file names create-missing-libraries.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

set -euo pipefail

VERSION=$(node -e 'console.log(require("./lerna.json").version);')

for S in $(node -e 'console.log(require("./packages/@aws-cdk/cloudformation-resource-spec").namespaces.join("\n"));'); do
P=$(tr 'A-Z' 'a-z' <<< "${S/AWS::/@aws-cdk/}")
PB=$(basename ${P})
if [ ! -d packages/${P} ]; then
echo "⏳ Creating package ${P} for scope ${S}..."
mkdir -p packages/${P}/test
mkdir -p packages/${P}/lib
echo '*.js' >> packages/${P}/.gitignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please use HEREDOCs instead? Will be wayyyy more readable...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I find the fact that HEREDOCs require you to break indentation very disturbing, BTW).

Copy link
Contributor

Choose a reason for hiding this comment

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

I know. Me too, but they are still way better than this 😜

echo '*.js.map' >> packages/${P}/.gitignore
echo '*.d.ts' >> packages/${P}/.gitignore
echo 'tsconfig.json' >> packages/${P}/.gitignore
echo 'tslint.json' >> packages/${P}/.gitignore
echo 'node_modules' >> packages/${P}/.gitignore
echo 'cfn' >> packages/${P}/.gitignore
echo 'dist' >> packages/${P}/.gitignore

echo "# Don't include original .ts files when doing \`npm pack\`" >> packages/${P}/.npmignore
echo '*.ts' >> packages/${P}/.npmignore
echo '!*.d.ts' >> packages/${P}/.npmignore
echo 'coverage' >> packages/${P}/.npmignore
echo '.nyc_output' >> packages/${P}/.npmignore
echo '*.tgz' >> packages/${P}/.npmignore

echo '{' >> packages/${P}/package.json
echo " \"name\": \"${P}\"," >> packages/${P}/package.json
echo " \"version\": \"${VERSION}\"," >> packages/${P}/package.json
echo " \"description\": \"The CDK Construct Library for ${S}\"," >> packages/${P}/package.json
echo " \"main\": \"lib/index.js\"," >> packages/${P}/package.json
echo " \"types\": \"lib/index.d.ts\"," >> packages/${P}/package.json
echo " \"jsii\": {" >> packages/${P}/package.json
echo " \"outdir\": \"dist\"," >> packages/${P}/package.json
echo " \"bundledDependencies\": []," >> packages/${P}/package.json
echo " \"names\": {" >> packages/${P}/package.json
echo " \"java\": \"com.amazonaws.cdk.${PB}\"," >> packages/${P}/package.json
echo " \"dotnet\": \"${S/AWS::/Aws.Cdk.}\"" >> packages/${P}/package.json
echo " }" >> packages/${P}/package.json
echo " }," >> packages/${P}/package.json
echo " \"repository\": {" >> packages/${P}/package.json
echo " \"type\": \"git\"," >> packages/${P}/package.json
echo " \"url\": \"git://github.com/awslabs/aws-cdk\"" >> packages/${P}/package.json
echo " }," >> packages/${P}/package.json
echo " \"scripts\": {" >> packages/${P}/package.json
echo " \"build\": \"cfn2ts --scope=${S} && jsii && tslint -p . && pkglint\"," >> packages/${P}/package.json
echo " \"watch\": \"jsii -w\"," >> packages/${P}/package.json
echo " \"lint\": \"jsii && tslint -p . --force\"," >> packages/${P}/package.json
echo " \"test\": \"nodeunit test/test.*.js && cdk-integ-assert\"," >> packages/${P}/package.json
echo " \"integ\": \"cdk-integ\"," >> packages/${P}/package.json
echo " \"pkglint\": \"pkglint -f\"" >> packages/${P}/package.json
echo " }," >> packages/${P}/package.json
echo " \"keywords\": [" >> packages/${P}/package.json
echo " \"aws\"," >> packages/${P}/package.json
echo " \"cdk\"," >> packages/${P}/package.json
echo " \"constructs\"," >> packages/${P}/package.json
echo " \"${PB}\"" >> packages/${P}/package.json
echo " ]," >> packages/${P}/package.json
echo " \"author\": {" >> packages/${P}/package.json
echo " \"name\": \"Amazon Web Services\"," >> packages/${P}/package.json
echo " \"url\": \"https://aws.amazon.com\"" >> packages/${P}/package.json
echo " }," >> packages/${P}/package.json
echo " \"license\": \"LicenseRef-LICENSE\"," >> packages/${P}/package.json
echo " \"devDependencies\": {" >> packages/${P}/package.json
echo " \"@aws-cdk/assert\": \"^${VERSION}\"," >> packages/${P}/package.json
echo " \"cfn2ts\": \"^${VERSION}\"," >> packages/${P}/package.json
echo " \"pkglint\": \"^${VERSION}\"" >> packages/${P}/package.json
echo " }," >> packages/${P}/package.json
echo " \"dependencies\": {" >> packages/${P}/package.json
echo " \"@aws-cdk/core\": \"^${VERSION}\"," >> packages/${P}/package.json
echo " \"@aws-cdk/runtime\": \"^${VERSION}\"" >> packages/${P}/package.json
echo " }" >> packages/${P}/package.json
echo '}' >> packages/${P}/package.json

echo "// The L1 Library for ${S}:" >> packages/${P}/lib/index.ts
echo "export * from '../cfn/${PB}';" >> packages/${P}/lib/index.ts

echo "import { Test, testCase } from 'nodeunit';" >> packages/${P}/test/test.${PB}.ts
echo "" >> packages/${P}/test/test.${PB}.ts
echo "exports = testCase({" >> packages/${P}/test/test.${PB}.ts
echo " notTested(test: Test) {" >> packages/${P}/test/test.${PB}.ts
echo " test.ok(true, 'No tests are specified for this package.');" >> packages/${P}/test/test.${PB}.ts
echo " test.done();" >> packages/${P}/test/test.${PB}.ts
echo " }" >> packages/${P}/test/test.${PB}.ts
echo "});" >> packages/${P}/test/test.${PB}.ts

echo "⌛️ Bootstrapping & building ${P}"
lerna bootstrap --scope=${P}
lerna run build --scope=${P}

git add packages/${P}

echo "✅ Have fun with your new package ${P}"
fi
done
4 changes: 2 additions & 2 deletions examples/cdk-examples-java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This an example of a CDK program written in Java.

## Building

To build this app, run `npm run prepare`. This will:
To build this app, run `npm run build`. This will:

1. Generate `project/pom.xml` with correct references to jsii and CDK
dependencies.
Expand Down Expand Up @@ -48,4 +48,4 @@ $ cdk diff
```

If you make modifications, make sure to rebuild the app, either by callign `mvn
package` from `./project` or `npm run prepare` from the root.
package` from `./project` or `npm run build` from the root.
2 changes: 1 addition & 1 deletion examples/cdk-examples-java/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"ignore": true
},
"scripts": {
"prepare": "/bin/bash generate.sh && cd project && mvn package",
"build": "/bin/bash generate.sh && cd project && mvn package",
"cdk": "cdk",
"test": "echo ok"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/cdk-examples-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ file at the root.
To synthesize or deploy and example app, you will first need to build it:

```shell
npm run prepare
npm run build
```

Or you can watch:
Expand Down
19 changes: 11 additions & 8 deletions examples/cdk-examples-typescript/advanced-usage/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { StackResource } from '@aws-cdk/cloudformation';
import * as cdk from '@aws-cdk/core';
import { PolicyStatement, ServicePrincipal } from '@aws-cdk/core';
import { WindowsImage, WindowsVersion } from '@aws-cdk/ec2';
import { InstanceResource, WindowsImage, WindowsVersion } from '@aws-cdk/ec2';
import { } from '@aws-cdk/ec2';
import { Role } from '@aws-cdk/iam';
import { cloudformation, ec2, sns, sqs } from '@aws-cdk/resources';
import { Bucket } from '@aws-cdk/s3';
import { SubscriptionResource, TopicResource } from '@aws-cdk/sns';
import { QueueResource } from '@aws-cdk/sqs';

/**
* This stack demonstrates the use of the IAM policy library shipped with the CDK.
Expand Down Expand Up @@ -54,7 +57,7 @@ class EnvContextExample extends cdk.Stack {
// render construct name based on it's availablity zone
const constructName = `InstanceFor${az.replace(/-/g, '').toUpperCase()}`;

new ec2.InstanceResource(this, constructName, {
new InstanceResource(this, constructName, {
imageId: ami.imageId,
availabilityZone: az,
});
Expand Down Expand Up @@ -89,7 +92,7 @@ class IncludeExample extends cdk.Stack {

// add constructs (and resources) programmatically
new EnvContextExample(parent, 'Example');
new sqs.QueueResource(this, 'CDKQueue', {});
new QueueResource(this, 'CDKQueue', {});
}
}

Expand All @@ -103,7 +106,7 @@ class NestedStackExample extends cdk.Stack {
// add an "AWS::CloudFormation::Stack" resource which uses the MongoDB quickstart
// https://aws.amazon.com/quickstart/architecture/mongodb/
// only non-default values are provided here.
new cloudformation.StackResource(this, 'NestedStack', {
new StackResource(this, 'NestedStack', {
templateUrl: 'https://s3.amazonaws.com/quickstart-reference/mongodb/latest/templates/mongodb-master.template',
parameters: {
KeyPairName: 'my-key-pair',
Expand All @@ -124,10 +127,10 @@ class ResourceReferencesExample extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);

const topic = new sns.TopicResource(this, 'Topic', {});
const queue = new sqs.QueueResource(this, 'Queue', {});
const topic = new TopicResource(this, 'Topic', {});
const queue = new QueueResource(this, 'Queue', {});

new sns.SubscriptionResource(this, 'Subscription', {
new SubscriptionResource(this, 'Subscription', {
topicArn: topic.ref, // resolves to { Ref: <topic-id> }
protocol: 'sqs',
endpoint: queue.queueArn // resolves to { "Fn::GetAtt": [ <queue-id>, "Arn" ] }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { UserPoolClientResource, UserPoolResource } from '@aws-cdk/cognito';
import { Construct } from '@aws-cdk/core';
import { cognito } from '@aws-cdk/resources';

export class CognitoChatRoomPool extends Construct {
constructor(parent: Construct, name: string) {
super(parent, name);

// Create chat room user pool
const chatPool = new cognito.UserPoolResource(this, 'UserPool', {
const chatPool = new UserPoolResource(this, 'UserPool', {
adminCreateUserConfig: {
allowAdminCreateUserOnly: false
},
Expand All @@ -26,7 +26,7 @@ export class CognitoChatRoomPool extends Construct {
});

// Now for the client
new cognito.UserPoolClientResource(this, 'UserPoolClient', {
new UserPoolClientResource(this, 'UserPoolClient', {
clientName: 'Chat-Room',
explicitAuthFlows: [ 'ADMIN_NO_SRP_AUTH' ],
refreshTokenValidity: 30,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Construct } from '@aws-cdk/core';
import * as dynamodb from '@aws-cdk/dynamodb';
import { KeyAttributeType, Table } from '@aws-cdk/dynamodb';

export class DynamoPostsTable extends Construct {
constructor(parent: Construct, name: string) {
super(parent, name);

const table = new dynamodb.Table(this, 'Table', {
const table = new Table(this, 'Table', {
readCapacity: 5, writeCapacity: 5
});

table.addPartitionKey('Alias', dynamodb.KeyAttributeType.String);
table.addSortKey('Timestamp', dynamodb.KeyAttributeType.String);
table.addPartitionKey('Alias', KeyAttributeType.String);
table.addSortKey('Timestamp', KeyAttributeType.String);
}
}
4 changes: 2 additions & 2 deletions examples/cdk-examples-typescript/cloudformation/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { App, Stack } from '@aws-cdk/core';
import { sqs } from '@aws-cdk/resources';
import { QueueResource } from '@aws-cdk/sqs';

class CloudFormationExample extends Stack {
constructor(parent: App) {
super(parent);

new sqs.QueueResource(this, 'MyQueue', {
new QueueResource(this, 'MyQueue', {
visibilityTimeout: 300
});
}
Expand Down
6 changes: 4 additions & 2 deletions examples/cdk-examples-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A bunch of CDK examples",
"private": true,
"scripts": {
"prepare": "tsc && tslint -p . && pkglint",
"build": "tsc && tslint -p . && pkglint",
"watch": "tsc -w",
"lint": "tsc && tslint -p . --force",
"test": "echo ok",
Expand All @@ -21,14 +21,16 @@
"pkglint": "^0.7.3-beta"
},
"dependencies": {
"@aws-cdk/cloudformation": "^0.7.3-beta",
"@aws-cdk/cognito": "^0.7.3-beta",
"@aws-cdk/core": "^0.7.3-beta",
"@aws-cdk/dynamodb": "^0.7.3-beta",
"@aws-cdk/ec2": "^0.7.3-beta",
"@aws-cdk/iam": "^0.7.3-beta",
"@aws-cdk/lambda": "^0.7.3-beta",
"@aws-cdk/neptune": "^0.7.3-beta",
"@aws-cdk/rds": "^0.7.3-beta",
"@aws-cdk/resources": "^0.7.3-beta",
"@aws-cdk/runtime": "^0.7.3-beta",
"@aws-cdk/rtv": "^0.7.3-beta",
"@aws-cdk/s3": "^0.7.3-beta",
"@aws-cdk/sns": "^0.7.3-beta",
Expand Down
13 changes: 6 additions & 7 deletions examples/cdk-examples-typescript/sns-sqs/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { App, PolicyDocument, PolicyStatement, Stack } from "@aws-cdk/core";
import { sns, sqs } from '@aws-cdk/resources';
import { Topic } from '@aws-cdk/sns';
import { Queue } from '@aws-cdk/sqs';
import { SubscriptionResource, Topic, TopicResource } from '@aws-cdk/sns';
import { Queue, QueuePolicyResource, QueueResource } from '@aws-cdk/sqs';

class ACL extends Stack {
constructor(parent: App, name: string) {
Expand All @@ -20,10 +19,10 @@ class CFN extends Stack {
constructor(parent: App, name: string) {
super(parent, name);

const topic = new sns.TopicResource(this, 'MyTopic');
const queue = new sqs.QueueResource(this, 'MyQueue');
const topic = new TopicResource(this, 'MyTopic');
const queue = new QueueResource(this, 'MyQueue');

new sns.SubscriptionResource(this, 'TopicToQueue', {
new SubscriptionResource(this, 'TopicToQueue', {
topicArn: topic.ref, // ref == arn for topics
endpoint: queue.queueName,
protocol: 'sqs'
Expand All @@ -36,7 +35,7 @@ class CFN extends Stack {
.addServicePrincipal('sns.amazonaws.com')
.setCondition('ArnEquals', { 'aws:SourceArn': topic.ref }));

new sqs.QueuePolicyResource(this, 'MyQueuePolicy', {
new QueuePolicyResource(this, 'MyQueuePolicy', {
policyDocument,
queues: [ queue.ref ]
});
Expand Down
7 changes: 7 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ set -euo pipefail
echo "============================================================================================="
echo "installing repo-global dependencies..."
npm i --no-package-lock --global-style

# Now that we have lerna available...
export PATH=node_modules/.bin:$PATH

echo "============================================================================================="
echo "bootstrapping..."
lerna bootstrap --reject-cycles
2 changes: 2 additions & 0 deletions packages/@aws-cdk/acm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ tsconfig.json
tslint.json
*.js.map
*.d.ts
node_modules
cfn
dist
2 changes: 1 addition & 1 deletion packages/@aws-cdk/acm/lib/certificate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Construct } from '@aws-cdk/core';
import { certificatemanager } from '@aws-cdk/resources';
import * as certificatemanager from '../cfn/certificatemanager';
import { CertificateArn, CertificateRef } from './certificate-ref';
import { apexDomain } from './util';

Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/acm/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export * from './certificate';
export * from './certificate-ref';

// The L1 library for AWS::CertificateManager:
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use the terminology AWS::CertificateManager CloudFormation resources

Copy link
Contributor Author

Choose a reason for hiding this comment

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

export * from '../cfn/certificatemanager';
6 changes: 3 additions & 3 deletions packages/@aws-cdk/acm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"url": "git://github.com/awslabs/aws-cdk"
},
"scripts": {
"prepare": "jsii && tslint -p . && pkglint",
"build": "cfn2ts --scope=AWS::CertificateManager && jsii && tslint -p . && pkglint",
"watch": "jsii -w",
"lint": "jsii && tslint -p . --force",
"test": "nodeunit test/test.*.js",
Expand All @@ -36,13 +36,13 @@
"license": "LicenseRef-LICENSE",
"devDependencies": {
"@aws-cdk/assert": "^0.7.3-beta",
"aws-cdk": "^0.7.3-beta",
"aws-sdk": "^2.259.1",
"cfn2ts": "^0.7.3-beta",
"pkglint": "^0.7.3-beta"
},
"dependencies": {
"@aws-cdk/core": "^0.7.3-beta",
"@aws-cdk/iam": "^0.7.3-beta",
"@aws-cdk/resources": "^0.7.3-beta"
"@aws-cdk/runtime": "^0.7.3-beta"
}
}
8 changes: 8 additions & 0 deletions packages/@aws-cdk/apigateway/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.js
*.js.map
*.d.ts
tsconfig.json
tslint.json
node_modules
cfn
dist
2 changes: 2 additions & 0 deletions packages/@aws-cdk/apigateway/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// The L1 Library for AWS::ApiGateway:
export * from '../cfn/apigateway';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the generated code should go under lib/cloudformation/

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, make sure cfn2ts creates a README file under the generated directory that says that it is generated and from which spec date

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That information is already included in the generated file itself... Do we really need it repeated?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, you are right.

Loading