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

feat: construct base class changes (breaking) #1444

Merged
merged 29 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c0d2d6a
doc: RFC for code asset metadata
Dec 26, 2018
9eeb8de
Close backticks
Dec 26, 2018
ad1a902
feat(assets): enable local tooling scenarios such as lambda debugging
Dec 27, 2018
a081639
revert unwanted change in function
Dec 27, 2018
416b6ba
Support disabling asset metadata (and disable in integ tests)
Dec 27, 2018
0f83270
Fix test
Dec 27, 2018
304e062
[WIP] construct refactors
Dec 27, 2018
d9b2e41
Merge remote-tracking branch 'origin/master' into benisrae/construct-…
Dec 27, 2018
fa22bdb
Merge remote-tracking branch 'origin/master' into benisrae/construct-…
Dec 30, 2018
9d90186
Fix immutability
Dec 30, 2018
90109bc
Rename generated parameter
Dec 30, 2018
c5a37dd
Rename "import" signature params to scope,scid,props
Dec 31, 2018
90f9e0b
more import linting
Dec 31, 2018
ad17a70
Revert construct id from "scid" to "id"
Dec 31, 2018
0c46f47
Fix a couple of tests
Jan 1, 2019
1f11823
Fix license/notice files to 2019
Jan 1, 2019
fa91909
extend IConstruct
Jan 1, 2019
dee1c6a
Clean up pipeline API a little
Jan 1, 2019
bacf1f1
Fix APIGW root
Jan 1, 2019
cf9d0a3
More linting
Jan 2, 2019
d9a14e8
Merge remote-tracking branch 'origin/master' into benisrae/construct-…
Jan 2, 2019
63b22b7
Revert
Jan 2, 2019
90ab74d
codepipeline fixes
Jan 2, 2019
a4ad01a
fix ecr build break
Jan 3, 2019
12a11f2
Revert cfn2ts default not to force regeneration
Jan 3, 2019
93bf0d3
Move reverts from scid to id
Jan 3, 2019
7b43081
Revert accidental rename of `containsCidr`
Jan 3, 2019
bd63dcf
Fix containsCidr test
Jan 3, 2019
a4dd4c5
Fix codecommit
Jan 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions examples/cdk-examples-typescript/advanced-usage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import cdk = require('@aws-cdk/cdk');
* This stack demonstrates the use of the IAM policy library shipped with the CDK.
*/
class PolicyExample extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

// here's how to create an IAM Role with an assume policy for the Lambda
// service principal.
Expand All @@ -38,8 +38,8 @@ class PolicyExample extends cdk.Stack {
* the AZ list and the AMI IDs are different.
*/
class EnvContextExample extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

// get the list of AZs for the current region/account
const azs = new cdk.AvailabilityZoneProvider(this).availabilityZones;
Expand Down Expand Up @@ -68,8 +68,8 @@ class EnvContextExample extends cdk.Stack {
* into your CDK stack and then add constructs and resources programmatically to it.
*/
class IncludeExample extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

// so you have an existing template...
// you can also load it from a file:
Expand All @@ -89,14 +89,14 @@ class IncludeExample extends cdk.Stack {
new cdk.Include(this, 'Include', { template });

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

class NestedStackExample extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

// pick up to 3 AZs from environment.
const azs = new cdk.AvailabilityZoneProvider(this).availabilityZones.slice(0, 3);
Expand All @@ -122,8 +122,8 @@ class NestedStackExample extends cdk.Stack {
* It also demonstrates how to modify resource options such as metadata
*/
class ResourceReferencesExample extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

const topic = new sns.CfnTopic(this, 'Topic', {});
const queue = new sqs.CfnQueue(this, 'Queue', {});
Expand All @@ -145,8 +145,8 @@ class ResourceReferencesExample extends cdk.Stack {
* Demonstrates how to use CloudFormation parameters, outputs, pseudo parameters and intrinsic functions.
*/
class CloudFormationExample extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

// parameters are constructs that synthesize into the template's "Parameters" section
const param = new cdk.Parameter(this, 'MyTemplateParameter', {
Expand Down
12 changes: 6 additions & 6 deletions examples/cdk-examples-typescript/bucket-import-export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import cdk = require('@aws-cdk/cdk');
class Producer extends cdk.Stack {
public readonly myBucketRef: s3.BucketImportProps;

constructor(parent: cdk.App, name: string) {
super(parent, name);
constructor(scope: cdk.App, scid: string) {
super(scope, scid);

const bucket = new s3.Bucket(this, 'MyBucket');
this.myBucketRef = bucket.export();
Expand All @@ -22,8 +22,8 @@ interface ConsumerConstructProps {
}

class ConsumerConstruct extends cdk.Construct {
constructor(parent: cdk.Construct, name: string, props: ConsumerConstructProps) {
super(parent, name);
constructor(scope: cdk.Construct, scid: string, props: ConsumerConstructProps) {
super(scope, scid);

props.bucket.addToResourcePolicy(new iam.PolicyStatement().addAction('*'));
}
Expand All @@ -39,8 +39,8 @@ interface ConsumerProps {
}

class Consumer extends cdk.Stack {
constructor(parent: cdk.App, name: string, props: ConsumerProps) {
super(parent, name);
constructor(scope: cdk.App, scid: string, props: ConsumerProps) {
super(scope, scid);

const user = new iam.User(this, 'MyUser');
const userBucket = s3.Bucket.import(this, 'ImportBucket', props.userBucketRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import cognito = require('@aws-cdk/aws-cognito');
import cdk = require('@aws-cdk/cdk');

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

// Create chat room user pool
const chatPool = new cognito.CfnUserPool(this, 'UserPool', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import dynamodb = require('@aws-cdk/aws-dynamodb');
import cdk = require('@aws-cdk/cdk');

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

const table = new dynamodb.Table(this, 'Table', {
readCapacity: 5, writeCapacity: 5
Expand Down
8 changes: 4 additions & 4 deletions examples/cdk-examples-typescript/chat-app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { CognitoChatRoomPool } from './cognito-chat-room-pool';
import { DynamoPostsTable } from './dynamodb-posts-table';

class MyStack extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

new DynamoPostsTable(this, 'Posts');

Expand Down Expand Up @@ -77,8 +77,8 @@ interface ChatAppFuncProps {
* Extend Function as all of the Chat app functions have these common props.
*/
class ChatAppFunction extends lambda.Function {
constructor(parent: cdk.Construct, name: string, props: ChatAppFuncProps) {
super(parent, name, {
constructor(scope: cdk.Construct, scid: string, props: ChatAppFuncProps) {
super(scope, scid, {
code: new lambda.S3Code(props.bucket, props.zipFile),
runtime: lambda.Runtime.NodeJS610,
handler: 'index.handler'
Expand Down
4 changes: 2 additions & 2 deletions examples/cdk-examples-typescript/cloudformation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import sqs = require('@aws-cdk/aws-sqs');
import cdk = require('@aws-cdk/cdk');

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

new sqs.CfnQueue(this, 'MyQueue', {
visibilityTimeout: 300
Expand Down
16 changes: 8 additions & 8 deletions examples/cdk-examples-typescript/custom-resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class DemoResource extends cdk.Construct implements cdk.IDependable {
public readonly dependencyElements: cdk.IDependable[];
public readonly response: string;

constructor(parent: cdk.Construct, name: string, props: DemoResourceProps) {
super(parent, name);
constructor(scope: cdk.Construct, scid: string, props: DemoResourceProps) {
super(scope, scid);

const resource = new CustomResource(this, 'Resource', {
lambdaProvider: new lambda.SingletonFunction(this, 'Singleton', {
Expand All @@ -44,8 +44,8 @@ class DemoResource extends cdk.Construct implements cdk.IDependable {
* A stack that only sets up the CustomResource and shows how to get an attribute from it
*/
class SucceedingStack extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

const resource = new DemoResource(this, 'DemoResource', {
message: 'CustomResource says hello',
Expand All @@ -63,8 +63,8 @@ class SucceedingStack extends cdk.Stack {
* A stack that sets up a failing CustomResource creation
*/
class FailCreationStack extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

new DemoResource(this, 'DemoResource', {
message: 'CustomResource is silent',
Expand All @@ -78,8 +78,8 @@ class FailCreationStack extends cdk.Stack {
* done properly.
*/
class FailAfterCreatingStack extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

const resource = new DemoResource(this, 'DemoResource', {
message: 'CustomResource says hello',
Expand Down
12 changes: 6 additions & 6 deletions examples/cdk-examples-typescript/ec2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import elb = require('@aws-cdk/aws-elasticloadbalancing');
import cdk = require('@aws-cdk/cdk');

class AppWithVpc extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

const vpc = new ec2.VpcNetwork(this, 'MyVpc');

Expand All @@ -30,8 +30,8 @@ interface MyAppProps extends cdk.StackProps {
}

class MyApp extends cdk.Stack {
constructor(parent: cdk.App, name: string, props: MyAppProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props: MyAppProps) {
super(scope, scid, props);

const vpc = ec2.VpcNetwork.import(this, 'VPC', props.infra.vpc);

Expand All @@ -54,8 +54,8 @@ class MyApp extends cdk.Stack {
class CommonInfrastructure extends cdk.Stack {
public vpc: ec2.VpcNetworkImportProps;

constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

const vpc = new ec2.VpcNetwork(this, 'VPC');
this.vpc = vpc.export();
Expand Down
4 changes: 2 additions & 2 deletions examples/cdk-examples-typescript/hello-cdk-ecs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import ecs = require('@aws-cdk/aws-ecs');
import cdk = require('@aws-cdk/cdk');

class BonjourECS extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

// For better iteration speed, it might make sense to put this VPC into
// a separate stack and import it here. We then have two stacks to
Expand Down
4 changes: 2 additions & 2 deletions examples/cdk-examples-typescript/hello-cdk-fargate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import ecs = require('@aws-cdk/aws-ecs');
import cdk = require('@aws-cdk/cdk');

class BonjourFargate extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

// Create VPC and Fargate Cluster
// NOTE: Limit AZs to avoid reaching resource quotas
Expand Down
4 changes: 2 additions & 2 deletions examples/cdk-examples-typescript/hello-cdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import dynamodb = require('@aws-cdk/aws-dynamodb');
import cdk = require('@aws-cdk/cdk');

class HelloCDK extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);
constructor(scope: cdk.App, scid: string, props?: cdk.StackProps) {
super(scope, scid, props);

const table = new dynamodb.Table(this, 'Table', {
readCapacity: 1,
Expand Down
16 changes: 7 additions & 9 deletions examples/cdk-examples-typescript/resource-overrides/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import cdk = require('@aws-cdk/cdk');
import assert = require('assert');

class ResourceOverridesExample extends cdk.Stack {
constructor(parent: cdk.App, id: string) {
super(parent, id);
constructor(scope: cdk.App, scid: string) {
super(scope, scid);

const otherBucket = new s3.Bucket(this, 'Other');

Expand All @@ -15,25 +15,23 @@ class ResourceOverridesExample extends cdk.Stack {
encryption: s3.BucketEncryption.KmsManaged
});

const bucketResource2 = bucket.findChild('Resource') as s3.CfnBucket;
const bucketResource2 = bucket.node.findChild('Resource') as s3.CfnBucket;
bucketResource2.addPropertyOverride('BucketEncryption.ServerSideEncryptionConfiguration.0.EncryptEverythingAndAlways', true);
bucketResource2.addPropertyDeletionOverride('BucketEncryption.ServerSideEncryptionConfiguration.0.ServerSideEncryptionByDefault');

return;

//
// Accessing the L1 bucket resource from an L2 bucket
//

const bucketResource = bucket.findChild('Resource') as s3.CfnBucket;
const anotherWay = bucket.children.find(c => (c as cdk.Resource).resourceType === 'AWS::S3::Bucket') as s3.CfnBucket;
const bucketResource = bucket.node.findChild('Resource') as s3.CfnBucket;
const anotherWay = bucket.node.children.find(c => (c as cdk.Resource).resourceType === 'AWS::S3::Bucket') as s3.CfnBucket;
assert.equal(bucketResource, anotherWay);

//
// This is how to specify resource options such as dependencies, metadata, update policy
//

bucketResource.addDependency(otherBucket.findChild('Resource') as cdk.Resource);
bucketResource.addDependency(otherBucket.node.findChild('Resource') as cdk.Resource);
bucketResource.options.metadata = { MetadataKey: 'MetadataValue' };
bucketResource.options.updatePolicy = {
autoScalingRollingUpdate: {
Expand Down Expand Up @@ -108,7 +106,7 @@ class ResourceOverridesExample extends cdk.Stack {
// need to consule the codebase or use the `.map.find` method above
//

const lc = asg.findChild('LaunchConfig') as autoscaling.CfnLaunchConfiguration;
const lc = asg.node.findChild('LaunchConfig') as autoscaling.CfnLaunchConfiguration;
lc.addPropertyOverride('Foo.Bar', 'Hello');
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/cdk-examples-typescript/sns-sqs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import sqs = require('@aws-cdk/aws-sqs');
import cdk = require('@aws-cdk/cdk');

class ACL extends cdk.Stack {
constructor(parent: cdk.App, name: string) {
super(parent, name);
constructor(scope: cdk.App, scid: string) {
super(scope, scid);

const topic = new sns.Topic(this, 'MyTopic');
const queue = new sqs.Queue(this, 'MyQueue', {
Expand All @@ -17,8 +17,8 @@ class ACL extends cdk.Stack {
}

class CFN extends cdk.Stack {
constructor(parent: cdk.App, name: string) {
super(parent, name);
constructor(scope: cdk.App, scid: string) {
super(scope, scid);

const topic = new sns.CfnTopic(this, 'MyTopic');
const queue = new sqs.CfnQueue(this, 'MyQueue');
Expand Down
4 changes: 4 additions & 0 deletions packages/@aws-cdk/alexa-ask/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ dist
.LAST_BUILD
.LAST_PACKAGE
.jsii


# Include .jsii
!.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export class PipelineDeployStackAction extends cdk.Construct {

private readonly stack: cdk.Stack;

constructor(parent: cdk.Construct, id: string, props: PipelineDeployStackActionProps) {
super(parent, id);
constructor(scope: cdk.Construct, id: string, props: PipelineDeployStackActionProps) {
super(scope, id);

if (!cdk.environmentEquals(props.stack.env, cdk.Stack.find(this).env)) {
// FIXME: Add the necessary to extend to stacks in a different account
Expand Down Expand Up @@ -142,7 +142,7 @@ export class PipelineDeployStackAction extends cdk.Construct {

public validate(): string[] {
const result = super.validate();
const assets = this.stack.metadata.filter(md => md.type === cxapi.ASSET_METADATA);
const assets = this.stack.node.metadata.filter(md => md.type === cxapi.ASSET_METADATA);
if (assets.length > 0) {
// FIXME: Implement the necessary actions to publish assets
result.push(`Cannot deploy the stack ${this.stack.name} because it references ${assets.length} asset(s)`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export = nodeunit.testCase({
adminPermissions: false,
});
for (let i = 0 ; i < assetCount ; i++) {
deployedStack.addMetadata(cxapi.ASSET_METADATA, {});
deployedStack.node.addMetadata(cxapi.ASSET_METADATA, {});
}
test.deepEqual(action.validate(),
[`Cannot deploy the stack DeployedStack because it references ${assetCount} asset(s)`]);
Expand All @@ -286,8 +286,8 @@ export = nodeunit.testCase({
class FakeAction extends api.Action {
public readonly outputArtifact: api.Artifact;

constructor(parent: cdk.Construct, id: string, pipeline: code.Pipeline) {
super(parent, id, {
constructor(scope: cdk.Construct, id: string, pipeline: code.Pipeline) {
super(scope, id, {
artifactBounds: api.defaultBounds(),
category: api.ActionCategory.Test,
provider: 'Test',
Expand Down
Loading