diff --git a/examples/cdk-examples-typescript/advanced-usage/index.ts b/examples/cdk-examples-typescript/advanced-usage/index.ts index 233df2d25be1a..20fb650ebbe2c 100644 --- a/examples/cdk-examples-typescript/advanced-usage/index.ts +++ b/examples/cdk-examples-typescript/advanced-usage/index.ts @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); // here's how to create an IAM Role with an assume policy for the Lambda // service principal. @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); // get the list of AZs for the current region/account const azs = new cdk.AvailabilityZoneProvider(this).availabilityZones; @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); // so you have an existing template... // you can also load it from a file: @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); // pick up to 3 AZs from environment. const azs = new cdk.AvailabilityZoneProvider(this).availabilityZones.slice(0, 3); @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); const topic = new sns.CfnTopic(this, 'Topic', {}); const queue = new sqs.CfnQueue(this, 'Queue', {}); @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); // parameters are constructs that synthesize into the template's "Parameters" section const param = new cdk.Parameter(this, 'MyTemplateParameter', { diff --git a/examples/cdk-examples-typescript/bucket-import-export/index.ts b/examples/cdk-examples-typescript/bucket-import-export/index.ts index 32ecea2465819..e5c806ac5ae80 100644 --- a/examples/cdk-examples-typescript/bucket-import-export/index.ts +++ b/examples/cdk-examples-typescript/bucket-import-export/index.ts @@ -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, id: string) { + super(scope, id); const bucket = new s3.Bucket(this, 'MyBucket'); this.myBucketRef = bucket.export(); @@ -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, id: string, props: ConsumerConstructProps) { + super(scope, id); props.bucket.addToResourcePolicy(new iam.PolicyStatement().addAction('*')); } @@ -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, id: string, props: ConsumerProps) { + super(scope, id); const user = new iam.User(this, 'MyUser'); const userBucket = s3.Bucket.import(this, 'ImportBucket', props.userBucketRef); diff --git a/examples/cdk-examples-typescript/chat-app/cognito-chat-room-pool.ts b/examples/cdk-examples-typescript/chat-app/cognito-chat-room-pool.ts index 148384e5ed4c2..2ca776f6f777b 100644 --- a/examples/cdk-examples-typescript/chat-app/cognito-chat-room-pool.ts +++ b/examples/cdk-examples-typescript/chat-app/cognito-chat-room-pool.ts @@ -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, id: string) { + super(scope, id); // Create chat room user pool const chatPool = new cognito.CfnUserPool(this, 'UserPool', { diff --git a/examples/cdk-examples-typescript/chat-app/dynamodb-posts-table.ts b/examples/cdk-examples-typescript/chat-app/dynamodb-posts-table.ts index 4964eb58b485c..717da7f0aecc5 100644 --- a/examples/cdk-examples-typescript/chat-app/dynamodb-posts-table.ts +++ b/examples/cdk-examples-typescript/chat-app/dynamodb-posts-table.ts @@ -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, id: string) { + super(scope, id); const table = new dynamodb.Table(this, 'Table', { readCapacity: 5, writeCapacity: 5 diff --git a/examples/cdk-examples-typescript/chat-app/index.ts b/examples/cdk-examples-typescript/chat-app/index.ts index e2cad596456aa..6cbe846e4c9e8 100644 --- a/examples/cdk-examples-typescript/chat-app/index.ts +++ b/examples/cdk-examples-typescript/chat-app/index.ts @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); new DynamoPostsTable(this, 'Posts'); @@ -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, id: string, props: ChatAppFuncProps) { + super(scope, id, { code: new lambda.S3Code(props.bucket, props.zipFile), runtime: lambda.Runtime.NodeJS610, handler: 'index.handler' diff --git a/examples/cdk-examples-typescript/cloudformation/index.ts b/examples/cdk-examples-typescript/cloudformation/index.ts index e6c9776f541b7..0356b31abfafc 100644 --- a/examples/cdk-examples-typescript/cloudformation/index.ts +++ b/examples/cdk-examples-typescript/cloudformation/index.ts @@ -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 diff --git a/examples/cdk-examples-typescript/custom-resource/index.ts b/examples/cdk-examples-typescript/custom-resource/index.ts index bf1d716d0ab81..2414e1a968a4a 100644 --- a/examples/cdk-examples-typescript/custom-resource/index.ts +++ b/examples/cdk-examples-typescript/custom-resource/index.ts @@ -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, id: string, props: DemoResourceProps) { + super(scope, id); const resource = new CustomResource(this, 'Resource', { lambdaProvider: new lambda.SingletonFunction(this, 'Singleton', { @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); const resource = new DemoResource(this, 'DemoResource', { message: 'CustomResource says hello', @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); new DemoResource(this, 'DemoResource', { message: 'CustomResource is silent', @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); const resource = new DemoResource(this, 'DemoResource', { message: 'CustomResource says hello', diff --git a/examples/cdk-examples-typescript/ec2/index.ts b/examples/cdk-examples-typescript/ec2/index.ts index a94323c79e0af..d0f5573812bba 100644 --- a/examples/cdk-examples-typescript/ec2/index.ts +++ b/examples/cdk-examples-typescript/ec2/index.ts @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); const vpc = new ec2.VpcNetwork(this, 'MyVpc'); @@ -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, id: string, props: MyAppProps) { + super(scope, id, props); const vpc = ec2.VpcNetwork.import(this, 'VPC', props.infra.vpc); @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); const vpc = new ec2.VpcNetwork(this, 'VPC'); this.vpc = vpc.export(); diff --git a/examples/cdk-examples-typescript/hello-cdk-ecs/index.ts b/examples/cdk-examples-typescript/hello-cdk-ecs/index.ts index 3723874e96fda..522c4f175220b 100644 --- a/examples/cdk-examples-typescript/hello-cdk-ecs/index.ts +++ b/examples/cdk-examples-typescript/hello-cdk-ecs/index.ts @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, 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 diff --git a/examples/cdk-examples-typescript/hello-cdk-fargate/index.ts b/examples/cdk-examples-typescript/hello-cdk-fargate/index.ts index 531584a438e3f..dacee77a53e45 100644 --- a/examples/cdk-examples-typescript/hello-cdk-fargate/index.ts +++ b/examples/cdk-examples-typescript/hello-cdk-fargate/index.ts @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); // Create VPC and Fargate Cluster // NOTE: Limit AZs to avoid reaching resource quotas diff --git a/examples/cdk-examples-typescript/hello-cdk/index.ts b/examples/cdk-examples-typescript/hello-cdk/index.ts index 794add4b1a3db..21d66282bf765 100644 --- a/examples/cdk-examples-typescript/hello-cdk/index.ts +++ b/examples/cdk-examples-typescript/hello-cdk/index.ts @@ -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, id: string, props?: cdk.StackProps) { + super(scope, id, props); const table = new dynamodb.Table(this, 'Table', { readCapacity: 1, diff --git a/examples/cdk-examples-typescript/resource-overrides/index.ts b/examples/cdk-examples-typescript/resource-overrides/index.ts index eda4a6b6fae2a..35fa7067a138e 100644 --- a/examples/cdk-examples-typescript/resource-overrides/index.ts +++ b/examples/cdk-examples-typescript/resource-overrides/index.ts @@ -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, id: string) { + super(scope, id); const otherBucket = new s3.Bucket(this, 'Other'); @@ -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: { @@ -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'); } } diff --git a/examples/cdk-examples-typescript/sns-sqs/index.ts b/examples/cdk-examples-typescript/sns-sqs/index.ts index 6957a48f28cc6..db303fab94d4d 100644 --- a/examples/cdk-examples-typescript/sns-sqs/index.ts +++ b/examples/cdk-examples-typescript/sns-sqs/index.ts @@ -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, id: string) { + super(scope, id); const topic = new sns.Topic(this, 'MyTopic'); const queue = new sqs.Queue(this, 'MyQueue', { @@ -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, id: string) { + super(scope, id); const topic = new sns.CfnTopic(this, 'MyTopic'); const queue = new sqs.CfnQueue(this, 'MyQueue'); diff --git a/packages/@aws-cdk/alexa-ask/.npmignore b/packages/@aws-cdk/alexa-ask/.npmignore index 0ed32f4a4a755..2895a406c8e61 100644 --- a/packages/@aws-cdk/alexa-ask/.npmignore +++ b/packages/@aws-cdk/alexa-ask/.npmignore @@ -15,3 +15,7 @@ dist .LAST_BUILD .LAST_PACKAGE .jsii + + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/app-delivery/lib/pipeline-deploy-stack-action.ts b/packages/@aws-cdk/app-delivery/lib/pipeline-deploy-stack-action.ts index 7e8155a62a6e8..e784850965d7a 100644 --- a/packages/@aws-cdk/app-delivery/lib/pipeline-deploy-stack-action.ts +++ b/packages/@aws-cdk/app-delivery/lib/pipeline-deploy-stack-action.ts @@ -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 @@ -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)`); diff --git a/packages/@aws-cdk/app-delivery/test/test.pipeline-deploy-stack-action.ts b/packages/@aws-cdk/app-delivery/test/test.pipeline-deploy-stack-action.ts index 3c5876a60a894..3a73933d135e9 100644 --- a/packages/@aws-cdk/app-delivery/test/test.pipeline-deploy-stack-action.ts +++ b/packages/@aws-cdk/app-delivery/test/test.pipeline-deploy-stack-action.ts @@ -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)`]); @@ -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', diff --git a/packages/@aws-cdk/applet-js/test/test-applet.ts b/packages/@aws-cdk/applet-js/test/test-applet.ts index 685fbc98f1422..978f644bd88d3 100644 --- a/packages/@aws-cdk/applet-js/test/test-applet.ts +++ b/packages/@aws-cdk/applet-js/test/test-applet.ts @@ -7,11 +7,11 @@ export interface TestAppletProps extends StackProps { } export class TestApplet extends Stack { - constructor(parent: App, name: string, props: TestAppletProps) { - super(parent, name, props); + constructor(scope: App, id: string, props: TestAppletProps) { + super(scope, id, props); - new Parameter(this, 'P1', { default: this.required(props, 'prop1'), type: 'String' }); - new Parameter(this, 'P2', { default: this.required(props, 'prop2'), type: 'Number' }); + new Parameter(this, 'P1', { default: this.node.required(props, 'prop1'), type: 'String' }); + new Parameter(this, 'P2', { default: this.node.required(props, 'prop2'), type: 'Number' }); if (props.prop3) { new Parameter(this, 'P3', { default: props.prop3.join(','), type: 'StringList' }); @@ -24,8 +24,8 @@ export interface AppletProps extends StackProps { } export class Applet extends Stack { - constructor(parent: App, name: string, props: AppletProps) { - super(parent, name); + constructor(scope: App, id: string, props: AppletProps) { + super(scope, id); this.templateOptions.description = props.desc; } @@ -36,8 +36,8 @@ interface NoStackAppletProps { } export class NoStackApplet extends Construct { - constructor(parent: Construct, id: string, props: NoStackAppletProps) { - super(parent, id); + constructor(scope: Construct, id: string, props: NoStackAppletProps) { + super(scope, id); new Parameter(this, 'P1', { default: props.argument, type: 'String' }); } diff --git a/packages/@aws-cdk/assert/lib/expect.ts b/packages/@aws-cdk/assert/lib/expect.ts index 63108bd990b4d..a98a18abdc389 100644 --- a/packages/@aws-cdk/assert/lib/expect.ts +++ b/packages/@aws-cdk/assert/lib/expect.ts @@ -9,9 +9,9 @@ export function expect(stack: api.SynthesizedStack | cdk.Stack, skipValidation = if (isStackClassInstance(stack)) { if (!skipValidation) { - const errors = stack.validateTree(); + const errors = stack.node.validateTree(); if (errors.length > 0) { - throw new Error(`Stack validation failed:\n${errors.map(e => `${e.message} at: ${e.source.parent}`).join('\n')}`); + throw new Error(`Stack validation failed:\n${errors.map(e => `${e.message} at: ${e.source.node.scope}`).join('\n')}`); } } diff --git a/packages/@aws-cdk/assert/test/test.assertions.ts b/packages/@aws-cdk/assert/test/test.assertions.ts index 6591d679fc475..1a825c476c3f7 100644 --- a/packages/@aws-cdk/assert/test/test.assertions.ts +++ b/packages/@aws-cdk/assert/test/test.assertions.ts @@ -210,7 +210,7 @@ interface TestResourceProps extends cdk.ResourceProps { } class TestResource extends cdk.Resource { - constructor(parent: cdk.Construct, name: string, props: TestResourceProps) { - super(parent, name, props); + constructor(scope: cdk.Construct, id: string, props: TestResourceProps) { + super(scope, id, props); } } diff --git a/packages/@aws-cdk/assets-docker/lib/adopted-repository.ts b/packages/@aws-cdk/assets-docker/lib/adopted-repository.ts index 49fe6bfcce726..e8948eb436c0a 100644 --- a/packages/@aws-cdk/assets-docker/lib/adopted-repository.ts +++ b/packages/@aws-cdk/assets-docker/lib/adopted-repository.ts @@ -29,8 +29,8 @@ export class AdoptedRepository extends ecr.RepositoryBase { private readonly policyDocument = new iam.PolicyDocument(); - constructor(parent: cdk.Construct, id: string, private readonly props: AdoptedRepositoryProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: AdoptedRepositoryProps) { + super(scope, id); const fn = new lambda.SingletonFunction(this, 'Function', { runtime: lambda.Runtime.NodeJS810, diff --git a/packages/@aws-cdk/assets-docker/lib/image-asset.ts b/packages/@aws-cdk/assets-docker/lib/image-asset.ts index 8226d0635ef24..ef895e0e88a40 100644 --- a/packages/@aws-cdk/assets-docker/lib/image-asset.ts +++ b/packages/@aws-cdk/assets-docker/lib/image-asset.ts @@ -34,8 +34,8 @@ export class DockerImageAsset extends cdk.Construct { */ private readonly directory: string; - constructor(parent: cdk.Construct, id: string, props: DockerImageAssetProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: DockerImageAssetProps) { + super(scope, id); // resolve full path this.directory = path.resolve(props.directory); @@ -48,17 +48,17 @@ export class DockerImageAsset extends cdk.Construct { const imageNameParameter = new cdk.Parameter(this, 'ImageName', { type: 'String', - description: `ECR repository name and tag asset "${this.path}"`, + description: `ECR repository name and tag asset "${this.node.path}"`, }); const asset: cxapi.ContainerImageAssetMetadataEntry = { packaging: 'container-image', path: this.directory, - id: this.uniqueId, + id: this.node.uniqueId, imageNameParameter: imageNameParameter.logicalId }; - this.addMetadata(cxapi.ASSET_METADATA, asset); + this.node.addMetadata(cxapi.ASSET_METADATA, asset); // parse repository name and tag from the parameter (:) const components = cdk.Fn.split(':', imageNameParameter.valueAsString); diff --git a/packages/@aws-cdk/assets/lib/asset.ts b/packages/@aws-cdk/assets/lib/asset.ts index ff047f80ee4ad..d212171d738c9 100644 --- a/packages/@aws-cdk/assets/lib/asset.ts +++ b/packages/@aws-cdk/assets/lib/asset.ts @@ -81,8 +81,8 @@ export class Asset extends cdk.Construct { */ private readonly s3Prefix: string; - constructor(parent: cdk.Construct, id: string, props: GenericAssetProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: GenericAssetProps) { + super(scope, id); // resolve full path this.assetPath = path.resolve(props.path); @@ -101,12 +101,12 @@ export class Asset extends cdk.Construct { const bucketParam = new cdk.Parameter(this, 'S3Bucket', { type: 'String', - description: `S3 bucket for asset "${this.path}"`, + description: `S3 bucket for asset "${this.node.path}"`, }); const keyParam = new cdk.Parameter(this, 'S3VersionKey', { type: 'String', - description: `S3 key for asset version "${this.path}"` + description: `S3 key for asset version "${this.node.path}"` }); this.s3BucketName = bucketParam.value.toString(); @@ -127,13 +127,13 @@ export class Asset extends cdk.Construct { // parameters. const asset: cxapi.FileAssetMetadataEntry = { path: this.assetPath, - id: this.uniqueId, + id: this.node.uniqueId, packaging: props.packaging, s3BucketParameter: bucketParam.logicalId, s3KeyParameter: keyParam.logicalId, }; - this.addMetadata(cxapi.ASSET_METADATA, asset); + this.node.addMetadata(cxapi.ASSET_METADATA, asset); for (const reader of (props.readers || [])) { this.grantRead(reader); @@ -157,7 +157,7 @@ export class Asset extends cdk.Construct { * (e.g. "Code" for AWS::Lambda::Function) */ public addResourceMetadata(resource: cdk.Resource, resourceProperty: string) { - if (!this.getContext(cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT)) { + if (!this.node.getContext(cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT)) { return; // not enabled } @@ -197,8 +197,8 @@ export interface FileAssetProps { * An asset that represents a file on disk. */ export class FileAsset extends Asset { - constructor(parent: cdk.Construct, id: string, props: FileAssetProps) { - super(parent, id, { packaging: AssetPackaging.File, ...props }); + constructor(scope: cdk.Construct, id: string, props: FileAssetProps) { + super(scope, id, { packaging: AssetPackaging.File, ...props }); } } @@ -219,8 +219,8 @@ export interface ZipDirectoryAssetProps { * An asset that represents a ZIP archive of a directory on disk. */ export class ZipDirectoryAsset extends Asset { - constructor(parent: cdk.Construct, id: string, props: ZipDirectoryAssetProps) { - super(parent, id, { packaging: AssetPackaging.ZipDirectory, ...props }); + constructor(scope: cdk.Construct, id: string, props: ZipDirectoryAssetProps) { + super(scope, id, { packaging: AssetPackaging.ZipDirectory, ...props }); } } diff --git a/packages/@aws-cdk/assets/test/integ.assets.directory.lit.ts b/packages/@aws-cdk/assets/test/integ.assets.directory.lit.ts index 5a47748ef53e4..c40a17e30852c 100644 --- a/packages/@aws-cdk/assets/test/integ.assets.directory.lit.ts +++ b/packages/@aws-cdk/assets/test/integ.assets.directory.lit.ts @@ -4,8 +4,8 @@ import path = require('path'); import assets = require('../lib'); class TestStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { + super(scope, id, props); /// !show const asset = new assets.ZipDirectoryAsset(this, 'SampleAsset', { diff --git a/packages/@aws-cdk/assets/test/integ.assets.file.lit.ts b/packages/@aws-cdk/assets/test/integ.assets.file.lit.ts index f5bb206972f17..2e404ae70612c 100644 --- a/packages/@aws-cdk/assets/test/integ.assets.file.lit.ts +++ b/packages/@aws-cdk/assets/test/integ.assets.file.lit.ts @@ -4,8 +4,8 @@ import path = require('path'); import assets = require('../lib'); class TestStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { + super(scope, id, props); /// !show const asset = new assets.FileAsset(this, 'SampleAsset', { diff --git a/packages/@aws-cdk/assets/test/integ.assets.permissions.lit.ts b/packages/@aws-cdk/assets/test/integ.assets.permissions.lit.ts index a489c0f4f993e..b42dfc87c4e98 100644 --- a/packages/@aws-cdk/assets/test/integ.assets.permissions.lit.ts +++ b/packages/@aws-cdk/assets/test/integ.assets.permissions.lit.ts @@ -4,8 +4,8 @@ import path = require('path'); import assets = require('../lib'); class TestStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { + super(scope, id, props); const asset = new assets.FileAsset(this, 'MyFile', { path: path.join(__dirname, 'file-asset.txt') diff --git a/packages/@aws-cdk/assets/test/integ.assets.refs.lit.ts b/packages/@aws-cdk/assets/test/integ.assets.refs.lit.ts index 94e7cff503d9c..056fc21136f11 100644 --- a/packages/@aws-cdk/assets/test/integ.assets.refs.lit.ts +++ b/packages/@aws-cdk/assets/test/integ.assets.refs.lit.ts @@ -4,8 +4,8 @@ import path = require('path'); import assets = require('../lib'); class TestStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { + super(scope, id, props); /// !show const asset = new assets.ZipDirectoryAsset(this, 'SampleAsset', { diff --git a/packages/@aws-cdk/assets/test/integ.multi-assets.ts b/packages/@aws-cdk/assets/test/integ.multi-assets.ts index 33d732d5f1afa..4cf6220d8ca61 100644 --- a/packages/@aws-cdk/assets/test/integ.multi-assets.ts +++ b/packages/@aws-cdk/assets/test/integ.multi-assets.ts @@ -3,8 +3,8 @@ import path = require('path'); import assets = require('../lib'); class TestStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { + super(scope, id, props); // Check that the same asset added multiple times is // uploaded and copied. diff --git a/packages/@aws-cdk/assets/test/test.asset.ts b/packages/@aws-cdk/assets/test/test.asset.ts index e299f46928485..849063ffa7189 100644 --- a/packages/@aws-cdk/assets/test/test.asset.ts +++ b/packages/@aws-cdk/assets/test/test.asset.ts @@ -16,7 +16,7 @@ export = { // verify that metadata contains an "aws:cdk:asset" entry with // the correct information - const entry = asset.metadata.find(m => m.type === 'aws:cdk:asset'); + const entry = asset.node.metadata.find(m => m.type === 'aws:cdk:asset'); test.ok(entry, 'found metadata entry'); test.deepEqual(entry!.data, { path: dirPath, @@ -38,7 +38,7 @@ export = { const stack = new cdk.Stack(); const filePath = path.join(__dirname, 'file-asset.txt'); const asset = new FileAsset(stack, 'MyAsset', { path: filePath }); - const entry = asset.metadata.find(m => m.type === 'aws:cdk:asset'); + const entry = asset.node.metadata.find(m => m.type === 'aws:cdk:asset'); test.ok(entry, 'found metadata entry'); test.deepEqual(entry!.data, { path: filePath, @@ -146,7 +146,7 @@ export = { 'addResourceMetadata can be used to add CFN metadata to resources'(test: Test) { // GIVEN const stack = new cdk.Stack(); - stack.setContext(cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT, true); + stack.node.setContext(cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT, true); const location = path.join(__dirname, 'sample-asset-directory'); const resource = new cdk.Resource(stack, 'MyResource', { type: 'My::Resource::Type' }); diff --git a/packages/@aws-cdk/aws-amazonmq/.npmignore b/packages/@aws-cdk/aws-amazonmq/.npmignore index a38f4a5187806..aedb60356c270 100644 --- a/packages/@aws-cdk/aws-amazonmq/.npmignore +++ b/packages/@aws-cdk/aws-amazonmq/.npmignore @@ -15,4 +15,7 @@ dist .LAST_PACKAGE .jsii -*.snk \ No newline at end of file +*.snk + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/aws-apigateway/lib/deployment.ts b/packages/@aws-cdk/aws-apigateway/lib/deployment.ts index b4b04159f952b..2e7b45c73533c 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/deployment.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/deployment.ts @@ -65,8 +65,8 @@ export class Deployment extends cdk.Construct implements cdk.IDependable { private readonly resource: LatestDeploymentResource; - constructor(parent: cdk.Construct, id: string, props: DeploymentProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: DeploymentProps) { + super(scope, id); this.resource = new LatestDeploymentResource(this, 'Resource', { description: props.description, @@ -109,8 +109,8 @@ class LatestDeploymentResource extends CfnDeployment { private lazyLogicalId?: string; private hashComponents = new Array(); - constructor(parent: cdk.Construct, id: string, props: CfnDeploymentProps) { - super(parent, id, props); + constructor(scope: cdk.Construct, id: string, props: CfnDeploymentProps) { + super(scope, id, props); // from this point, don't allow accessing logical ID before synthesis this.lazyLogicalIdRequired = true; @@ -159,7 +159,7 @@ class LatestDeploymentResource extends CfnDeployment { public addToLogicalId(data: unknown) { // if the construct is locked, it means we are already synthesizing and then // we can't modify the hash because we might have already calculated it. - if (this.locked) { + if (this.node.locked) { throw new Error('Cannot modify the logical ID when the construct is locked'); } diff --git a/packages/@aws-cdk/aws-apigateway/lib/lambda-api.ts b/packages/@aws-cdk/aws-apigateway/lib/lambda-api.ts index bf2488a3f2531..baeb6ec451579 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/lambda-api.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/lambda-api.ts @@ -40,12 +40,12 @@ export interface LambdaRestApiProps { * add resources and methods to the API. */ export class LambdaRestApi extends RestApi { - constructor(parent: cdk.Construct, id: string, props: LambdaRestApiProps) { + constructor(scope: cdk.Construct, id: string, props: LambdaRestApiProps) { if (props.options && props.options.defaultIntegration) { throw new Error(`Cannot specify "options.defaultIntegration" since Lambda integration is automatically defined`); } - super(parent, id, { + super(scope, id, { defaultIntegration: new LambdaIntegration(props.handler), ...props.options }); diff --git a/packages/@aws-cdk/aws-apigateway/lib/method.ts b/packages/@aws-cdk/aws-apigateway/lib/method.ts index 711abf00c2d56..08dc1841ee4ff 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/method.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/method.ts @@ -70,8 +70,8 @@ export class Method extends cdk.Construct { public readonly resource: IRestApiResource; public readonly restApi: RestApi; - constructor(parent: cdk.Construct, id: string, props: MethodProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: MethodProps) { + super(scope, id); this.resource = props.resource; this.restApi = props.resource.resourceApi; @@ -118,7 +118,7 @@ export class Method extends cdk.Construct { public get methodArn(): string { if (!this.restApi.deploymentStage) { throw new Error( - `Unable to determine ARN for method "${this.id}" since there is no stage associated with this API.\n` + + `Unable to determine ARN for method "${this.node.id}" since there is no stage associated with this API.\n` + 'Either use the `deploy` prop or explicitly assign `deploymentStage` on the RestApi'); } diff --git a/packages/@aws-cdk/aws-apigateway/lib/resource.ts b/packages/@aws-cdk/aws-apigateway/lib/resource.ts index 9928bb5087526..18280598ffaee 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/resource.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/resource.ts @@ -4,7 +4,7 @@ import { Integration } from './integration'; import { Method, MethodOptions } from './method'; import { RestApi } from './restapi'; -export interface IRestApiResource { +export interface IRestApiResource extends cdk.IConstruct { /** * The rest API that this resource is part of. * @@ -96,8 +96,8 @@ export class Resource extends cdk.Construct implements IRestApiResource { public readonly defaultIntegration?: Integration; public readonly defaultMethodOptions?: MethodOptions; - constructor(parent: cdk.Construct, id: string, props: ResourceProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: ResourceProps) { + super(scope, id); validateResourcePathPart(props.pathPart); @@ -173,8 +173,8 @@ export class ProxyResource extends Resource { private readonly parentResource: IRestApiResource; - constructor(parent: cdk.Construct, id: string, props: ProxyResourceProps) { - super(parent, id, { + constructor(scope: cdk.Construct, id: string, props: ProxyResourceProps) { + super(scope, id, { parent: props.parent, pathPart: '{proxy+}', defaultIntegration: props.defaultIntegration, diff --git a/packages/@aws-cdk/aws-apigateway/lib/restapi-ref.ts b/packages/@aws-cdk/aws-apigateway/lib/restapi-ref.ts deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts index 35304e1b88766..b4cdda1805f1a 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts @@ -14,7 +14,7 @@ export interface RestApiImportProps { restApiId: string; } -export interface IRestApi { +export interface IRestApi extends cdk.IConstruct { /** * The ID of this API Gateway RestApi. */ @@ -161,8 +161,8 @@ export class RestApi extends cdk.Construct implements cdk.IDependable, IRestApi * @param id Construct ID * @param props Imported rest API properties */ - public static import(parent: cdk.Construct, id: string, props: RestApiImportProps): IRestApi { - return new ImportedRestApi(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: RestApiImportProps): IRestApi { + return new ImportedRestApi(scope, id, props); } /** @@ -201,8 +201,8 @@ export class RestApi extends cdk.Construct implements cdk.IDependable, IRestApi private readonly methods = new Array(); - constructor(parent: cdk.Construct, id: string, props: RestApiProps = { }) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: RestApiProps = { }) { + super(scope, id); const resource = new CfnRestApi(this, 'Resource', { name: props.restApiName || id, @@ -236,6 +236,7 @@ export class RestApi extends cdk.Construct implements cdk.IDependable, IRestApi // configure the "root" resource this.root = { + node: this.node, addResource: (pathPart: string, options?: ResourceOptions) => { return new Resource(this, pathPart, { parent: this.root, pathPart, ...options }); }, @@ -409,8 +410,8 @@ export class RestApiUrl extends cdk.CloudFormationToken { } class ImportedRestApi extends cdk.Construct implements IRestApi { public restApiId: string; - constructor(parent: cdk.Construct, id: string, private readonly props: RestApiImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: RestApiImportProps) { + super(scope, id); this.restApiId = props.restApiId; } diff --git a/packages/@aws-cdk/aws-apigateway/lib/stage.ts b/packages/@aws-cdk/aws-apigateway/lib/stage.ts index 7f6970772e3e7..4ed4ab4dab2e4 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/stage.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/stage.ts @@ -132,8 +132,8 @@ export class Stage extends cdk.Construct implements cdk.IDependable { private readonly restApi: IRestApi; - constructor(parent: cdk.Construct, id: string, props: StageProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: StageProps) { + super(scope, id); const methodSettings = this.renderMethodSettings(props); diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.books.ts b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.books.ts index 63868c142da91..783459ebb6009 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.books.ts +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.books.ts @@ -3,8 +3,8 @@ import cdk = require('@aws-cdk/cdk'); import apigw = require('../lib'); class BookStack extends cdk.Stack { - constructor(parent: cdk.App, name: string) { - super(parent, name); + constructor(scope: cdk.App, id: string) { + super(scope, id); const booksHandler = new apigw.LambdaIntegration(new lambda.Function(this, 'BooksHandler', { runtime: lambda.Runtime.NodeJS610, diff --git a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.ts b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.ts index a492d0a2fb9f9..d81e9ac3ccea1 100644 --- a/packages/@aws-cdk/aws-apigateway/test/integ.restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/test/integ.restapi.ts @@ -3,8 +3,8 @@ import cdk = require('@aws-cdk/cdk'); import apigateway = require('../lib'); class Test extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); const api = new apigateway.RestApi(this, 'my-api', { retainDeployments: true, diff --git a/packages/@aws-cdk/aws-apigateway/test/test.deployment.ts b/packages/@aws-cdk/aws-apigateway/test/test.deployment.ts index 063e9590e2920..f9b927af1bd2a 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.deployment.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.deployment.ts @@ -152,7 +152,7 @@ export = { test.done(); function synthesize() { - stack.validateTree(); + stack.node.validateTree(); return stack.toCloudFormation(); } }, diff --git a/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts b/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts index b6531ae26f0b2..a0917ec673025 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts @@ -386,7 +386,7 @@ export = { const exported = api.export(); // THEN - stack.validateTree(); + stack.node.validateTree(); test.deepEqual(stack.toCloudFormation().Outputs.MyRestApiRestApiIdB93C5C2D, { Value: { Ref: 'MyRestApi2D1F47A9' }, Export: { Name: 'MyRestApiRestApiIdB93C5C2D' } diff --git a/packages/@aws-cdk/aws-applicationautoscaling/lib/base-scalable-attribute.ts b/packages/@aws-cdk/aws-applicationautoscaling/lib/base-scalable-attribute.ts index 94aa6e8764cd2..446cae58f42b5 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/lib/base-scalable-attribute.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/lib/base-scalable-attribute.ts @@ -46,8 +46,8 @@ export interface BaseScalableAttributeProps extends EnableScalingProps { export abstract class BaseScalableAttribute extends cdk.Construct { private target: ScalableTarget; - public constructor(parent: cdk.Construct, id: string, protected readonly props: BaseScalableAttributeProps) { - super(parent, id); + public constructor(scope: cdk.Construct, id: string, protected readonly props: BaseScalableAttributeProps) { + super(scope, id); this.target = new ScalableTarget(this, 'Target', { serviceNamespace: this.props.serviceNamespace, diff --git a/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts b/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts index 1a0fbac75c00a..eaedba2e01fbd 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/lib/scalable-target.ts @@ -76,8 +76,8 @@ export class ScalableTarget extends cdk.Construct { private readonly actions = new Array(); - constructor(parent: cdk.Construct, id: string, props: ScalableTargetProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: ScalableTargetProps) { + super(scope, id); if (props.maxCapacity < 0) { throw new RangeError(`maxCapacity cannot be negative, got: ${props.maxCapacity}`); diff --git a/packages/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-action.ts b/packages/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-action.ts index 917a71ab98197..c825577ab21d3 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-action.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-action.ts @@ -80,11 +80,11 @@ export class StepScalingAction extends cdk.Construct implements cloudwatch.IAlar private readonly adjustments = new Array(); - constructor(parent: cdk.Construct, id: string, props: StepScalingActionProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: StepScalingActionProps) { + super(scope, id); const resource = new CfnScalingPolicy(this, 'Resource', { - policyName: props.policyName || this.uniqueId, + policyName: props.policyName || this.node.uniqueId, policyType: 'StepScaling', stepScalingPolicyConfiguration: { adjustmentType: props.adjustmentType, diff --git a/packages/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-policy.ts b/packages/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-policy.ts index 63a99dc6ae0c9..1ee9f9324732a 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-policy.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/lib/step-scaling-policy.ts @@ -68,8 +68,8 @@ export class StepScalingPolicy extends cdk.Construct { public readonly upperAlarm?: cloudwatch.Alarm; public readonly upperAction?: StepScalingAction; - constructor(parent: cdk.Construct, id: string, props: StepScalingPolicyProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: StepScalingPolicyProps) { + super(scope, id); if (props.scalingSteps.length < 2) { throw new Error('You must supply at least 2 intervals for autoscaling'); diff --git a/packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts b/packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts index 4747e1bb0aaec..59d10805f3956 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts @@ -104,7 +104,7 @@ export class TargetTrackingScalingPolicy extends cdk.Construct { */ public readonly scalingPolicyArn: string; - constructor(parent: cdk.Construct, id: string, props: TargetTrackingScalingPolicyProps) { + constructor(scope: cdk.Construct, id: string, props: TargetTrackingScalingPolicyProps) { if ((props.customMetric === undefined) === (props.predefinedMetric === undefined)) { throw new Error(`Exactly one of 'customMetric' or 'predefinedMetric' must be specified.`); } @@ -116,10 +116,10 @@ export class TargetTrackingScalingPolicy extends cdk.Construct { throw new RangeError(`scaleOutCooldown cannot be negative, got: ${props.scaleOutCooldownSec}`); } - super(parent, id); + super(scope, id); const resource = new CfnScalingPolicy(this, 'Resource', { - policyName: props.policyName || this.uniqueId, + policyName: props.policyName || this.node.uniqueId, policyType: 'TargetTrackingScaling', scalingTargetId: props.scalingTarget.scalableTargetId, targetTrackingScalingPolicyConfiguration: { diff --git a/packages/@aws-cdk/aws-applicationautoscaling/test/util.ts b/packages/@aws-cdk/aws-applicationautoscaling/test/util.ts index c228c9ba9abb9..9b6a20a960d54 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/test/util.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/test/util.ts @@ -4,8 +4,8 @@ import fc = require('fast-check'); import appscaling = require('../lib'); import { ServiceNamespace } from '../lib'; -export function createScalableTarget(parent: cdk.Construct) { - return new appscaling.ScalableTarget(parent, 'Target', { +export function createScalableTarget(scope: cdk.Construct) { + return new appscaling.ScalableTarget(scope, 'Target', { serviceNamespace: ServiceNamespace.DynamoDb, scalableDimension: 'test:TestCount', resourceId: 'test:this/test', diff --git a/packages/@aws-cdk/aws-appstream/.npmignore b/packages/@aws-cdk/aws-appstream/.npmignore index 0ed32f4a4a755..2895a406c8e61 100644 --- a/packages/@aws-cdk/aws-appstream/.npmignore +++ b/packages/@aws-cdk/aws-appstream/.npmignore @@ -15,3 +15,7 @@ dist .LAST_BUILD .LAST_PACKAGE .jsii + + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts b/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts index e1b926d6d240b..19f50f187bfed 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts @@ -196,8 +196,8 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup private readonly targetGroupArns: string[] = []; private albTargetGroup?: elbv2.ApplicationTargetGroup; - constructor(parent: cdk.Construct, name: string, props: AutoScalingGroupProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: AutoScalingGroupProps) { + super(scope, id); if (props.cooldownSeconds !== undefined && props.cooldownSeconds < 0) { throw new RangeError(`cooldownSeconds cannot be negative, got: ${props.cooldownSeconds}`); @@ -210,7 +210,7 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup this.connections = new ec2.Connections({ securityGroups: [this.securityGroup] }); this.securityGroups.push(this.securityGroup); this.tags = new TagManager(this, {initialTags: props.tags}); - this.tags.setTag(NAME_TAG, this.path, { overwrite: false }); + this.tags.setTag(NAME_TAG, this.node.path, { overwrite: false }); this.role = new iam.Role(this, 'InstanceRole', { assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com') diff --git a/packages/@aws-cdk/aws-autoscaling/lib/lifecycle-hook.ts b/packages/@aws-cdk/aws-autoscaling/lib/lifecycle-hook.ts index 46f7cb018b1c6..4192f32636ca5 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/lifecycle-hook.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/lifecycle-hook.ts @@ -76,8 +76,8 @@ export class LifecycleHook extends cdk.Construct implements api.ILifecycleHook { */ public readonly lifecycleHookName: string; - constructor(parent: cdk.Construct, id: string, props: LifecycleHookProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: LifecycleHookProps) { + super(scope, id); this.role = props.role || new iam.Role(this, 'Role', { assumedBy: new iam.ServicePrincipal('autoscaling.amazonaws.com') diff --git a/packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts b/packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts index d6ead67ad2023..4f04b79969055 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts @@ -82,8 +82,8 @@ const CRON_EXPRESSION = new RegExp('^' + [CRON_PART, CRON_PART, CRON_PART, CRON_ * Define a scheduled scaling action */ export class ScheduledAction extends cdk.Construct { - constructor(parent: cdk.Construct, id: string, props: ScheduledActionProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: ScheduledActionProps) { + super(scope, id); if (!CRON_EXPRESSION.exec(props.schedule)) { throw new Error(`Input to ScheduledAction should be a cron expression, got: ${props.schedule}`); diff --git a/packages/@aws-cdk/aws-autoscaling/lib/step-scaling-action.ts b/packages/@aws-cdk/aws-autoscaling/lib/step-scaling-action.ts index 6c9f397f7f8ed..158a08b0fb1be 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/step-scaling-action.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/step-scaling-action.ts @@ -73,8 +73,8 @@ export class StepScalingAction extends cdk.Construct implements cloudwatch.IAlar private readonly adjustments = new Array(); - constructor(parent: cdk.Construct, id: string, props: StepScalingActionProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: StepScalingActionProps) { + super(scope, id); const resource = new CfnScalingPolicy(this, 'Resource', { policyType: 'StepScaling', diff --git a/packages/@aws-cdk/aws-autoscaling/lib/step-scaling-policy.ts b/packages/@aws-cdk/aws-autoscaling/lib/step-scaling-policy.ts index 12c0f7b77b853..063212910493a 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/step-scaling-policy.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/step-scaling-policy.ts @@ -69,8 +69,8 @@ export class StepScalingPolicy extends cdk.Construct { public readonly upperAlarm?: cloudwatch.Alarm; public readonly upperAction?: StepScalingAction; - constructor(parent: cdk.Construct, id: string, props: StepScalingPolicyProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: StepScalingPolicyProps) { + super(scope, id); if (props.scalingSteps.length < 2) { throw new Error('You must supply at least 2 intervals for autoscaling'); diff --git a/packages/@aws-cdk/aws-autoscaling/lib/target-tracking-scaling-policy.ts b/packages/@aws-cdk/aws-autoscaling/lib/target-tracking-scaling-policy.ts index 591cada43800d..13b454e4b2b4b 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/target-tracking-scaling-policy.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/target-tracking-scaling-policy.ts @@ -109,7 +109,7 @@ export class TargetTrackingScalingPolicy extends cdk.Construct implements cdk.ID */ private resource: CfnScalingPolicy; - constructor(parent: cdk.Construct, id: string, props: TargetTrackingScalingPolicyProps) { + constructor(scope: cdk.Construct, id: string, props: TargetTrackingScalingPolicyProps) { if ((props.customMetric === undefined) === (props.predefinedMetric === undefined)) { throw new Error(`Exactly one of 'customMetric' or 'predefinedMetric' must be specified.`); } @@ -126,7 +126,7 @@ export class TargetTrackingScalingPolicy extends cdk.Construct implements cdk.ID throw new Error('When tracking the ALBRequestCountPerTarget metric, the ALB identifier must be supplied in resourceLabel'); } - super(parent, id); + super(scope, id); this.resource = new CfnScalingPolicy(this, 'Resource', { policyType: 'TargetTrackingScaling', diff --git a/packages/@aws-cdk/aws-autoscaling/test/test.scaling.ts b/packages/@aws-cdk/aws-autoscaling/test/test.scaling.ts index ac2c3e5bddde3..3128ca3966a13 100644 --- a/packages/@aws-cdk/aws-autoscaling/test/test.scaling.ts +++ b/packages/@aws-cdk/aws-autoscaling/test/test.scaling.ts @@ -227,8 +227,8 @@ class ASGFixture extends cdk.Construct { public readonly vpc: ec2.VpcNetwork; public readonly asg: autoscaling.AutoScalingGroup; - constructor(parent: cdk.Construct, id: string) { - super(parent, id); + constructor(scope: cdk.Construct, id: string) { + super(scope, id); this.vpc = new ec2.VpcNetwork(this, 'VPC'); this.asg = new autoscaling.AutoScalingGroup(this, 'ASG', { diff --git a/packages/@aws-cdk/aws-autoscaling/test/test.scheduled-action.ts b/packages/@aws-cdk/aws-autoscaling/test/test.scheduled-action.ts index 282a94625ab7f..8d7433e33a866 100644 --- a/packages/@aws-cdk/aws-autoscaling/test/test.scheduled-action.ts +++ b/packages/@aws-cdk/aws-autoscaling/test/test.scheduled-action.ts @@ -103,9 +103,9 @@ export = { }, }; -function makeAutoScalingGroup(parent: cdk.Construct) { - const vpc = new ec2.VpcNetwork(parent, 'VPC'); - return new autoscaling.AutoScalingGroup(parent, 'ASG', { +function makeAutoScalingGroup(scope: cdk.Construct) { + const vpc = new ec2.VpcNetwork(scope, 'VPC'); + return new autoscaling.AutoScalingGroup(scope, 'ASG', { vpc, instanceType: new ec2.InstanceType('t2.micro'), machineImage: new ec2.AmazonLinuxImage(), diff --git a/packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts b/packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts index 32acc34ae7cd0..3df89dd8a4bf2 100644 --- a/packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts +++ b/packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts @@ -1,8 +1,8 @@ -import { Construct, Output } from '@aws-cdk/cdk'; +import { Construct, IConstruct, Output } from '@aws-cdk/cdk'; import { CfnCertificate } from './certificatemanager.generated'; import { apexDomain } from './util'; -export interface ICertificate { +export interface ICertificate extends IConstruct { /** * The certificate's ARN */ @@ -73,8 +73,8 @@ export class Certificate extends Construct implements ICertificate { /** * Import a certificate */ - public static import(parent: Construct, name: string, props: CertificateImportProps): ICertificate { - return new ImportedCertificate(parent, name, props); + public static import(scope: Construct, id: string, props: CertificateImportProps): ICertificate { + return new ImportedCertificate(scope, id, props); } /** @@ -82,8 +82,8 @@ export class Certificate extends Construct implements ICertificate { */ public readonly certificateArn: string; - constructor(parent: Construct, name: string, props: CertificateProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: CertificateProps) { + super(scope, id); const allDomainNames = [props.domainName].concat(props.subjectAlternativeNames || []); @@ -125,8 +125,8 @@ export class Certificate extends Construct implements ICertificate { class ImportedCertificate extends Construct implements ICertificate { public readonly certificateArn: string; - constructor(parent: Construct, name: string, private readonly props: CertificateImportProps) { - super(parent, name); + constructor(scope: Construct, id: string, private readonly props: CertificateImportProps) { + super(scope, id); this.certificateArn = props.certificateArn; } diff --git a/packages/@aws-cdk/aws-cloudformation/lib/custom-resource.ts b/packages/@aws-cdk/aws-cloudformation/lib/custom-resource.ts index 656cf77e13387..d204190d659e4 100644 --- a/packages/@aws-cdk/aws-cloudformation/lib/custom-resource.ts +++ b/packages/@aws-cdk/aws-cloudformation/lib/custom-resource.ts @@ -68,12 +68,12 @@ export class CustomResource extends CfnCustomResource { private readonly userProperties?: Properties; - constructor(parent: cdk.Construct, name: string, props: CustomResourceProps) { + constructor(scope: cdk.Construct, id: string, props: CustomResourceProps) { if (!!props.lambdaProvider === !!props.topicProvider) { throw new Error('Exactly one of "lambdaProvider" or "topicProvider" must be set.'); } - super(parent, name, { + super(scope, id, { serviceToken: props.lambdaProvider ? props.lambdaProvider.functionArn : props.topicProvider!.topicArn }); diff --git a/packages/@aws-cdk/aws-cloudformation/lib/pipeline-actions.ts b/packages/@aws-cdk/aws-cloudformation/lib/pipeline-actions.ts index e8e1ee3fcbfe7..f38df0a6c4d22 100644 --- a/packages/@aws-cdk/aws-cloudformation/lib/pipeline-actions.ts +++ b/packages/@aws-cdk/aws-cloudformation/lib/pipeline-actions.ts @@ -57,8 +57,8 @@ export abstract class PipelineCloudFormationAction extends codepipeline.Action { */ public outputArtifact?: codepipeline.Artifact; - constructor(parent: cdk.Construct, id: string, props: PipelineCloudFormationActionProps, configuration?: any) { - super(parent, id, { + constructor(scope: cdk.Construct, id: string, props: PipelineCloudFormationActionProps, configuration?: any) { + super(scope, id, { stage: props.stage, runOrder: props.runOrder, region: props.region, @@ -79,7 +79,7 @@ export abstract class PipelineCloudFormationAction extends codepipeline.Action { if (props.outputFileName) { this.outputArtifact = this.addOutputArtifact(props.outputArtifactName || - (props.stage.name + this.id + 'Artifact')); + (props.stage.name + this.node.id + 'Artifact')); } } } @@ -98,8 +98,8 @@ export interface PipelineExecuteChangeSetActionProps extends PipelineCloudFormat * CodePipeline action to execute a prepared change set. */ export class PipelineExecuteChangeSetAction extends PipelineCloudFormationAction { - constructor(parent: cdk.Construct, id: string, props: PipelineExecuteChangeSetActionProps) { - super(parent, id, props, { + constructor(scope: cdk.Construct, id: string, props: PipelineExecuteChangeSetActionProps) { + super(scope, id, props, { ActionMode: 'CHANGE_SET_EXECUTE', ChangeSetName: props.changeSetName, }); @@ -196,9 +196,9 @@ export interface PipelineCloudFormationDeployActionProps extends PipelineCloudFo export abstract class PipelineCloudFormationDeployAction extends PipelineCloudFormationAction { public readonly role: iam.IRole; - constructor(parent: cdk.Construct, id: string, props: PipelineCloudFormationDeployActionProps, configuration: any) { + constructor(scope: cdk.Construct, id: string, props: PipelineCloudFormationDeployActionProps, configuration: any) { const capabilities = props.adminPermissions && props.capabilities === undefined ? CloudFormationCapabilities.NamedIAM : props.capabilities; - super(parent, id, props, { + super(scope, id, props, { ...configuration, // None evaluates to empty string which is falsey and results in undefined Capabilities: (capabilities && capabilities.toString()) || undefined, @@ -253,8 +253,8 @@ export interface PipelineCreateReplaceChangeSetActionProps extends PipelineCloud * If the change set exists, AWS CloudFormation deletes it, and then creates a new one. */ export class PipelineCreateReplaceChangeSetAction extends PipelineCloudFormationDeployAction { - constructor(parent: cdk.Construct, id: string, props: PipelineCreateReplaceChangeSetActionProps) { - super(parent, id, props, { + constructor(scope: cdk.Construct, id: string, props: PipelineCreateReplaceChangeSetActionProps) { + super(scope, id, props, { ActionMode: 'CHANGE_SET_REPLACE', ChangeSetName: props.changeSetName, TemplatePath: props.templatePath.location, @@ -309,8 +309,8 @@ export interface PipelineCreateUpdateStackActionProps extends PipelineCloudForma * troubleshooting them. You would typically choose this mode for testing. */ export class PipelineCreateUpdateStackAction extends PipelineCloudFormationDeployAction { - constructor(parent: cdk.Construct, id: string, props: PipelineCreateUpdateStackActionProps) { - super(parent, id, props, { + constructor(scope: cdk.Construct, id: string, props: PipelineCreateUpdateStackActionProps) { + super(scope, id, props, { ActionMode: props.replaceOnFailure ? 'REPLACE_ON_FAILURE' : 'CREATE_UPDATE', TemplatePath: props.templatePath.location }); @@ -338,8 +338,8 @@ export interface PipelineDeleteStackActionProps extends PipelineCloudFormationDe * without deleting a stack. */ export class PipelineDeleteStackAction extends PipelineCloudFormationDeployAction { - constructor(parent: cdk.Construct, id: string, props: PipelineDeleteStackActionProps) { - super(parent, id, props, { + constructor(scope: cdk.Construct, id: string, props: PipelineDeleteStackActionProps) { + super(scope, id, props, { ActionMode: 'DELETE_ONLY', }); SingletonPolicy.forRole(props.stage.pipeline.role).grantDeleteStack(props); @@ -394,7 +394,7 @@ class SingletonPolicy extends cdk.Construct { * @returns the SingletonPolicy for this role. */ public static forRole(role: iam.Role): SingletonPolicy { - const found = role.tryFindChild(SingletonPolicy.UUID); + const found = role.node.tryFindChild(SingletonPolicy.UUID); return (found as SingletonPolicy) || new SingletonPolicy(role); } diff --git a/packages/@aws-cdk/aws-cloudformation/test/integ.trivial-lambda-resource.ts b/packages/@aws-cdk/aws-cloudformation/test/integ.trivial-lambda-resource.ts index 3055be69a307d..bb4278fe12620 100644 --- a/packages/@aws-cdk/aws-cloudformation/test/integ.trivial-lambda-resource.ts +++ b/packages/@aws-cdk/aws-cloudformation/test/integ.trivial-lambda-resource.ts @@ -18,8 +18,8 @@ interface DemoResourceProps { class DemoResource extends cdk.Construct { public readonly response: string; - constructor(parent: cdk.Construct, name: string, props: DemoResourceProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: DemoResourceProps) { + super(scope, id); const resource = new CustomResource(this, 'Resource', { lambdaProvider: new lambda.SingletonFunction(this, 'Singleton', { @@ -41,8 +41,8 @@ class DemoResource extends cdk.Construct { * 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, id: string, props?: cdk.StackProps) { + super(scope, id, props); const resource = new DemoResource(this, 'DemoResource', { message: 'CustomResource says hello', diff --git a/packages/@aws-cdk/aws-cloudformation/test/test.pipeline-actions.ts b/packages/@aws-cdk/aws-cloudformation/test/test.pipeline-actions.ts index 37da55382672f..001799de59a13 100644 --- a/packages/@aws-cdk/aws-cloudformation/test/test.pipeline-actions.ts +++ b/packages/@aws-cdk/aws-cloudformation/test/test.pipeline-actions.ts @@ -284,6 +284,10 @@ class PipelineDouble implements cpapi.IPipeline { public readonly pipelineArn: string; public readonly role: iam.Role; + public get node(): cdk.ConstructNode { + throw new Error('this is not a real construct'); + } + constructor({ pipelineName, role }: { pipelineName?: string, role: iam.Role }) { this.pipelineName = pipelineName || 'TestPipeline'; this.pipelineArn = cdk.ArnUtils.fromComponents({ service: 'codepipeline', resource: 'pipeline', resourceName: this.pipelineName }); @@ -314,6 +318,10 @@ class StageDouble implements cpapi.IStage, cpapi.IInternalStage { public readonly actions = new Array(); + public get node(): cdk.ConstructNode { + throw new Error('this is not a real construct'); + } + constructor({ name, pipeline }: { name?: string, pipeline: cpapi.IPipeline }) { this.name = name || 'TestStage'; this.pipeline = pipeline; @@ -335,8 +343,8 @@ class StageDouble implements cpapi.IStage, cpapi.IInternalStage { class RoleDouble extends iam.Role { public readonly statements = new Array(); - constructor(parent: cdk.Construct, id: string, props: iam.RoleProps = { assumedBy: new iam.ServicePrincipal('test') }) { - super(parent, id, props); + constructor(scope: cdk.Construct, id: string, props: iam.RoleProps = { assumedBy: new iam.ServicePrincipal('test') }) { + super(scope, id, props); } public addToPolicy(statement: iam.PolicyStatement) { diff --git a/packages/@aws-cdk/aws-cloudformation/test/test.resource.ts b/packages/@aws-cdk/aws-cloudformation/test/test.resource.ts index 668699634cde0..b546732e358bd 100644 --- a/packages/@aws-cdk/aws-cloudformation/test/test.resource.ts +++ b/packages/@aws-cdk/aws-cloudformation/test/test.resource.ts @@ -141,8 +141,8 @@ export = { }; class TestCustomResource extends cdk.Construct { - constructor(parent: cdk.Construct, name: string) { - super(parent, name); + constructor(scope: cdk.Construct, id: string) { + super(scope, id); const singletonLambda = new lambda.SingletonFunction(this, 'Lambda', { uuid: 'TestCustomResourceProvider', diff --git a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts index cd75a92c2e7a0..40a01ad6b653f 100644 --- a/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts +++ b/packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts @@ -523,8 +523,8 @@ export class CloudFrontWebDistribution extends cdk.Construct implements route53. "vip": [SecurityPolicyProtocol.SSLv3, SecurityPolicyProtocol.TLSv1], }; - constructor(parent: cdk.Construct, name: string, props: CloudFrontWebDistributionProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: CloudFrontWebDistributionProps) { + super(scope, id); const distributionConfig: CfnDistribution.DistributionConfigProperty = { comment: props.comment, diff --git a/packages/@aws-cdk/aws-cloudtrail/lib/index.ts b/packages/@aws-cdk/aws-cloudtrail/lib/index.ts index 07d9f8dcd5d8f..fc8f08883cd13 100644 --- a/packages/@aws-cdk/aws-cloudtrail/lib/index.ts +++ b/packages/@aws-cdk/aws-cloudtrail/lib/index.ts @@ -126,8 +126,8 @@ export class CloudTrail extends cdk.Construct { private readonly cloudWatchLogsGroupArn?: string; private eventSelectors: EventSelector[] = []; - constructor(parent: cdk.Construct, name: string, props: CloudTrailProps = {}) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: CloudTrailProps = {}) { + super(scope, id); const s3bucket = new s3.Bucket(this, 'S3', {encryption: s3.BucketEncryption.Unencrypted}); const cloudTrailPrincipal = "cloudtrail.amazonaws.com"; @@ -182,7 +182,7 @@ export class CloudTrail extends cdk.Construct { eventSelectors: this.eventSelectors }); this.cloudTrailArn = trail.trailArn; - const s3BucketPolicy = s3bucket.findChild("Policy").findChild("Resource") as s3.CfnBucketPolicy; + const s3BucketPolicy = s3bucket.node.findChild("Policy").node.findChild("Resource") as s3.CfnBucketPolicy; trail.addDependency(s3BucketPolicy); } diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts b/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts index 6c05caad19bbc..078671e301b4e 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts @@ -140,8 +140,8 @@ export class Alarm extends Construct { */ private readonly annotation: HorizontalAnnotation; - constructor(parent: Construct, name: string, props: AlarmProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: AlarmProps) { + super(scope, id); const comparisonOperator = props.comparisonOperator || ComparisonOperator.GreaterThanOrEqualToThreshold; diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts b/packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts index ee690a8129a27..0f08dde461215 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/dashboard.ts @@ -19,8 +19,8 @@ export class Dashboard extends Construct { private readonly rows: IWidget[] = []; private readonly dashboard: CfnDashboard; - constructor(parent: Construct, name: string, props?: DashboardProps) { - super(parent, name); + constructor(scope: Construct, id: string, props?: DashboardProps) { + super(scope, id); // WORKAROUND -- Dashboard cannot be updated if the DashboardName is missing. // This is a bug in CloudFormation, but we don't want CDK users to have a bad diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/metric.ts b/packages/@aws-cdk/aws-cloudwatch/lib/metric.ts index 6d09191c0a854..d3a5bc9b5d4e7 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/metric.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/metric.ts @@ -148,8 +148,8 @@ export class Metric { * Combines both properties that may adjust the metric (aggregation) as well * as alarm properties. */ - public newAlarm(parent: cdk.Construct, name: string, props: NewAlarmProps): Alarm { - return new Alarm(parent, name, { + public newAlarm(scope: cdk.Construct, id: string, props: NewAlarmProps): Alarm { + return new Alarm(scope, id, { metric: this.with({ statistic: props.statistic, periodSec: props.periodSec, diff --git a/packages/@aws-cdk/aws-codebuild/lib/pipeline-actions.ts b/packages/@aws-cdk/aws-codebuild/lib/pipeline-actions.ts index 721e402147dc0..718553416a290 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/pipeline-actions.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/pipeline-actions.ts @@ -57,11 +57,11 @@ export interface PipelineBuildActionProps extends CommonPipelineBuildActionProps * CodePipeline build Action that uses AWS CodeBuild. */ export class PipelineBuildAction extends codepipeline.BuildAction { - constructor(parent: cdk.Construct, name: string, props: PipelineBuildActionProps) { + constructor(scope: cdk.Construct, id: string, props: PipelineBuildActionProps) { // This happened when ProjectName was accidentally set to the project's ARN: // https://qiita.com/ikeisuke/items/2fbc0b80b9bbd981b41f - super(parent, name, { + super(scope, id, { provider: 'CodeBuild', artifactBounds: { minInputs: 1, maxInputs: 5, minOutputs: 0, maxOutputs: 5 }, configuration: { @@ -143,8 +143,8 @@ export interface PipelineTestActionProps extends CommonPipelineTestActionProps, } export class PipelineTestAction extends codepipeline.TestAction { - constructor(parent: cdk.Construct, name: string, props: PipelineTestActionProps) { - super(parent, name, { + constructor(scope: cdk.Construct, id: string, props: PipelineTestActionProps) { + super(scope, id, { provider: 'CodeBuild', artifactBounds: { minInputs: 1, maxInputs: 5, minOutputs: 0, maxOutputs: 5 }, configuration: { diff --git a/packages/@aws-cdk/aws-codebuild/lib/pipeline-project.ts b/packages/@aws-cdk/aws-codebuild/lib/pipeline-project.ts index cce3cefd46563..7d6e4e4193e09 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/pipeline-project.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/pipeline-project.ts @@ -11,8 +11,8 @@ export interface PipelineProjectProps extends CommonProjectProps { * A convenience class for CodeBuild Projects that are used in CodePipeline. */ export class PipelineProject extends Project { - constructor(parent: cdk.Construct, id: string, props?: PipelineProjectProps) { - super(parent, id, { + constructor(scope: cdk.Construct, id: string, props?: PipelineProjectProps) { + super(scope, id, { source: new CodePipelineSource(), artifacts: new CodePipelineBuildArtifacts(), ...props diff --git a/packages/@aws-cdk/aws-codebuild/lib/project.ts b/packages/@aws-cdk/aws-codebuild/lib/project.ts index a3021c83ae132..42defa04578b7 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/project.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/project.ts @@ -20,7 +20,7 @@ const CODEPIPELINE_TYPE = 'CODEPIPELINE'; const S3_BUCKET_ENV = 'SCRIPT_S3_BUCKET'; const S3_KEY_ENV = 'SCRIPT_S3_KEY'; -export interface IProject extends events.IEventRuleTarget { +export interface IProject extends cdk.IConstruct, events.IEventRuleTarget { /** The ARN of this Project. */ readonly projectArn: string; @@ -421,7 +421,7 @@ export abstract class ProjectBase extends cdk.Construct implements IProject { } return { - id: this.id, + id: this.node.id, arn: this.projectArn, roleArn: this.eventsRole.roleArn, }; @@ -433,8 +433,8 @@ class ImportedProject extends ProjectBase { public readonly projectName: string; public readonly role?: iam.Role = undefined; - constructor(parent: cdk.Construct, name: string, private readonly props: ProjectImportProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, private readonly props: ProjectImportProps) { + super(scope, id); this.projectArn = cdk.ArnUtils.fromComponents({ service: 'codebuild', @@ -592,8 +592,8 @@ export class Project extends ProjectBase { * @param props the properties of the referenced Project * @returns a reference to the existing Project */ - public static import(parent: cdk.Construct, name: string, props: ProjectImportProps): IProject { - return new ImportedProject(parent, name, props); + public static import(scope: cdk.Construct, id: string, props: ProjectImportProps): IProject { + return new ImportedProject(scope, id, props); } /** @@ -616,8 +616,8 @@ export class Project extends ProjectBase { private readonly _secondarySources: BuildSource[]; private readonly _secondaryArtifacts: BuildArtifacts[]; - constructor(parent: cdk.Construct, name: string, props: ProjectProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: ProjectProps) { + super(scope, id); if (props.buildScriptAssetEntrypoint && !props.buildScriptAsset) { throw new Error('To use buildScriptAssetEntrypoint, supply buildScriptAsset as well.'); @@ -1007,8 +1007,8 @@ export class LinuxBuildImage implements IBuildImage { /** * Uses an Docker image asset as a Linux build image. */ - public static fromAsset(parent: cdk.Construct, id: string, props: DockerImageAssetProps): LinuxBuildImage { - const asset = new DockerImageAsset(parent, id, props); + public static fromAsset(scope: cdk.Construct, id: string, props: DockerImageAssetProps): LinuxBuildImage { + const asset = new DockerImageAsset(scope, id, props); const image = new LinuxBuildImage(asset.imageUri); // allow this codebuild to pull this image (CodeBuild doesn't use a role, so @@ -1100,8 +1100,8 @@ export class WindowsBuildImage implements IBuildImage { /** * Uses an Docker image asset as a Windows build image. */ - public static fromAsset(parent: cdk.Construct, id: string, props: DockerImageAssetProps): WindowsBuildImage { - const asset = new DockerImageAsset(parent, id, props); + public static fromAsset(scope: cdk.Construct, id: string, props: DockerImageAssetProps): WindowsBuildImage { + const asset = new DockerImageAsset(scope, id, props); const image = new WindowsBuildImage(asset.imageUri); // allow this codebuild to pull this image (CodeBuild doesn't use a role, so diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.defaults.lit.ts b/packages/@aws-cdk/aws-codebuild/test/integ.defaults.lit.ts index f3d0355985489..563213dcd7003 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.defaults.lit.ts +++ b/packages/@aws-cdk/aws-codebuild/test/integ.defaults.lit.ts @@ -2,8 +2,8 @@ import cdk = require('@aws-cdk/cdk'); import codebuild = require('../lib'); class TestStack extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); /// !show new codebuild.Project(this, 'MyProject', { diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.docker-asset.lit.ts b/packages/@aws-cdk/aws-codebuild/test/integ.docker-asset.lit.ts index 9d7a01b103c7a..ad0f38b10e22e 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.docker-asset.lit.ts +++ b/packages/@aws-cdk/aws-codebuild/test/integ.docker-asset.lit.ts @@ -3,8 +3,8 @@ import path = require('path'); import codebuild = require('../lib'); class TestStack extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); new codebuild.Project(this, 'MyProject', { buildSpec: { diff --git a/packages/@aws-cdk/aws-codebuild/test/integ.ecr.lit.ts b/packages/@aws-cdk/aws-codebuild/test/integ.ecr.lit.ts index d90695607a54e..8d8105bbfb6e3 100644 --- a/packages/@aws-cdk/aws-codebuild/test/integ.ecr.lit.ts +++ b/packages/@aws-cdk/aws-codebuild/test/integ.ecr.lit.ts @@ -3,8 +3,8 @@ import cdk = require('@aws-cdk/cdk'); import codebuild = require('../lib'); class TestStack extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); const ecrRepository = new ecr.Repository(this, 'MyRepo'); diff --git a/packages/@aws-cdk/aws-codecommit/lib/pipeline-action.ts b/packages/@aws-cdk/aws-codecommit/lib/pipeline-action.ts index 0fa65e3699bcd..596a7d7882cad 100644 --- a/packages/@aws-cdk/aws-codecommit/lib/pipeline-action.ts +++ b/packages/@aws-cdk/aws-codecommit/lib/pipeline-action.ts @@ -46,8 +46,8 @@ export interface PipelineSourceActionProps extends CommonPipelineSourceActionPro * CodePipeline Source that is provided by an AWS CodeCommit repository. */ export class PipelineSourceAction extends codepipeline.SourceAction { - constructor(parent: cdk.Construct, name: string, props: PipelineSourceActionProps) { - super(parent, name, { + constructor(scope: cdk.Construct, id: string, props: PipelineSourceActionProps) { + super(scope, id, { stage: props.stage, runOrder: props.runOrder, provider: 'CodeCommit', @@ -60,7 +60,7 @@ export class PipelineSourceAction extends codepipeline.SourceAction { }); if (!props.pollForSourceChanges) { - props.repository.onCommit(props.stage.pipeline.uniqueId + 'EventRule', props.stage.pipeline, props.branch || 'master'); + props.repository.onCommit(props.stage.pipeline.node.uniqueId + 'EventRule', props.stage.pipeline, props.branch || 'master'); } // https://docs.aws.amazon.com/codecommit/latest/userguide/auth-and-access-control-permissions-reference.html#aa-acp diff --git a/packages/@aws-cdk/aws-codecommit/lib/repository.ts b/packages/@aws-cdk/aws-codecommit/lib/repository.ts index b1718363eb60b..086990af2bd25 100644 --- a/packages/@aws-cdk/aws-codecommit/lib/repository.ts +++ b/packages/@aws-cdk/aws-codecommit/lib/repository.ts @@ -4,7 +4,7 @@ import cdk = require('@aws-cdk/cdk'); import { CfnRepository } from './codecommit.generated'; import { CommonPipelineSourceActionProps, PipelineSourceAction } from './pipeline-action'; -export interface IRepository { +export interface IRepository extends cdk.IConstruct { /** The ARN of this Repository. */ readonly repositoryArn: string; @@ -241,8 +241,8 @@ class ImportedRepository extends RepositoryBase { public readonly repositoryArn: string; public readonly repositoryName: string; - constructor(parent: cdk.Construct, name: string, private readonly props: RepositoryImportProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, private readonly props: RepositoryImportProps) { + super(scope, id); this.repositoryArn = cdk.ArnUtils.fromComponents({ service: 'codecommit', @@ -289,20 +289,20 @@ export class Repository extends RepositoryBase { * Import a Repository defined either outside the CDK, or in a different Stack * (exported with the {@link export} method). * - * @param parent the parent Construct for the Repository - * @param name the name of the Repository Construct + * @param scope the parent Construct for the Repository + * @param id the name of the Repository Construct * @param props the properties used to identify the existing Repository * @returns a reference to the existing Repository */ - public static import(parent: cdk.Construct, name: string, props: RepositoryImportProps): IRepository { - return new ImportedRepository(parent, name, props); + public static import(scope: cdk.Construct, id: string, props: RepositoryImportProps): IRepository { + return new ImportedRepository(scope, id, props); } private readonly repository: CfnRepository; private readonly triggers = new Array(); - constructor(parent: cdk.Construct, name: string, props: RepositoryProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: RepositoryProps) { + super(scope, id); this.repository = new CfnRepository(this, 'Resource', { repositoryName: props.repositoryName, @@ -355,7 +355,7 @@ export class Repository extends RepositoryBase { let name = options && options.name; if (!name) { - name = this.path + '/' + arn; + name = this.node.path + '/' + arn; } if (this.triggers.find(prop => prop.name === name)) { diff --git a/packages/@aws-cdk/aws-codedeploy/lib/application.ts b/packages/@aws-cdk/aws-codedeploy/lib/application.ts index d5442ee21f0e1..3c8bfeee3e806 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/application.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/application.ts @@ -11,7 +11,7 @@ import { CfnApplication } from './codedeploy.generated'; * or one defined in a different CDK Stack, * use the {@link #import} method. */ -export interface IServerApplication { +export interface IServerApplication extends cdk.IConstruct { readonly applicationArn: string; readonly applicationName: string; @@ -37,8 +37,8 @@ class ImportedServerApplication extends cdk.Construct implements IServerApplicat public readonly applicationArn: string; public readonly applicationName: string; - constructor(parent: cdk.Construct, id: string, private readonly props: ServerApplicationImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: ServerApplicationImportProps) { + super(scope, id); this.applicationName = props.applicationName; this.applicationArn = applicationName2Arn(this.applicationName); @@ -74,15 +74,15 @@ export class ServerApplication extends cdk.Construct implements IServerApplicati * @param props the properties of the referenced Application * @returns a Construct representing a reference to an existing Application */ - public static import(parent: cdk.Construct, id: string, props: ServerApplicationImportProps): IServerApplication { - return new ImportedServerApplication(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: ServerApplicationImportProps): IServerApplication { + return new ImportedServerApplication(scope, id, props); } public readonly applicationArn: string; public readonly applicationName: string; - constructor(parent: cdk.Construct, id: string, props?: ServerApplicationProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props?: ServerApplicationProps) { + super(scope, id); const resource = new CfnApplication(this, 'Resource', { applicationName: props && props.applicationName, diff --git a/packages/@aws-cdk/aws-codedeploy/lib/deployment-config.ts b/packages/@aws-cdk/aws-codedeploy/lib/deployment-config.ts index c71421e84a2e8..6783ecb4114f8 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/deployment-config.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/deployment-config.ts @@ -32,8 +32,8 @@ class ImportedServerDeploymentConfig extends cdk.Construct implements IServerDep public readonly deploymentConfigName: string; public readonly deploymentConfigArn: string; - constructor(parent: cdk.Construct, id: string, private readonly props: ServerDeploymentConfigImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: ServerDeploymentConfigImportProps) { + super(scope, id); this.deploymentConfigName = props.deploymentConfigName; this.deploymentConfigArn = arnForDeploymentConfigName(this.deploymentConfigName); @@ -105,15 +105,15 @@ export class ServerDeploymentConfig extends cdk.Construct implements IServerDepl * @param props the properties of the referenced custom Deployment Configuration * @returns a Construct representing a reference to an existing custom Deployment Configuration */ - public static import(parent: cdk.Construct, id: string, props: ServerDeploymentConfigImportProps): IServerDeploymentConfig { - return new ImportedServerDeploymentConfig(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: ServerDeploymentConfigImportProps): IServerDeploymentConfig { + return new ImportedServerDeploymentConfig(scope, id, props); } public readonly deploymentConfigName: string; public readonly deploymentConfigArn: string; - constructor(parent: cdk.Construct, id: string, props: ServerDeploymentConfigProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: ServerDeploymentConfigProps) { + super(scope, id); const resource = new CfnDeploymentConfig(this, 'Resource', { deploymentConfigName: props.deploymentConfigName, diff --git a/packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts index 8cd588b07bff6..e24c68cacaebb 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/deployment-group.ts @@ -11,7 +11,7 @@ import { CfnDeploymentGroup } from './codedeploy.generated'; import { IServerDeploymentConfig, ServerDeploymentConfig } from "./deployment-config"; import { CommonPipelineDeployActionProps, PipelineDeployAction } from "./pipeline-action"; -export interface IServerDeploymentGroup { +export interface IServerDeploymentGroup extends cdk.IConstruct { readonly application: IServerApplication; readonly role?: iam.Role; readonly deploymentGroupName: string; @@ -66,8 +66,8 @@ export abstract class ServerDeploymentGroupBase extends cdk.Construct implements public readonly deploymentConfig: IServerDeploymentConfig; public abstract readonly autoScalingGroups?: autoscaling.AutoScalingGroup[]; - constructor(parent: cdk.Construct, id: string, deploymentConfig?: IServerDeploymentConfig) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, deploymentConfig?: IServerDeploymentConfig) { + super(scope, id); this.deploymentConfig = deploymentConfig || ServerDeploymentConfig.OneAtATime; } @@ -99,8 +99,8 @@ class ImportedServerDeploymentGroup extends ServerDeploymentGroupBase { public readonly deploymentGroupArn: string; public readonly autoScalingGroups?: autoscaling.AutoScalingGroup[] = undefined; - constructor(parent: cdk.Construct, id: string, private readonly props: ServerDeploymentGroupImportProps) { - super(parent, id, props.deploymentConfig); + constructor(scope: cdk.Construct, id: string, private readonly props: ServerDeploymentGroupImportProps) { + super(scope, id, props.deploymentConfig); this.application = props.application; this.deploymentGroupName = props.deploymentGroupName; @@ -284,8 +284,8 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase { * @param props the properties of the referenced Deployment Group * @returns a Construct representing a reference to an existing Deployment Group */ - public static import(parent: cdk.Construct, id: string, props: ServerDeploymentGroupImportProps): IServerDeploymentGroup { - return new ImportedServerDeploymentGroup(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: ServerDeploymentGroupImportProps): IServerDeploymentGroup { + return new ImportedServerDeploymentGroup(scope, id, props); } public readonly application: IServerApplication; @@ -298,8 +298,8 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase { private readonly codeDeployBucket: s3.IBucket; private readonly alarms: cloudwatch.Alarm[]; - constructor(parent: cdk.Construct, id: string, props: ServerDeploymentGroupProps = {}) { - super(parent, id, props.deploymentConfig); + constructor(scope: cdk.Construct, id: string, props: ServerDeploymentGroupProps = {}) { + super(scope, id, props.deploymentConfig); this.application = props.application || new ServerApplication(this, 'Application'); diff --git a/packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts b/packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts index 2a840e575385a..8461eb85a6734 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/pipeline-action.ts @@ -29,8 +29,8 @@ export interface PipelineDeployActionProps extends CommonPipelineDeployActionPro } export class PipelineDeployAction extends codepipeline.DeployAction { - constructor(parent: cdk.Construct, id: string, props: PipelineDeployActionProps) { - super(parent, id, { + constructor(scope: cdk.Construct, id: string, props: PipelineDeployActionProps) { + super(scope, id, { stage: props.stage, runOrder: props.runOrder, artifactBounds: { minInputs: 1, maxInputs: 1, minOutputs: 0, maxOutputs: 0 }, diff --git a/packages/@aws-cdk/aws-codepipeline-api/lib/action.ts b/packages/@aws-cdk/aws-codepipeline-api/lib/action.ts index 0f6ef1754787d..81aa0cb18095b 100644 --- a/packages/@aws-cdk/aws-codepipeline-api/lib/action.ts +++ b/packages/@aws-cdk/aws-codepipeline-api/lib/action.ts @@ -72,7 +72,7 @@ export interface IInternalStage { * It extends {@link events.IEventRuleTarget}, * so this interface can be used as a Target for CloudWatch Events. */ -export interface IPipeline extends events.IEventRuleTarget { +export interface IPipeline extends cdk.IConstruct, events.IEventRuleTarget { /** * The name of the Pipeline. */ @@ -83,11 +83,6 @@ export interface IPipeline extends events.IEventRuleTarget { */ readonly pipelineArn: string; - /** - * The unique ID of the Pipeline Construct. - */ - readonly uniqueId: string; - /** * The service Role of the Pipeline. */ @@ -111,7 +106,7 @@ export interface IPipeline extends events.IEventRuleTarget { /** * The abstract interface of a Pipeline Stage that is used by Actions. */ -export interface IStage { +export interface IStage extends cdk.IConstruct { /** * The physical, human-readable name of this Pipeline Stage. */ @@ -226,8 +221,8 @@ export abstract class Action extends cdk.Construct { private readonly artifactBounds: ActionArtifactBounds; private readonly stage: IStage; - constructor(parent: cdk.Construct, id: string, props: ActionProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: ActionProps) { + super(scope, id); validation.validateName('Action', id); @@ -253,7 +248,7 @@ export abstract class Action extends cdk.Construct { } public onStateChange(name: string, target?: events.IEventRuleTarget, options?: events.EventRuleProps) { - const rule = new events.EventRule(this.parent!!, name, options); + const rule = new events.EventRule(this, name, options); rule.addTarget(target); rule.addEventPattern({ detailType: [ 'CodePipeline Stage Execution State Change' ], @@ -261,7 +256,7 @@ export abstract class Action extends cdk.Construct { resources: [ this.stage.pipeline.pipelineArn ], detail: { stage: [ this.stage.name ], - action: [ this.id ], + action: [ this.node.id ], }, }); return rule; @@ -288,8 +283,8 @@ export abstract class Action extends cdk.Construct { } // export class ElasticBeanstalkDeploy extends DeployAction { -// constructor(parent: Stage, name: string, applicationName: string, environmentName: string) { -// super(parent, name, 'ElasticBeanstalk', { minInputs: 1, maxInputs: 1, minOutputs: 0, maxOutputs: 0 }, { +// constructor(scope: Stage, id: string, applicationName: string, environmentName: string) { +// super(scope, id, 'ElasticBeanstalk', { minInputs: 1, maxInputs: 1, minOutputs: 0, maxOutputs: 0 }, { // ApplicationName: applicationName, // EnvironmentName: environmentName // }); @@ -297,8 +292,8 @@ export abstract class Action extends cdk.Construct { // } // export class OpsWorksDeploy extends DeployAction { -// constructor(parent: Stage, name: string, app: string, stack: string, layer?: string) { -// super(parent, name, 'OpsWorks', { minInputs: 1, maxInputs: 1, minOutputs: 0, maxOutputs: 0 }, { +// constructor(scope: Stage, id: string, app: string, stack: string, layer?: string) { +// super(scope, id, 'OpsWorks', { minInputs: 1, maxInputs: 1, minOutputs: 0, maxOutputs: 0 }, { // Stack: stack, // App: app, // Layer: layer, @@ -307,8 +302,8 @@ export abstract class Action extends cdk.Construct { // } // export class ECSDeploy extends DeployAction { -// constructor(parent: Stage, name: string, clusterName: string, serviceName: string, fileName?: string) { -// super(parent, name, 'ECS', { minInputs: 1, maxInputs: 1, minOutputs: 0, maxOutputs: 0 }, { +// constructor(scope: Stage, id: string, clusterName: string, serviceName: string, fileName?: string) { +// super(scope, id, 'ECS', { minInputs: 1, maxInputs: 1, minOutputs: 0, maxOutputs: 0 }, { // ClusterName: clusterName, // ServiceName: serviceName, // FileName: fileName, @@ -353,16 +348,16 @@ export abstract class Action extends cdk.Construct { */ // export class JenkinsBuild extends BuildAction { -// constructor(parent: Stage, name: string, jenkinsProvider: string, project: string) { -// super(parent, name, jenkinsProvider, DefaultBounds(), { +// constructor(scope: Stage, id: string, jenkinsProvider: string, project: string) { +// super(scope, id, jenkinsProvider, DefaultBounds(), { // ProjectName: project // }); // } // } // export class JenkinsTest extends TestAction { -// constructor(parent: Stage, name: string, jenkinsProvider: string, project: string) { -// super(parent, name, jenkinsProvider, DefaultBounds(), { +// constructor(scope: Stage, id: string, jenkinsProvider: string, project: string) { +// super(scope, id, jenkinsProvider, DefaultBounds(), { // ProjectName: project // }); // } diff --git a/packages/@aws-cdk/aws-codepipeline-api/lib/artifact.ts b/packages/@aws-cdk/aws-codepipeline-api/lib/artifact.ts index b31da4dc4884a..4269b38b0fa6d 100644 --- a/packages/@aws-cdk/aws-codepipeline-api/lib/artifact.ts +++ b/packages/@aws-cdk/aws-codepipeline-api/lib/artifact.ts @@ -5,8 +5,8 @@ import { Action } from "./action"; * An output artifact of an action. Artifacts can be used as input by some actions. */ export class Artifact extends Construct { - constructor(parent: Action, readonly name: string) { - super(parent, name); + constructor(scope: Action, readonly name: string) { + super(scope, name); } /** @@ -51,7 +51,7 @@ export class Artifact extends Construct { } public toString() { - return this.name; + return this.node.id; } } diff --git a/packages/@aws-cdk/aws-codepipeline-api/lib/build-action.ts b/packages/@aws-cdk/aws-codepipeline-api/lib/build-action.ts index da078f34a4bd1..8f3cc332d9b23 100644 --- a/packages/@aws-cdk/aws-codepipeline-api/lib/build-action.ts +++ b/packages/@aws-cdk/aws-codepipeline-api/lib/build-action.ts @@ -50,8 +50,8 @@ export interface BuildActionProps extends CommonActionProps, CommonActionConstru export abstract class BuildAction extends Action { public readonly outputArtifact: Artifact; - constructor(parent: cdk.Construct, name: string, props: BuildActionProps) { - super(parent, name, { + constructor(scope: cdk.Construct, id: string, props: BuildActionProps) { + super(scope, id, { category: ActionCategory.Build, ...props, }); diff --git a/packages/@aws-cdk/aws-codepipeline-api/lib/deploy-action.ts b/packages/@aws-cdk/aws-codepipeline-api/lib/deploy-action.ts index 7e678020b9be0..5a86fd5ce2a21 100644 --- a/packages/@aws-cdk/aws-codepipeline-api/lib/deploy-action.ts +++ b/packages/@aws-cdk/aws-codepipeline-api/lib/deploy-action.ts @@ -15,8 +15,8 @@ export interface DeployActionProps extends CommonActionProps, CommonActionConstr } export abstract class DeployAction extends Action { - constructor(parent: cdk.Construct, name: string, props: DeployActionProps) { - super(parent, name, { + constructor(scope: cdk.Construct, id: string, props: DeployActionProps) { + super(scope, id, { category: ActionCategory.Deploy, ...props, }); diff --git a/packages/@aws-cdk/aws-codepipeline-api/lib/source-action.ts b/packages/@aws-cdk/aws-codepipeline-api/lib/source-action.ts index 83c2a355b4f1e..2b699c41e2050 100644 --- a/packages/@aws-cdk/aws-codepipeline-api/lib/source-action.ts +++ b/packages/@aws-cdk/aws-codepipeline-api/lib/source-action.ts @@ -52,8 +52,8 @@ export interface SourceActionProps extends CommonActionProps, CommonActionConstr export abstract class SourceAction extends Action { public readonly outputArtifact: Artifact; - constructor(parent: cdk.Construct, name: string, props: SourceActionProps) { - super(parent, name, { + constructor(scope: cdk.Construct, id: string, props: SourceActionProps) { + super(scope, id, { category: ActionCategory.Source, artifactBounds: { minInputs: 0, maxInputs: 0, minOutputs: 1, maxOutputs: 1 }, ...props, diff --git a/packages/@aws-cdk/aws-codepipeline-api/lib/test-action.ts b/packages/@aws-cdk/aws-codepipeline-api/lib/test-action.ts index 1d20efab9c9ac..9c9b91bdfa422 100644 --- a/packages/@aws-cdk/aws-codepipeline-api/lib/test-action.ts +++ b/packages/@aws-cdk/aws-codepipeline-api/lib/test-action.ts @@ -64,8 +64,8 @@ export interface TestActionProps extends CommonActionProps, CommonActionConstruc export abstract class TestAction extends Action { public readonly outputArtifact?: Artifact; - constructor(parent: cdk.Construct, name: string, props: TestActionProps) { - super(parent, name, { + constructor(scope: cdk.Construct, id: string, props: TestActionProps) { + super(scope, id, { category: ActionCategory.Test, ...props, }); diff --git a/packages/@aws-cdk/aws-codepipeline/lib/cross-region-scaffold-stack.ts b/packages/@aws-cdk/aws-codepipeline/lib/cross-region-scaffold-stack.ts index 6f85db318f8ac..43d37c1f388a6 100644 --- a/packages/@aws-cdk/aws-codepipeline/lib/cross-region-scaffold-stack.ts +++ b/packages/@aws-cdk/aws-codepipeline/lib/cross-region-scaffold-stack.ts @@ -28,8 +28,8 @@ export class CrossRegionScaffoldStack extends cdk.Stack { */ public readonly replicationBucketName: string; - constructor(parent?: cdk.App, props: CrossRegionScaffoldStackProps = defaultCrossRegionScaffoldStackProps()) { - super(parent, generateStackName(props), { + constructor(scope: cdk.App, props: CrossRegionScaffoldStackProps) { + super(scope, generateStackName(props), { env: { region: props.region, account: props.account, @@ -61,8 +61,3 @@ function generateUniqueName(baseName: string, region: string, account: string, return baseName + (toUpperCase ? hash.toUpperCase() : hash.toLowerCase()); } - -// purely to defeat the limitation that a required argument cannot follow an optional one -function defaultCrossRegionScaffoldStackProps(): CrossRegionScaffoldStackProps { - throw new Error('The props argument when creating a CrossRegionScaffoldStack is required'); -} diff --git a/packages/@aws-cdk/aws-codepipeline/lib/github-source-action.ts b/packages/@aws-cdk/aws-codepipeline/lib/github-source-action.ts index 398c52f12d35a..652b13e6bbcfa 100644 --- a/packages/@aws-cdk/aws-codepipeline/lib/github-source-action.ts +++ b/packages/@aws-cdk/aws-codepipeline/lib/github-source-action.ts @@ -56,8 +56,8 @@ export interface GitHubSourceActionProps extends actions.CommonActionProps, * Source that is provided by a GitHub repository. */ export class GitHubSourceAction extends actions.SourceAction { - constructor(parent: cdk.Construct, name: string, props: GitHubSourceActionProps) { - super(parent, name, { + constructor(scope: cdk.Construct, id: string, props: GitHubSourceActionProps) { + super(scope, id, { stage: props.stage, runOrder: props.runOrder, owner: 'ThirdParty', @@ -84,7 +84,7 @@ export class GitHubSourceAction extends actions.SourceAction { matchEquals: 'refs/heads/{Branch}', }, ], - targetAction: this.id, + targetAction: this.node.id, targetPipeline: props.stage.pipeline.pipelineName, targetPipelineVersion: 1, registerWithThirdParty: true, diff --git a/packages/@aws-cdk/aws-codepipeline/lib/manual-approval-action.ts b/packages/@aws-cdk/aws-codepipeline/lib/manual-approval-action.ts index 259fa080ae328..9b5a839d44dd8 100644 --- a/packages/@aws-cdk/aws-codepipeline/lib/manual-approval-action.ts +++ b/packages/@aws-cdk/aws-codepipeline/lib/manual-approval-action.ts @@ -36,8 +36,8 @@ export class ManualApprovalAction extends actions.Action { */ public readonly notificationTopic?: sns.ITopic; - constructor(parent: cdk.Construct, name: string, props: ManualApprovalActionProps) { - super(parent, name, { + constructor(scope: cdk.Construct, id: string, props: ManualApprovalActionProps) { + super(scope, id, { category: actions.ActionCategory.Approval, provider: 'Manual', artifactBounds: { minInputs: 0, maxInputs: 0, minOutputs: 0, maxOutputs: 0 }, diff --git a/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts b/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts index db8688b22bffe..81437ec3eeb0a 100644 --- a/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts +++ b/packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts @@ -88,8 +88,8 @@ export class Pipeline extends cdk.Construct implements cpapi.IPipeline { private readonly artifactStores: { [region: string]: any }; private readonly _crossRegionScaffoldStacks: { [region: string]: CrossRegionScaffoldStack } = {}; - constructor(parent: cdk.Construct, name: string, props?: PipelineProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props?: PipelineProps) { + super(scope, id); props = props || {}; cpapi.validateName('Pipeline', props.pipelineName); @@ -181,7 +181,7 @@ export class Pipeline extends cdk.Construct implements cpapi.IPipeline { } return { - id: this.id, + id: this.node.id, arn: this.pipelineArn, roleArn: this.eventsRole.roleArn, }; @@ -285,7 +285,7 @@ export class Pipeline extends cdk.Construct implements cpapi.IPipeline { // ignore unused private method (it's actually used in Stage) // @ts-ignore - private _attachActionToRegion(stage: Stage, action: actions.Action): void { + private _attachActionToRegion(stage: Stage, action: cpapi.Action): void { // handle cross-region Actions here if (!action.region) { return; @@ -306,6 +306,9 @@ export class Pipeline extends cdk.Construct implements cpapi.IPipeline { const pipelineAccount = pipelineStack.requireAccountId( "You need to specify an explicit account when using CodePipeline's cross-region support"); const app = pipelineStack.parentApp(); + if (!app) { + throw new Error(`Pipeline stack which uses cross region actions must be part of an application`); + } const crossRegionScaffoldStack = new CrossRegionScaffoldStack(app, { region: action.region, account: pipelineAccount, @@ -327,10 +330,10 @@ export class Pipeline extends cdk.Construct implements cpapi.IPipeline { // ignore unused private method (it's actually used in Stage) // @ts-ignore - private _generateOutputArtifactName(stage: actions.IStage, action: actions.Action): string { + private _generateOutputArtifactName(stage: cpapi.IStage, action: cpapi.Action): string { // generate the artifact name based on the Action's full logical ID, // thus guaranteeing uniqueness - return 'Artifact_' + action.uniqueId; + return 'Artifact_' + action.node.uniqueId; } /** @@ -362,7 +365,7 @@ export class Pipeline extends cdk.Construct implements cpapi.IPipeline { } } } - throw new Error(`Could not determine the input artifact for Action with name '${action.id}'. ` + + throw new Error(`Could not determine the input artifact for Action with name '${action.node.id}'. ` + 'Please provide it explicitly with the inputArtifact property.'); } @@ -417,7 +420,7 @@ export class Pipeline extends cdk.Construct implements cpapi.IPipeline { for (const stage of this.stages) { const onlySourceActionsPermitted = firstStage; for (const action of stage.actions) { - errors.push(...cpapi.validateSourceAction(onlySourceActionsPermitted, action.category, action.id, stage.id)); + errors.push(...cpapi.validateSourceAction(onlySourceActionsPermitted, action.category, action.node.id, stage.node.id)); } firstStage = false; } diff --git a/packages/@aws-cdk/aws-codepipeline/lib/stage.ts b/packages/@aws-cdk/aws-codepipeline/lib/stage.ts index bd1faa6398c80..ee51f5c5fa33b 100644 --- a/packages/@aws-cdk/aws-codepipeline/lib/stage.ts +++ b/packages/@aws-cdk/aws-codepipeline/lib/stage.ts @@ -89,11 +89,11 @@ export class Stage extends cdk.Construct implements cpapi.IStage, cpapi.IInterna /** * Create a new Stage. */ - constructor(parent: cdk.Construct, name: string, props: StageProps) { - super(parent, name); - this.name = name; + constructor(scope: cdk.Construct, id: string, props: StageProps) { + super(scope, id); + this.name = id; this.pipeline = props.pipeline; - cpapi.validateName('Stage', name); + cpapi.validateName('Stage', id); (this.pipeline as any)._attachStage(this, props.placement); } @@ -111,7 +111,7 @@ export class Stage extends cdk.Construct implements cpapi.IStage, cpapi.IInterna public render(): CfnPipeline.StageDeclarationProperty { return { - name: this.id, + name: this.node.id, actions: this._actions.map(action => this.renderAction(action)), }; } @@ -124,7 +124,7 @@ export class Stage extends cdk.Construct implements cpapi.IStage, cpapi.IInterna source: [ 'aws.codepipeline' ], resources: [ this.pipeline.pipelineArn ], detail: { - stage: [ this.id ], + stage: [ this.node.id ], }, }); return rule; @@ -151,7 +151,7 @@ export class Stage extends cdk.Construct implements cpapi.IStage, cpapi.IInterna private renderAction(action: cpapi.Action): CfnPipeline.ActionDeclarationProperty { return { - name: action.id, + name: action.node.id, inputArtifacts: action._inputArtifacts.map(a => ({ name: a.name })), actionTypeId: { category: action.category.toString(), @@ -167,7 +167,7 @@ export class Stage extends cdk.Construct implements cpapi.IStage, cpapi.IInterna private validateHasActions(): string[] { if (this._actions.length === 0) { - return [`Stage '${this.id}' must have at least one action`]; + return [`Stage '${this.node.id}' must have at least one action`]; } return []; } diff --git a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-events.expected.json b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-events.expected.json index 47d2022609c36..b977353f76690 100644 --- a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-events.expected.json +++ b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-events.expected.json @@ -290,7 +290,7 @@ ] } }, - "MyPipelineOnActionStateChange3B9E6332": { + "MyPipelineCodeCommitSourceOnActionStateChange39DCCFC1": { "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { diff --git a/packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts b/packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts index fcdd72d99fb8e..5a29a47764a2f 100644 --- a/packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts +++ b/packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts @@ -416,7 +416,9 @@ export = { const pipelineRegion = 'us-west-2'; const pipelineAccount = '123'; - const stack = new cdk.Stack(undefined, undefined, { + const app = new cdk.App(); + + const stack = new cdk.Stack(app, 'TestStack', { env: { region: pipelineRegion, account: pipelineAccount, @@ -510,8 +512,8 @@ export = { test.notEqual(usEast1ScaffoldStack, undefined); test.equal(usEast1ScaffoldStack.env.region, 'us-east-1'); test.equal(usEast1ScaffoldStack.env.account, pipelineAccount); - test.ok(usEast1ScaffoldStack.id.indexOf('us-east-1') !== -1, - `expected '${usEast1ScaffoldStack.id}' to contain 'us-east-1'`); + test.ok(usEast1ScaffoldStack.node.id.indexOf('us-east-1') !== -1, + `expected '${usEast1ScaffoldStack.node.id}' to contain 'us-east-1'`); test.done(); }, diff --git a/packages/@aws-cdk/aws-dlm/.npmignore b/packages/@aws-cdk/aws-dlm/.npmignore index 0ed32f4a4a755..2895a406c8e61 100644 --- a/packages/@aws-cdk/aws-dlm/.npmignore +++ b/packages/@aws-cdk/aws-dlm/.npmignore @@ -15,3 +15,7 @@ dist .LAST_BUILD .LAST_PACKAGE .jsii + + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/aws-dynamodb/lib/table.ts b/packages/@aws-cdk/aws-dynamodb/lib/table.ts index 8f282e8f9c958..7f3d8e1685344 100644 --- a/packages/@aws-cdk/aws-dynamodb/lib/table.ts +++ b/packages/@aws-cdk/aws-dynamodb/lib/table.ts @@ -196,8 +196,8 @@ export class Table extends Construct { private readonly indexScaling = new Map(); private readonly scalingRole: iam.IRole; - constructor(parent: Construct, name: string, props: TableProps = {}) { - super(parent, name); + constructor(scope: Construct, id: string, props: TableProps = {}) { + super(scope, id); this.billingMode = props.billingMode || BillingMode.Provisioned; this.validateProvisioning(props); @@ -220,7 +220,7 @@ export class Table extends Construct { timeToLiveSpecification: props.ttlAttributeName ? { attributeName: props.ttlAttributeName, enabled: true } : undefined }); - if (props.tableName) { this.addMetadata('aws:cdk:hasPhysicalName', props.tableName); } + if (props.tableName) { this.node.addMetadata('aws:cdk:hasPhysicalName', props.tableName); } this.tableArn = this.table.tableArn; this.tableName = this.table.tableName; diff --git a/packages/@aws-cdk/aws-ec2/lib/machine-image.ts b/packages/@aws-cdk/aws-ec2/lib/machine-image.ts index 6bca12accf619..ee4e9cb6a928f 100644 --- a/packages/@aws-cdk/aws-ec2/lib/machine-image.ts +++ b/packages/@aws-cdk/aws-ec2/lib/machine-image.ts @@ -7,7 +7,7 @@ export interface IMachineImageSource { /** * Return the image to use in the given context */ - getImage(parent: Construct): MachineImage; + getImage(scope: Construct): MachineImage; } /** @@ -24,8 +24,8 @@ export class WindowsImage implements IMachineImageSource { /** * Return the image to use in the given context */ - public getImage(parent: Construct): MachineImage { - const ssmProvider = new SSMParameterProvider(parent, { + public getImage(scope: Construct): MachineImage { + const ssmProvider = new SSMParameterProvider(scope, { parameterName: this.imageParameterName(this.version), }); @@ -95,7 +95,7 @@ export class AmazonLinuxImage implements IMachineImageSource { /** * Return the image to use in the given context */ - public getImage(parent: Construct): MachineImage { + public getImage(scope: Construct): MachineImage { const parts: Array = [ this.generation, 'ami', @@ -107,7 +107,7 @@ export class AmazonLinuxImage implements IMachineImageSource { const parameterName = '/aws/service/ami-amazon-linux-latest/' + parts.join('-'); - const ssmProvider = new SSMParameterProvider(parent, { + const ssmProvider = new SSMParameterProvider(scope, { parameterName, }); const ami = ssmProvider.parameterValue(); @@ -187,8 +187,8 @@ export class GenericLinuxImage implements IMachineImageSource { constructor(private readonly amiMap: {[region: string]: string}) { } - public getImage(parent: Construct): MachineImage { - const stack = Stack.find(parent); + public getImage(scope: Construct): MachineImage { + const stack = Stack.find(scope); const region = stack.requireRegion('AMI cannot be determined'); const ami = this.amiMap[region]; if (!ami) { diff --git a/packages/@aws-cdk/aws-ec2/lib/security-group.ts b/packages/@aws-cdk/aws-ec2/lib/security-group.ts index 001c3935b87f7..0a22448141753 100644 --- a/packages/@aws-cdk/aws-ec2/lib/security-group.ts +++ b/packages/@aws-cdk/aws-ec2/lib/security-group.ts @@ -1,10 +1,10 @@ -import { Construct, ITaggable, Output, TagManager, Tags, Token } from '@aws-cdk/cdk'; +import { Construct, IConstruct, ITaggable, Output, TagManager, Tags, Token } from '@aws-cdk/cdk'; import { Connections, IConnectable } from './connections'; import { CfnSecurityGroup, CfnSecurityGroupEgress, CfnSecurityGroupIngress } from './ec2.generated'; import { IPortRange, ISecurityGroupRule } from './security-group-rule'; import { IVpcNetwork } from './vpc-ref'; -export interface ISecurityGroup extends ISecurityGroupRule, IConnectable { +export interface ISecurityGroup extends IConstruct, ISecurityGroupRule, IConnectable { readonly securityGroupId: string; addIngressRule(peer: ISecurityGroupRule, connection: IPortRange, description?: string): void; addEgressRule(peer: ISecurityGroupRule, connection: IPortRange, description?: string): void; @@ -31,6 +31,10 @@ export abstract class SecurityGroupBase extends Construct implements ISecurityGr */ public readonly defaultPortRange?: IPortRange; + public get uniqueId() { + return this.node.uniqueId; + } + public addIngressRule(peer: ISecurityGroupRule, connection: IPortRange, description?: string) { let id = `from ${peer.uniqueId}:${connection}`; if (description === undefined) { @@ -39,7 +43,7 @@ export abstract class SecurityGroupBase extends Construct implements ISecurityGr id = id.replace('/', '_'); // Skip duplicates - if (this.tryFindChild(id) === undefined) { + if (this.node.tryFindChild(id) === undefined) { new CfnSecurityGroupIngress(this, id, { groupId: this.securityGroupId, ...peer.toIngressRuleJSON(), @@ -57,7 +61,7 @@ export abstract class SecurityGroupBase extends Construct implements ISecurityGr id = id.replace('/', '_'); // Skip duplicates - if (this.tryFindChild(id) === undefined) { + if (this.node.tryFindChild(id) === undefined) { new CfnSecurityGroupEgress(this, id, { groupId: this.securityGroupId, ...peer.toEgressRuleJSON(), @@ -134,8 +138,8 @@ export class SecurityGroup extends SecurityGroupBase implements ITaggable { /** * Import an existing SecurityGroup */ - public static import(parent: Construct, id: string, props: SecurityGroupImportProps): ISecurityGroup { - return new ImportedSecurityGroup(parent, id, props); + public static import(scope: Construct, id: string, props: SecurityGroupImportProps): ISecurityGroup { + return new ImportedSecurityGroup(scope, id, props); } /** @@ -164,11 +168,11 @@ export class SecurityGroup extends SecurityGroupBase implements ITaggable { private readonly allowAllOutbound: boolean; - constructor(parent: Construct, name: string, props: SecurityGroupProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: SecurityGroupProps) { + super(scope, id); this.tags = new TagManager(this, { initialTags: props.tags}); - const groupDescription = props.description || this.path; + const groupDescription = props.description || this.node.path; this.allowAllOutbound = props.allowAllOutbound !== false; @@ -392,8 +396,8 @@ export interface ConnectionRule { class ImportedSecurityGroup extends SecurityGroupBase { public readonly securityGroupId: string; - constructor(parent: Construct, name: string, private readonly props: SecurityGroupImportProps) { - super(parent, name); + constructor(scope: Construct, id: string, private readonly props: SecurityGroupImportProps) { + super(scope, id); this.securityGroupId = props.securityGroupId; } diff --git a/packages/@aws-cdk/aws-ec2/lib/util.ts b/packages/@aws-cdk/aws-ec2/lib/util.ts index a646aa8051470..77a11e16bb305 100644 --- a/packages/@aws-cdk/aws-ec2/lib/util.ts +++ b/packages/@aws-cdk/aws-ec2/lib/util.ts @@ -26,7 +26,7 @@ export const DEFAULT_SUBNET_NAME = { * All subnet names look like NAME <> "Subnet" <> INDEX */ export function subnetName(subnet: IVpcSubnet) { - return subnet.id.replace(/Subnet\d+$/, ''); + return subnet.node.id.replace(/Subnet\d+$/, ''); } /** @@ -46,7 +46,7 @@ export class ExportSubnetGroup { private readonly groups: number; constructor( - parent: cdk.Construct, + scope: cdk.Construct, exportName: string, private readonly subnets: IVpcSubnet[], private readonly type: SubnetType, @@ -59,13 +59,13 @@ export class ExportSubnetGroup { throw new Error(`Number of subnets (${subnets.length}) must be a multiple of number of availability zones (${azs})`); } - this.ids = this.exportIds(parent, exportName); + this.ids = this.exportIds(scope, exportName); this.names = this.exportNames(); } - private exportIds(parent: cdk.Construct, name: string): string[] | undefined { + private exportIds(scope: cdk.Construct, name: string): string[] | undefined { if (this.subnets.length === 0) { return undefined; } - return new cdk.StringListOutput(parent, name, { values: this.subnets.map(s => s.subnetId) }).makeImportValues().map(x => x.toString()); + return new cdk.StringListOutput(scope, name, { values: this.subnets.map(s => s.subnetId) }).makeImportValues().map(x => x.toString()); } /** @@ -117,10 +117,10 @@ export class ImportSubnetGroup { this.names = this.normalizeNames(names, DEFAULT_SUBNET_NAME[type], nameField); } - public import(parent: cdk.Construct): IVpcSubnet[] { + public import(scope: cdk.Construct): IVpcSubnet[] { return range(this.subnetIds.length).map(i => { const k = Math.floor(i / this.availabilityZones.length); - return VpcSubnet.import(parent, subnetId(this.names[k], i), { + return VpcSubnet.import(scope, subnetId(this.names[k], i), { availabilityZone: this.pickAZ(i), subnetId: this.subnetIds[i] }); diff --git a/packages/@aws-cdk/aws-ec2/lib/vpc-ref.ts b/packages/@aws-cdk/aws-ec2/lib/vpc-ref.ts index 3d0ce4dc6530b..f92f0f6447aea 100644 --- a/packages/@aws-cdk/aws-ec2/lib/vpc-ref.ts +++ b/packages/@aws-cdk/aws-ec2/lib/vpc-ref.ts @@ -1,17 +1,7 @@ -import { Construct, IDependable } from "@aws-cdk/cdk"; +import { Construct, IConstruct, IDependable } from "@aws-cdk/cdk"; import { subnetName } from './util'; -export interface IVpcSubnet extends IDependable { - /** - * Logical ID of the subnet. - */ - readonly id: string; - - /** - * Construct path of this subnet. - */ - readonly path: string; - +export interface IVpcSubnet extends IConstruct, IDependable { /** * The Availability Zone the subnet is located in */ @@ -28,7 +18,7 @@ export interface IVpcSubnet extends IDependable { export(): VpcSubnetImportProps; } -export interface IVpcNetwork extends IDependable { +export interface IVpcNetwork extends IConstruct, IDependable { /** * Identifier for this VPC */ diff --git a/packages/@aws-cdk/aws-ec2/lib/vpc.ts b/packages/@aws-cdk/aws-ec2/lib/vpc.ts index 080c0ae8bb922..6c25430b6cca5 100644 --- a/packages/@aws-cdk/aws-ec2/lib/vpc.ts +++ b/packages/@aws-cdk/aws-ec2/lib/vpc.ts @@ -218,15 +218,15 @@ export class VpcNetwork extends VpcNetworkBase implements cdk.ITaggable { /** * Import an exported VPC */ - public static import(parent: cdk.Construct, name: string, props: VpcNetworkImportProps): IVpcNetwork { - return new ImportedVpcNetwork(parent, name, props); + public static import(scope: cdk.Construct, id: string, props: VpcNetworkImportProps): IVpcNetwork { + return new ImportedVpcNetwork(scope, id, props); } /** * Import an existing VPC from context */ - public static importFromContext(parent: cdk.Construct, name: string, props: VpcNetworkProviderProps): IVpcNetwork { - return VpcNetwork.import(parent, name, new VpcNetworkProvider(parent, props).vpcProps); + public static importFromContext(scope: cdk.Construct, id: string, props: VpcNetworkProviderProps): IVpcNetwork { + return VpcNetwork.import(scope, id, new VpcNetworkProvider(scope, props).vpcProps); } /** @@ -285,8 +285,8 @@ export class VpcNetwork extends VpcNetworkBase implements cdk.ITaggable { * Network routing for the public subnets will be configured to allow outbound access directly via an Internet Gateway. * Network routing for the private subnets will be configured to allow outbound access via a set of resilient NAT Gateways (one per AZ). */ - constructor(parent: cdk.Construct, name: string, props: VpcNetworkProps = {}) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: VpcNetworkProps = {}) { + super(scope, id); // Can't have enabledDnsHostnames without enableDnsSupport if (props.enableDnsHostnames && !props.enableDnsSupport) { @@ -294,7 +294,7 @@ export class VpcNetwork extends VpcNetworkBase implements cdk.ITaggable { } this.tags = new cdk.TagManager(this, { initialTags: props.tags}); - this.tags.setTag(NAME_TAG, this.path, { overwrite: false }); + this.tags.setTag(NAME_TAG, this.node.path, { overwrite: false }); const cidrBlock = ifUndefined(props.cidr, VpcNetwork.DEFAULT_CIDR_RANGE); this.networkBuilder = new NetworkBuilder(cidrBlock); @@ -519,8 +519,8 @@ export interface VpcSubnetProps { * Represents a new VPC subnet resource */ export class VpcSubnet extends cdk.Construct implements IVpcSubnet, cdk.ITaggable, cdk.IDependable { - public static import(parent: cdk.Construct, name: string, props: VpcSubnetImportProps): IVpcSubnet { - return new ImportedVpcSubnet(parent, name, props); + public static import(scope: cdk.Construct, id: string, props: VpcSubnetImportProps): IVpcSubnet { + return new ImportedVpcSubnet(scope, id, props); } /** @@ -548,10 +548,10 @@ export class VpcSubnet extends cdk.Construct implements IVpcSubnet, cdk.ITaggabl */ private readonly routeTableId: string; - constructor(parent: cdk.Construct, name: string, props: VpcSubnetProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: VpcSubnetProps) { + super(scope, id); this.tags = new cdk.TagManager(this, {initialTags: props.tags}); - this.tags.setTag(NAME_TAG, this.path, {overwrite: false}); + this.tags.setTag(NAME_TAG, this.node.path, {overwrite: false}); this.availabilityZone = props.availabilityZone; const subnet = new CfnSubnet(this, 'Subnet', { @@ -612,8 +612,8 @@ export class VpcSubnet extends cdk.Construct implements IVpcSubnet, cdk.ITaggabl * Represents a public VPC subnet resource */ export class VpcPublicSubnet extends VpcSubnet { - constructor(parent: cdk.Construct, name: string, props: VpcSubnetProps) { - super(parent, name, props); + constructor(scope: cdk.Construct, id: string, props: VpcSubnetProps) { + super(scope, id, props); } /** @@ -648,8 +648,8 @@ export class VpcPublicSubnet extends VpcSubnet { * Represents a private VPC subnet resource */ export class VpcPrivateSubnet extends VpcSubnet { - constructor(parent: cdk.Construct, name: string, props: VpcSubnetProps) { - super(parent, name, props); + constructor(scope: cdk.Construct, id: string, props: VpcSubnetProps) { + super(scope, id, props); } /** @@ -664,15 +664,15 @@ function ifUndefined(value: T | undefined, defaultValue: T): T { return value !== undefined ? value : defaultValue; } -export class ImportedVpcNetwork extends VpcNetworkBase { +class ImportedVpcNetwork extends VpcNetworkBase { public readonly vpcId: string; public readonly publicSubnets: IVpcSubnet[]; public readonly privateSubnets: IVpcSubnet[]; public readonly isolatedSubnets: IVpcSubnet[]; public readonly availabilityZones: string[]; - constructor(parent: cdk.Construct, id: string, private readonly props: VpcNetworkImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: VpcNetworkImportProps) { + super(scope, id); this.vpcId = props.vpcId; this.availabilityZones = props.availabilityZones; @@ -693,13 +693,13 @@ export class ImportedVpcNetwork extends VpcNetworkBase { } } -export class ImportedVpcSubnet extends cdk.Construct implements IVpcSubnet { +class ImportedVpcSubnet extends cdk.Construct implements IVpcSubnet { public readonly availabilityZone: string; public readonly subnetId: string; public readonly dependencyElements = new Array(); - constructor(parent: cdk.Construct, id: string, private readonly props: VpcSubnetImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: VpcSubnetImportProps) { + super(scope, id); this.subnetId = props.subnetId; this.availabilityZone = props.availabilityZone; diff --git a/packages/@aws-cdk/aws-ec2/test/example.share-vpcs.lit.ts b/packages/@aws-cdk/aws-ec2/test/example.share-vpcs.lit.ts index c48f53f38fcd9..5f2d2b20f08f3 100644 --- a/packages/@aws-cdk/aws-ec2/test/example.share-vpcs.lit.ts +++ b/packages/@aws-cdk/aws-ec2/test/example.share-vpcs.lit.ts @@ -8,8 +8,8 @@ interface ConstructThatTakesAVpcProps { } class ConstructThatTakesAVpc extends cdk.Construct { - constructor(parent: cdk.Construct, id: string, _props: ConstructThatTakesAVpcProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, _props: ConstructThatTakesAVpcProps) { + super(scope, id); } } @@ -17,8 +17,8 @@ class ConstructThatTakesAVpc extends cdk.Construct { class Stack1 extends cdk.Stack { public readonly vpcProps: ec2.VpcNetworkImportProps; - constructor(parent: cdk.App, id: string, props?: cdk.StackProps) { - super(parent, id, props); + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { + super(scope, id, props); const vpc = new ec2.VpcNetwork(this, 'VPC'); @@ -32,8 +32,8 @@ interface Stack2Props extends cdk.StackProps { } class Stack2 extends cdk.Stack { - constructor(parent: cdk.App, id: string, props: Stack2Props) { - super(parent, id, props); + constructor(scope: cdk.App, id: string, props: Stack2Props) { + super(scope, id, props); // Import the VPC from a set of properties const vpc = ec2.VpcNetwork.import(this, 'VPC', props.vpcProps); diff --git a/packages/@aws-cdk/aws-ec2/test/test.vpc.ts b/packages/@aws-cdk/aws-ec2/test/test.vpc.ts index f4cab6224ea79..dcc3ecd5d3827 100644 --- a/packages/@aws-cdk/aws-ec2/test/test.vpc.ts +++ b/packages/@aws-cdk/aws-ec2/test/test.vpc.ts @@ -362,12 +362,12 @@ export = { const stack = getTestStack(); const vpc = new VpcNetwork(stack, 'TheVPC'); for (const subnet of vpc.publicSubnets) { - const tag = {Key: 'Name', Value: subnet.path}; + const tag = {Key: 'Name', Value: subnet.node.path}; expect(stack).to(haveResource('AWS::EC2::NatGateway', hasTags([tag]))); expect(stack).to(haveResource('AWS::EC2::RouteTable', hasTags([tag]))); } for (const subnet of vpc.privateSubnets) { - const tag = {Key: 'Name', Value: subnet.path}; + const tag = {Key: 'Name', Value: subnet.node.path}; expect(stack).to(haveResource('AWS::EC2::RouteTable', hasTags([tag]))); } test.done(); @@ -468,10 +468,12 @@ export = { test.equal(6, imported.publicSubnets.length); for (let i = 0; i < 3; i++) { - test.equal(true, imported.publicSubnets[i].id.startsWith('Ingress'), `${imported.publicSubnets[i].id} does not start with "Ingress"`); + // tslint:disable-next-line:max-line-length + test.equal(true, imported.publicSubnets[i].node.id.startsWith('Ingress'), `${imported.publicSubnets[i].node.id} does not start with "Ingress"`); } for (let i = 3; i < 6; i++) { - test.equal(true, imported.publicSubnets[i].id.startsWith('Egress'), `${imported.publicSubnets[i].id} does not start with "Egress"`); + // tslint:disable-next-line:max-line-length + test.equal(true, imported.publicSubnets[i].node.id.startsWith('Egress'), `${imported.publicSubnets[i].node.id} does not start with "Egress"`); } test.done(); @@ -531,7 +533,7 @@ function getTestStack(): Stack { /** * Do a complete import/export test, return the imported VPC */ -function doImportExportTest(constructFn: (parent: Construct) => VpcNetwork): IVpcNetwork { +function doImportExportTest(constructFn: (scope: Construct) => VpcNetwork): IVpcNetwork { // GIVEN const stack1 = getTestStack(); const stack2 = getTestStack(); diff --git a/packages/@aws-cdk/aws-ecr/lib/pipeline-action.ts b/packages/@aws-cdk/aws-ecr/lib/pipeline-action.ts index ec0fa6db438f9..4ccb694afc95a 100644 --- a/packages/@aws-cdk/aws-ecr/lib/pipeline-action.ts +++ b/packages/@aws-cdk/aws-ecr/lib/pipeline-action.ts @@ -40,8 +40,8 @@ export interface PipelineSourceActionProps extends CommonPipelineSourceActionPro * The ECR Repository source CodePipeline Action. */ export class PipelineSourceAction extends codepipeline.SourceAction { - constructor(parent: cdk.Construct, name: string, props: PipelineSourceActionProps) { - super(parent, name, { + constructor(scope: cdk.Construct, id: string, props: PipelineSourceActionProps) { + super(scope, id, { provider: 'ECR', configuration: { RepositoryName: props.repository.repositoryName, @@ -56,7 +56,7 @@ export class PipelineSourceAction extends codepipeline.SourceAction { ) .addResource(props.repository.repositoryArn)); - props.repository.onImagePushed(props.stage.pipeline.uniqueId + 'SourceEventRule', + props.repository.onImagePushed(props.stage.pipeline.node.uniqueId + 'SourceEventRule', props.stage.pipeline, props.imageTag); } } diff --git a/packages/@aws-cdk/aws-ecr/lib/repository-ref.ts b/packages/@aws-cdk/aws-ecr/lib/repository-ref.ts index 3c73b055a06e6..f85be5d0db917 100644 --- a/packages/@aws-cdk/aws-ecr/lib/repository-ref.ts +++ b/packages/@aws-cdk/aws-ecr/lib/repository-ref.ts @@ -7,7 +7,7 @@ import { CommonPipelineSourceActionProps, PipelineSourceAction } from './pipelin /** * Represents an ECR repository. */ -export interface IRepository { +export interface IRepository extends cdk.IConstruct { /** * The name of the repository */ @@ -114,8 +114,8 @@ export abstract class RepositoryBase extends cdk.Construct implements IRepositor /** * Import a repository */ - public static import(parent: cdk.Construct, id: string, props: RepositoryImportProps): IRepository { - return new ImportedRepository(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: RepositoryImportProps): IRepository { + return new ImportedRepository(scope, id, props); } /** @@ -254,8 +254,8 @@ class ImportedRepository extends RepositoryBase { public readonly repositoryName: string; public readonly repositoryArn: string; - constructor(parent: cdk.Construct, id: string, private readonly props: RepositoryImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: RepositoryImportProps) { + super(scope, id); if (props.repositoryArn) { this.repositoryArn = props.repositoryArn; diff --git a/packages/@aws-cdk/aws-ecr/lib/repository.ts b/packages/@aws-cdk/aws-ecr/lib/repository.ts index 1d74accc18173..98ea1f4697752 100644 --- a/packages/@aws-cdk/aws-ecr/lib/repository.ts +++ b/packages/@aws-cdk/aws-ecr/lib/repository.ts @@ -48,8 +48,8 @@ export class Repository extends RepositoryBase { private readonly registryId?: string; private policyDocument?: iam.PolicyDocument; - constructor(parent: cdk.Construct, id: string, props: RepositoryProps = {}) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: RepositoryProps = {}) { + super(scope, id); const resource = new CfnRepository(this, 'Resource', { repositoryName: props.repositoryName, diff --git a/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts b/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts index de987d2f1decf..9ccfe00335f60 100644 --- a/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts @@ -93,13 +93,13 @@ export abstract class BaseService extends cdk.Construct private readonly resource: CfnService; private scalableTaskCount?: ScalableTaskCount; - constructor(parent: cdk.Construct, - name: string, + constructor(scope: cdk.Construct, + id: string, props: BaseServiceProps, additionalProps: any, clusterName: string, taskDefinition: TaskDefinition) { - super(parent, name); + super(scope, id); this.taskDefinition = taskDefinition; @@ -212,7 +212,7 @@ export abstract class BaseService extends cdk.Construct this.loadBalancers.push({ targetGroupArn: targetGroup.targetGroupArn, - containerName: this.taskDefinition.defaultContainer!.id, + containerName: this.taskDefinition.defaultContainer!.node.id, containerPort: this.taskDefinition.defaultContainer!.containerPort, }); diff --git a/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts b/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts index 7c10a4cbc3653..f1a96595e6640 100644 --- a/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts +++ b/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts @@ -155,10 +155,10 @@ export class TaskDefinition extends cdk.Construct { */ private readonly placementConstraints = new Array(); - constructor(parent: cdk.Construct, name: string, props: TaskDefinitionProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: TaskDefinitionProps) { + super(scope, id); - this.family = props.family || this.uniqueId; + this.family = props.family || this.node.uniqueId; this.compatibility = props.compatibility; if (props.volumes) { @@ -254,7 +254,7 @@ export class TaskDefinition extends cdk.Construct { // Container sizes for (const container of this.containers) { if (!container.memoryLimitSpecified) { - ret.push(`ECS Container ${container.id} must have at least one of 'memoryLimitMiB' or 'memoryReservationMiB' specified`); + ret.push(`ECS Container ${container.node.id} must have at least one of 'memoryLimitMiB' or 'memoryReservationMiB' specified`); } } } diff --git a/packages/@aws-cdk/aws-ecs/lib/cluster.ts b/packages/@aws-cdk/aws-ecs/lib/cluster.ts index db8ade9548d70..ac90dc3660d60 100644 --- a/packages/@aws-cdk/aws-ecs/lib/cluster.ts +++ b/packages/@aws-cdk/aws-ecs/lib/cluster.ts @@ -30,8 +30,8 @@ export class Cluster extends cdk.Construct implements ICluster { /** * Import an existing cluster */ - public static import(parent: cdk.Construct, name: string, props: ClusterImportProps): ICluster { - return new ImportedCluster(parent, name, props); + public static import(scope: cdk.Construct, id: string, props: ClusterImportProps): ICluster { + return new ImportedCluster(scope, id, props); } /** @@ -59,8 +59,8 @@ export class Cluster extends cdk.Construct implements ICluster { */ private _hasEc2Capacity: boolean = false; - constructor(parent: cdk.Construct, name: string, props: ClusterProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: ClusterProps) { + super(scope, id); const cluster = new CfnCluster(this, 'Resource', {clusterName: props.clusterName}); @@ -193,8 +193,8 @@ export class EcsOptimizedAmi implements ec2.IMachineImageSource { /** * Return the correct image */ - public getImage(parent: cdk.Construct): ec2.MachineImage { - const ssmProvider = new cdk.SSMParameterProvider(parent, { + public getImage(scope: cdk.Construct): ec2.MachineImage { + const ssmProvider = new cdk.SSMParameterProvider(scope, { parameterName: EcsOptimizedAmi.AmiParameterName }); @@ -208,7 +208,7 @@ export class EcsOptimizedAmi implements ec2.IMachineImageSource { /** * An ECS cluster */ -export interface ICluster { +export interface ICluster extends cdk.IConstruct { /** * Name of the cluster */ @@ -286,8 +286,8 @@ class ImportedCluster extends cdk.Construct implements ICluster { */ public readonly hasEc2Capacity: boolean; - constructor(parent: cdk.Construct, name: string, private readonly props: ClusterImportProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, private readonly props: ClusterImportProps) { + super(scope, id); this.clusterName = props.clusterName; this.vpc = ec2.VpcNetwork.import(this, "vpc", props.vpc); this.hasEc2Capacity = props.hasEc2Capacity !== false; diff --git a/packages/@aws-cdk/aws-ecs/lib/container-definition.ts b/packages/@aws-cdk/aws-ecs/lib/container-definition.ts index dfcbaf07959d0..478ff70763f05 100644 --- a/packages/@aws-cdk/aws-ecs/lib/container-definition.ts +++ b/packages/@aws-cdk/aws-ecs/lib/container-definition.ts @@ -222,8 +222,8 @@ export class ContainerDefinition extends cdk.Construct { */ private readonly links = new Array(); - constructor(parent: cdk.Construct, id: string, taskDefinition: TaskDefinition, private readonly props: ContainerDefinitionProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, taskDefinition: TaskDefinition, private readonly props: ContainerDefinitionProps) { + super(scope, id); this.essential = props.essential !== undefined ? props.essential : true; this.taskDefinition = taskDefinition; this.memoryLimitSpecified = props.memoryLimitMiB !== undefined || props.memoryReservationMiB !== undefined; @@ -243,9 +243,9 @@ export class ContainerDefinition extends cdk.Construct { throw new Error(`You must use network mode Bridge to add container links.`); } if (alias !== undefined) { - this.links.push(`${container.id}:${alias}`); + this.links.push(`${container.node.id}:${alias}`); } else { - this.links.push(`${container.id}`); + this.links.push(`${container.node.id}`); } } @@ -323,7 +323,7 @@ export class ContainerDefinition extends cdk.Construct { */ public get ingressPort(): number { if (this.portMappings.length === 0) { - throw new Error(`Container ${this.id} hasn't defined any ports. Call addPortMappings().`); + throw new Error(`Container ${this.node.id} hasn't defined any ports. Call addPortMappings().`); } const defaultPortMapping = this.portMappings[0]; @@ -342,7 +342,7 @@ export class ContainerDefinition extends cdk.Construct { */ public get containerPort(): number { if (this.portMappings.length === 0) { - throw new Error(`Container ${this.id} hasn't defined any ports. Call addPortMappings().`); + throw new Error(`Container ${this.node.id} hasn't defined any ports. Call addPortMappings().`); } const defaultPortMapping = this.portMappings[0]; return defaultPortMapping.containerPort; @@ -367,7 +367,7 @@ export class ContainerDefinition extends cdk.Construct { memory: this.props.memoryLimitMiB, memoryReservation: this.props.memoryReservationMiB, mountPoints: this.mountPoints.map(renderMountPoint), - name: this.id, + name: this.node.id, portMappings: this.portMappings.map(renderPortMapping), privileged: this.props.privileged, readonlyRootFilesystem: this.props.readonlyRootFilesystem, diff --git a/packages/@aws-cdk/aws-ecs/lib/container-image.ts b/packages/@aws-cdk/aws-ecs/lib/container-image.ts index f1a9bb8583eb2..6acf0fb894339 100644 --- a/packages/@aws-cdk/aws-ecs/lib/container-image.ts +++ b/packages/@aws-cdk/aws-ecs/lib/container-image.ts @@ -42,7 +42,7 @@ export class ContainerImage { /** * Reference an image that's constructed directly from sources on disk */ - public static fromAsset(parent: cdk.Construct, id: string, props: AssetImageProps) { - return new AssetImage(parent, id, props); + public static fromAsset(scope: cdk.Construct, id: string, props: AssetImageProps) { + return new AssetImage(scope, id, props); } } diff --git a/packages/@aws-cdk/aws-ecs/lib/drain-hook/instance-drain-hook.ts b/packages/@aws-cdk/aws-ecs/lib/drain-hook/instance-drain-hook.ts index 763ede6430c71..9605f66bf0af9 100644 --- a/packages/@aws-cdk/aws-ecs/lib/drain-hook/instance-drain-hook.ts +++ b/packages/@aws-cdk/aws-ecs/lib/drain-hook/instance-drain-hook.ts @@ -39,8 +39,8 @@ export interface InstanceDrainHookProps { * A hook to drain instances from ECS traffic before they're terminated */ export class InstanceDrainHook extends cdk.Construct { - constructor(parent: cdk.Construct, id: string, props: InstanceDrainHookProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: InstanceDrainHookProps) { + super(scope, id); const drainTimeSeconds = props.drainTimeSec !== undefined ? props.drainTimeSec : 300; diff --git a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts b/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts index de8bbac1be357..80e85bf387778 100644 --- a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts @@ -72,7 +72,7 @@ export class Ec2Service extends BaseService implements elb.ILoadBalancerTarget { private readonly daemon: boolean; private readonly cluster: ICluster; - constructor(parent: cdk.Construct, name: string, props: Ec2ServiceProps) { + constructor(scope: cdk.Construct, id: string, props: Ec2ServiceProps) { if (props.daemon && props.desiredCount !== undefined) { throw new Error('Daemon mode launches one task on every instance. Don\'t supply desiredCount.'); } @@ -81,7 +81,7 @@ export class Ec2Service extends BaseService implements elb.ILoadBalancerTarget { throw new Error('Supplied TaskDefinition is not configured for compatibility with EC2'); } - super(parent, name, { + super(scope, id, { ...props, // If daemon, desiredCount must be undefined and that's what we want. Otherwise, default to 1. desiredCount: props.daemon || props.desiredCount !== undefined ? props.desiredCount : 1, @@ -193,7 +193,7 @@ export class Ec2Service extends BaseService implements elb.ILoadBalancerTarget { this.loadBalancers.push({ loadBalancerName: loadBalancer.loadBalancerName, - containerName: this.taskDefinition.defaultContainer!.id, + containerName: this.taskDefinition.defaultContainer!.node.id, containerPort: this.taskDefinition.defaultContainer!.containerPort, }); } diff --git a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-task-definition.ts b/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-task-definition.ts index 86d67a1728704..a1a130e2a1868 100644 --- a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-task-definition.ts +++ b/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-task-definition.ts @@ -28,8 +28,8 @@ export interface Ec2TaskDefinitionProps extends CommonTaskDefinitionProps { * Define Tasks to run on an ECS cluster */ export class Ec2TaskDefinition extends TaskDefinition { - constructor(parent: cdk.Construct, name: string, props: Ec2TaskDefinitionProps = {}) { - super(parent, name, { + constructor(scope: cdk.Construct, id: string, props: Ec2TaskDefinitionProps = {}) { + super(scope, id, { ...props, compatibility: Compatibility.Ec2, placementConstraints: props.placementConstraints, diff --git a/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts b/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts index 409c360d0a49d..66e0d9600cd98 100644 --- a/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts @@ -55,12 +55,12 @@ export interface FargateServiceProps extends BaseServiceProps { * Start a service on an ECS cluster */ export class FargateService extends BaseService { - constructor(parent: cdk.Construct, name: string, props: FargateServiceProps) { + constructor(scope: cdk.Construct, id: string, props: FargateServiceProps) { if (!isFargateCompatible(props.taskDefinition.compatibility)) { throw new Error('Supplied TaskDefinition is not configured for compatibility with Fargate'); } - super(parent, name, { + super(scope, id, { ...props, desiredCount: props.desiredCount !== undefined ? props.desiredCount : 1, }, { diff --git a/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-task-definition.ts b/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-task-definition.ts index 475e90faa2d01..f98ca512bb8e2 100644 --- a/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-task-definition.ts +++ b/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-task-definition.ts @@ -51,8 +51,8 @@ export class FargateTaskDefinition extends TaskDefinition { // we need to explicitly write the type here, as type deduction for enums won't lead to // the import being generated in the .d.ts file. - constructor(parent: cdk.Construct, name: string, props: FargateTaskDefinitionProps = {}) { - super(parent, name, { + constructor(scope: cdk.Construct, id: string, props: FargateTaskDefinitionProps = {}) { + super(scope, id, { ...props, cpu: props.cpu || '256', memoryMiB: props.memoryMiB || '512', diff --git a/packages/@aws-cdk/aws-ecs/lib/images/asset-image.ts b/packages/@aws-cdk/aws-ecs/lib/images/asset-image.ts index eb281218798d4..10687aa342765 100644 --- a/packages/@aws-cdk/aws-ecs/lib/images/asset-image.ts +++ b/packages/@aws-cdk/aws-ecs/lib/images/asset-image.ts @@ -14,8 +14,8 @@ export interface AssetImageProps { * An image that will be built at synthesis time */ export class AssetImage extends DockerImageAsset implements IContainerImage { - constructor(parent: cdk.Construct, id: string, props: AssetImageProps) { - super(parent, id, { directory: props.directory }); + constructor(scope: cdk.Construct, id: string, props: AssetImageProps) { + super(scope, id, { directory: props.directory }); } public bind(containerDefinition: ContainerDefinition): void { diff --git a/packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts b/packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts index 425fc8d799055..bbf9c2e01b4c5 100644 --- a/packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/load-balanced-ecs-service.ts @@ -72,8 +72,8 @@ export class LoadBalancedEc2Service extends cdk.Construct { */ public readonly loadBalancer: elbv2.ApplicationLoadBalancer; - constructor(parent: cdk.Construct, id: string, props: LoadBalancedEc2ServiceProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: LoadBalancedEc2ServiceProps) { + super(scope, id); const taskDefinition = new Ec2TaskDefinition(this, 'TaskDef', {}); diff --git a/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service-applet.ts b/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service-applet.ts index af5937804d9d4..ca019b69f93f9 100644 --- a/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service-applet.ts +++ b/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service-applet.ts @@ -102,8 +102,8 @@ export interface LoadBalancedFargateServiceAppletProps extends cdk.StackProps { * load balancer, ECS cluster, VPC, and (optionally) Route53 alias record. */ export class LoadBalancedFargateServiceApplet extends cdk.Stack { - constructor(parent: cdk.App, id: string, props: LoadBalancedFargateServiceAppletProps) { - super(parent, id, props); + constructor(scope: cdk.App, id: string, props: LoadBalancedFargateServiceAppletProps) { + super(scope, id, props); const vpc = new VpcNetwork(this, 'MyVpc', { maxAZs: 2 }); const cluster = new Cluster(this, 'Cluster', { vpc }); diff --git a/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service.ts b/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service.ts index 722829eac58f7..c90ff69435add 100644 --- a/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/load-balanced-fargate-service.ts @@ -120,8 +120,8 @@ export class LoadBalancedFargateService extends cdk.Construct { public readonly service: FargateService; - constructor(parent: cdk.Construct, id: string, props: LoadBalancedFargateServiceProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: LoadBalancedFargateServiceProps) { + super(scope, id); const taskDefinition = new FargateTaskDefinition(this, 'TaskDef', { memoryMiB: props.memoryMiB, @@ -132,7 +132,7 @@ export class LoadBalancedFargateService extends cdk.Construct { const container = taskDefinition.addContainer('web', { image: props.image, - logging: optIn ? this.createAWSLogDriver(this.id) : undefined + logging: optIn ? this.createAWSLogDriver(this.node.id) : undefined }); container.addPortMappings({ diff --git a/packages/@aws-cdk/aws-ecs/lib/log-drivers/aws-log-driver.ts b/packages/@aws-cdk/aws-ecs/lib/log-drivers/aws-log-driver.ts index 781938b45b4ed..b97b4f9616714 100644 --- a/packages/@aws-cdk/aws-ecs/lib/log-drivers/aws-log-driver.ts +++ b/packages/@aws-cdk/aws-ecs/lib/log-drivers/aws-log-driver.ts @@ -55,8 +55,8 @@ export class AwsLogDriver extends LogDriver { */ public readonly logGroup: logs.ILogGroup; - constructor(parent: cdk.Construct, id: string, private readonly props: AwsLogDriverProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: AwsLogDriverProps) { + super(scope, id); this.logGroup = props.logGroup || new logs.LogGroup(this, 'LogGroup', { retentionDays: 365, }); diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts index 186d524ac6c99..118504c686501 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts @@ -205,8 +205,8 @@ export class LoadBalancer extends cdk.Construct implements IConnectable, codedep private readonly instancePorts: number[] = []; private readonly targets: ILoadBalancerTarget[] = []; - constructor(parent: cdk.Construct, name: string, props: LoadBalancerProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: LoadBalancerProps) { + super(scope, id); this.securityGroup = new SecurityGroup(this, 'SecurityGroup', { vpc: props.vpc, allowAllOutbound: false }); this.connections = new Connections({ securityGroups: [this.securityGroup] }); diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/test/test.loadbalancer.ts b/packages/@aws-cdk/aws-elasticloadbalancing/test/test.loadbalancer.ts index 103de812bb014..0ffe5a7b7a279 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/test/test.loadbalancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancing/test/test.loadbalancer.ts @@ -7,7 +7,7 @@ import { ILoadBalancerTarget, LoadBalancer, LoadBalancingProtocol } from '../lib export = { 'test specifying nonstandard port works'(test: Test) { const stack = new Stack(undefined, undefined, { env: { account: '1234', region: 'test' }}); - stack.setContext('availability-zones:1234:test', ['test-1a', 'test-1b']); + stack.node.setContext('availability-zones:1234:test', ['test-1a', 'test-1b']); const vpc = new VpcNetwork(stack, 'VCP'); const lb = new LoadBalancer(stack, 'LB', { vpc }); diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-certificate.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-certificate.ts index 59265225c0e83..45fd4924f4cc4 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-certificate.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-certificate.ts @@ -28,8 +28,8 @@ export class ApplicationListenerCertificate extends cdk.Construct implements cdk */ public readonly dependencyElements: cdk.IDependable[] = []; - constructor(parent: cdk.Construct, id: string, props: ApplicationListenerCertificateProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: ApplicationListenerCertificateProps) { + super(scope, id); const resource = new CfnListenerCertificate(this, 'Resource', { listenerArn: props.listener.listenerArn, diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts index 4b69d8acf6612..cbe634e20b6c6 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts @@ -73,8 +73,8 @@ export class ApplicationListenerRule extends cdk.Construct implements cdk.IDepen private readonly actions: any[] = []; private readonly listener: IApplicationListener; - constructor(parent: cdk.Construct, id: string, props: ApplicationListenerRuleProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: ApplicationListenerRuleProps) { + super(scope, id); if (!props.hostHeader && !props.pathPattern) { throw new Error(`At least one of 'hostHeader' or 'pathPattern' is required when defining a load balancing rule.`); diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.ts index 7257af6e3e4da..60c2033f1e153 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.ts @@ -79,8 +79,8 @@ export class ApplicationListener extends BaseListener implements IApplicationLis /** * Import an existing listener */ - public static import(parent: cdk.Construct, id: string, props: ApplicationListenerImportProps): IApplicationListener { - return new ImportedApplicationListener(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: ApplicationListenerImportProps): IApplicationListener { + return new ImportedApplicationListener(scope, id, props); } /** @@ -108,10 +108,10 @@ export class ApplicationListener extends BaseListener implements IApplicationLis */ private readonly defaultPort: number; - constructor(parent: cdk.Construct, id: string, props: ApplicationListenerProps) { + constructor(scope: cdk.Construct, id: string, props: ApplicationListenerProps) { const [protocol, port] = determineProtocolAndPort(props.protocol, props.port); - super(parent, id, { + super(scope, id, { loadBalancerArn: props.loadBalancer.loadBalancerArn, certificates: new cdk.Token(() => this.certificateArns.map(certificateArn => ({ certificateArn }))), protocol, @@ -258,7 +258,7 @@ export class ApplicationListener extends BaseListener implements IApplicationLis /** * Properties to reference an existing listener */ -export interface IApplicationListener extends ec2.IConnectable, cdk.IDependable { +export interface IApplicationListener extends cdk.IConstruct, ec2.IConnectable, cdk.IDependable { /** * ARN of the listener */ @@ -332,8 +332,8 @@ class ImportedApplicationListener extends cdk.Construct implements IApplicationL */ public readonly listenerArn: string; - constructor(parent: cdk.Construct, id: string, private readonly props: ApplicationListenerImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: ApplicationListenerImportProps) { + super(scope, id); this.listenerArn = props.listenerArn; diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts index f3d1076ac023f..bddec5bac2bae 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts @@ -49,15 +49,15 @@ export class ApplicationLoadBalancer extends BaseLoadBalancer implements IApplic /** * Import an existing Application Load Balancer */ - public static import(parent: cdk.Construct, id: string, props: ApplicationLoadBalancerImportProps): IApplicationLoadBalancer { - return new ImportedApplicationLoadBalancer(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: ApplicationLoadBalancerImportProps): IApplicationLoadBalancer { + return new ImportedApplicationLoadBalancer(scope, id, props); } public readonly connections: ec2.Connections; private readonly securityGroup: ec2.ISecurityGroup; - constructor(parent: cdk.Construct, id: string, props: ApplicationLoadBalancerProps) { - super(parent, id, props, { + constructor(scope: cdk.Construct, id: string, props: ApplicationLoadBalancerProps) { + super(scope, id, props, { type: "application", securityGroups: new cdk.Token(() => [this.securityGroup.securityGroupId]), ipAddressType: props.ipAddressType, @@ -65,7 +65,7 @@ export class ApplicationLoadBalancer extends BaseLoadBalancer implements IApplic this.securityGroup = props.securityGroup || new ec2.SecurityGroup(this, 'SecurityGroup', { vpc: props.vpc, - description: `Automatically created Security Group for ELB ${this.uniqueId}`, + description: `Automatically created Security Group for ELB ${this.node.uniqueId}`, allowAllOutbound: false }); this.connections = new ec2.Connections({ securityGroups: [this.securityGroup] }); @@ -476,7 +476,7 @@ export enum HttpCodeTarget { /** * An application load balancer */ -export interface IApplicationLoadBalancer extends ec2.IConnectable { +export interface IApplicationLoadBalancer extends cdk.IConstruct, ec2.IConnectable { /** * The ARN of this load balancer */ @@ -557,8 +557,8 @@ class ImportedApplicationLoadBalancer extends cdk.Construct implements IApplicat */ public readonly vpc?: ec2.IVpcNetwork; - constructor(parent: cdk.Construct, id: string, private readonly props: ApplicationLoadBalancerImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: ApplicationLoadBalancerImportProps) { + super(scope, id); this.loadBalancerArn = props.loadBalancerArn; this.connections = new ec2.Connections({ diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-target-group.ts index d3786805de5db..58cef9303b9a0 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-target-group.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-target-group.ts @@ -66,17 +66,17 @@ export class ApplicationTargetGroup extends TargetGroupBase { /** * Import an existing target group */ - public static import(parent: cdk.Construct, id: string, props: TargetGroupImportProps): IApplicationTargetGroup { - return new ImportedApplicationTargetGroup(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: TargetGroupImportProps): IApplicationTargetGroup { + return new ImportedApplicationTargetGroup(scope, id, props); } private readonly connectableMembers: ConnectableMember[]; private readonly listeners: IApplicationListener[]; - constructor(parent: cdk.Construct, id: string, props: ApplicationTargetGroupProps) { + constructor(scope: cdk.Construct, id: string, props: ApplicationTargetGroupProps) { const [protocol, port] = determineProtocolAndPort(props.protocol, props.port); - super(parent, id, props, { + super(scope, id, props, { protocol, port, }); diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-listener.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-listener.ts index e6c5ecba109aa..63e25e704aedb 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-listener.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-listener.ts @@ -39,8 +39,8 @@ export class NetworkListener extends BaseListener implements INetworkListener { /** * Import an existing listener */ - public static import(parent: cdk.Construct, id: string, props: NetworkListenerImportProps): INetworkListener { - return new ImportedNetworkListener(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: NetworkListenerImportProps): INetworkListener { + return new ImportedNetworkListener(scope, id, props); } /** @@ -48,8 +48,8 @@ export class NetworkListener extends BaseListener implements INetworkListener { */ private readonly loadBalancer: INetworkLoadBalancer; - constructor(parent: cdk.Construct, id: string, props: NetworkListenerProps) { - super(parent, id, { + constructor(scope: cdk.Construct, id: string, props: NetworkListenerProps) { + super(scope, id, { loadBalancerArn: props.loadBalancer.loadBalancerArn, protocol: Protocol.Tcp, port: props.port, @@ -114,7 +114,7 @@ export class NetworkListener extends BaseListener implements INetworkListener { /** * Properties to reference an existing listener */ -export interface INetworkListener extends cdk.IDependable { +export interface INetworkListener extends cdk.IConstruct, cdk.IDependable { /** * ARN of the listener */ @@ -147,8 +147,8 @@ class ImportedNetworkListener extends cdk.Construct implements INetworkListener */ public readonly listenerArn: string; - constructor(parent: cdk.Construct, id: string, private readonly props: NetworkListenerImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: NetworkListenerImportProps) { + super(scope, id); this.listenerArn = props.listenerArn; } diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts index 8979ae96939f3..9dbba56279829 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-load-balancer.ts @@ -20,12 +20,12 @@ export interface NetworkLoadBalancerProps extends BaseLoadBalancerProps { * Define a new network load balancer */ export class NetworkLoadBalancer extends BaseLoadBalancer implements INetworkLoadBalancer { - public static import(parent: cdk.Construct, id: string, props: NetworkLoadBalancerImportProps): INetworkLoadBalancer { - return new ImportedNetworkLoadBalancer(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: NetworkLoadBalancerImportProps): INetworkLoadBalancer { + return new ImportedNetworkLoadBalancer(scope, id, props); } - constructor(parent: cdk.Construct, id: string, props: NetworkLoadBalancerProps) { - super(parent, id, props, { + constructor(scope: cdk.Construct, id: string, props: NetworkLoadBalancerProps) { + super(scope, id, props, { type: "network", }); @@ -187,7 +187,7 @@ export class NetworkLoadBalancer extends BaseLoadBalancer implements INetworkLoa /** * A network load balancer */ -export interface INetworkLoadBalancer { +export interface INetworkLoadBalancer extends cdk.IConstruct { /** * The ARN of this load balancer */ @@ -237,8 +237,8 @@ class ImportedNetworkLoadBalancer extends cdk.Construct implements INetworkLoadB */ public readonly vpc?: ec2.IVpcNetwork; - constructor(parent: cdk.Construct, id: string, private readonly props: NetworkLoadBalancerImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: NetworkLoadBalancerImportProps) { + super(scope, id); this.loadBalancerArn = props.loadBalancerArn; } diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-target-group.ts index 44ef15726bbd6..579009605f69e 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-target-group.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-target-group.ts @@ -39,14 +39,14 @@ export class NetworkTargetGroup extends TargetGroupBase { /** * Import an existing listener */ - public static import(parent: cdk.Construct, id: string, props: TargetGroupImportProps): INetworkTargetGroup { - return new ImportedNetworkTargetGroup(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: TargetGroupImportProps): INetworkTargetGroup { + return new ImportedNetworkTargetGroup(scope, id, props); } private readonly listeners: INetworkListener[]; - constructor(parent: cdk.Construct, id: string, props: NetworkTargetGroupProps) { - super(parent, id, props, { + constructor(scope: cdk.Construct, id: string, props: NetworkTargetGroupProps) { + super(scope, id, props, { protocol: Protocol.Tcp, port: props.port, }); diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-listener.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-listener.ts index 25cf2a2b506e0..a4043438529b8 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-listener.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-listener.ts @@ -10,8 +10,8 @@ export abstract class BaseListener extends cdk.Construct implements cdk.IDependa public readonly listenerArn: string; private readonly defaultActions: any[] = []; - constructor(parent: cdk.Construct, id: string, additionalProps: any) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, additionalProps: any) { + super(scope, id); const resource = new CfnListener(this, 'Resource', { ...additionalProps, diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts index 6d2fdc138bd85..a70ef98fcd4d2 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-load-balancer.ts @@ -93,8 +93,8 @@ export abstract class BaseLoadBalancer extends cdk.Construct implements route53. */ private readonly attributes: Attributes = {}; - constructor(parent: cdk.Construct, id: string, baseProps: BaseLoadBalancerProps, additionalProps: any) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, baseProps: BaseLoadBalancerProps, additionalProps: any) { + super(scope, id); const internetFacing = ifUndefined(baseProps.internetFacing, false); diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts index 5dc46928649ff..32cd72a8ad4a3 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts @@ -202,8 +202,8 @@ export abstract class TargetGroupBase extends cdk.Construct implements ITargetGr */ private readonly resource: CfnTargetGroup; - constructor(parent: cdk.Construct, id: string, baseProps: BaseTargetGroupProps, additionalProps: any) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, baseProps: BaseTargetGroupProps, additionalProps: any) { + super(scope, id); if (baseProps.deregistrationDelaySec !== undefined) { this.setAttribute('deregistration_delay.timeout_seconds', baseProps.deregistrationDelaySec.toString()); @@ -327,7 +327,7 @@ export interface TargetGroupImportProps { /** * A target group */ -export interface ITargetGroup { +export interface ITargetGroup extends cdk.IConstruct { /** * ARN of the target group */ diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/imported.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/imported.ts index 4449f667785c4..bf2a663ebc337 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/imported.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/imported.ts @@ -15,8 +15,8 @@ export abstract class ImportedTargetGroupBase extends cdk.Construct implements I */ public readonly loadBalancerArns: string; - constructor(parent: cdk.Construct, id: string, private readonly props: TargetGroupImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: TargetGroupImportProps) { + super(scope, id); this.targetGroupArn = props.targetGroupArn; this.loadBalancerArns = props.loadBalancerArns || new cdk.AwsNoValue().toString(); diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts index dc12141699132..2bc6f79866622 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts @@ -88,7 +88,7 @@ export = { }); // THEN - const errors = stack.validateTree(); + const errors = stack.node.validateTree(); test.deepEqual(errors.map(e => e.message), ['HTTPS Listener needs at least one certificate (call addCertificateArns)']); test.done(); diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/helpers.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/helpers.ts index 2b129f97c67e7..7f747e4893890 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/helpers.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/helpers.ts @@ -7,8 +7,8 @@ export class FakeSelfRegisteringTarget extends cdk.Construct implements elbv2.IA public readonly securityGroup: ec2.SecurityGroup; public readonly connections: ec2.Connections; - constructor(parent: cdk.Construct, id: string, vpc: ec2.VpcNetwork) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, vpc: ec2.VpcNetwork) { + super(scope, id); this.securityGroup = new ec2.SecurityGroup(this, 'SG', { vpc }); this.connections = new ec2.Connections({ securityGroups: [this.securityGroup] diff --git a/packages/@aws-cdk/aws-events/lib/rule-ref.ts b/packages/@aws-cdk/aws-events/lib/rule-ref.ts index 4bc2ebcb27398..fc7b9d8ab481b 100644 --- a/packages/@aws-cdk/aws-events/lib/rule-ref.ts +++ b/packages/@aws-cdk/aws-events/lib/rule-ref.ts @@ -1,3 +1,5 @@ +import { IConstruct } from '@aws-cdk/cdk'; + export interface EventRuleImportProps { /** * The value of the event rule Amazon Resource Name (ARN), such as @@ -6,7 +8,7 @@ export interface EventRuleImportProps { eventRuleArn: string; } -export interface IEventRule { +export interface IEventRule extends IConstruct { /** * The value of the event rule Amazon Resource Name (ARN), such as * arn:aws:events:us-east-2:123456789012:rule/example. diff --git a/packages/@aws-cdk/aws-events/lib/rule.ts b/packages/@aws-cdk/aws-events/lib/rule.ts index 85a989fcf27c3..b04ab872c860c 100644 --- a/packages/@aws-cdk/aws-events/lib/rule.ts +++ b/packages/@aws-cdk/aws-events/lib/rule.ts @@ -67,8 +67,8 @@ export class EventRule extends Construct implements IEventRule { /** * Imports a rule by ARN into this stack. */ - public static import(parent: Construct, name: string, props: EventRuleImportProps): IEventRule { - return new ImportedEventRule(parent, name, props); + public static import(scope: Construct, id: string, props: EventRuleImportProps): IEventRule { + return new ImportedEventRule(scope, id, props); } public readonly ruleArn: string; @@ -77,8 +77,8 @@ export class EventRule extends Construct implements IEventRule { private readonly eventPattern: EventPattern = { }; private scheduleExpression?: string; - constructor(parent: Construct, name: string, props: EventRuleProps = { }) { - super(parent, name); + constructor(scope: Construct, id: string, props: EventRuleProps = { }) { + super(scope, id); const resource = new CfnRule(this, 'Resource', { name: props.ruleName, @@ -117,7 +117,7 @@ export class EventRule extends Construct implements IEventRule { public addTarget(target?: IEventRuleTarget, inputOptions?: TargetInputTemplate) { if (!target) { return; } - const targetProps = target.asEventRuleTarget(this.ruleArn, this.uniqueId); + const targetProps = target.asEventRuleTarget(this.ruleArn, this.node.uniqueId); // check if a target with this ID already exists if (this.targets.find(t => t.id === targetProps.id)) { @@ -239,8 +239,8 @@ export class EventRule extends Construct implements IEventRule { class ImportedEventRule extends Construct implements IEventRule { public readonly ruleArn: string; - constructor(parent: Construct, id: string, private readonly props: EventRuleImportProps) { - super(parent, id); + constructor(scope: Construct, id: string, private readonly props: EventRuleImportProps) { + super(scope, id); this.ruleArn = props.eventRuleArn; } diff --git a/packages/@aws-cdk/aws-events/test/test.rule.ts b/packages/@aws-cdk/aws-events/test/test.rule.ts index dd638cd64e548..3e0001c455d9d 100644 --- a/packages/@aws-cdk/aws-events/test/test.rule.ts +++ b/packages/@aws-cdk/aws-events/test/test.rule.ts @@ -330,7 +330,7 @@ export = { rule.addTarget(t1); test.deepEqual(resolve(receivedRuleArn), resolve(rule.ruleArn)); - test.deepEqual(receivedRuleId, rule.uniqueId); + test.deepEqual(receivedRuleId, rule.node.uniqueId); test.done(); }, diff --git a/packages/@aws-cdk/aws-iam/lib/group.ts b/packages/@aws-cdk/aws-iam/lib/group.ts index 4f3cda702641f..7e68246eb7b1c 100644 --- a/packages/@aws-cdk/aws-iam/lib/group.ts +++ b/packages/@aws-cdk/aws-iam/lib/group.ts @@ -54,8 +54,8 @@ export class Group extends Construct implements IPrincipal { private readonly attachedPolicies = new AttachedPolicies(); private defaultPolicy?: Policy; - constructor(parent: Construct, name: string, props: GroupProps = {}) { - super(parent, name); + constructor(scope: Construct, id: string, props: GroupProps = {}) { + super(scope, id); this.managedPolicies = props.managedPolicyArns || []; diff --git a/packages/@aws-cdk/aws-iam/lib/lazy-role.ts b/packages/@aws-cdk/aws-iam/lib/lazy-role.ts index e9dcd7e160404..429c7fa4f14cd 100644 --- a/packages/@aws-cdk/aws-iam/lib/lazy-role.ts +++ b/packages/@aws-cdk/aws-iam/lib/lazy-role.ts @@ -1,7 +1,7 @@ import cdk = require('@aws-cdk/cdk'); import { Policy } from './policy'; import { PolicyPrincipal, PolicyStatement } from './policy-document'; -import { IRole, Role, RoleProps } from './role'; +import { IRole, Role, RoleImportProps, RoleProps } from './role'; /** * An IAM role that only gets attached to the construct tree once it gets used, not before @@ -18,8 +18,12 @@ export class LazyRole extends cdk.Construct implements IRole { private readonly policies = new Array(); private readonly managedPolicies = new Array(); - constructor(parent: cdk.Construct, id: string, private readonly props: RoleProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: RoleProps) { + super(scope, id); + } + + public export(): RoleImportProps { + return this.instantiate().export(); } /** @@ -73,6 +77,10 @@ export class LazyRole extends cdk.Construct implements IRole { return this.instantiate().roleArn; } + public get roleId(): string { + return this.instantiate().roleId; + } + /** * Returns a Principal object representing the ARN of this role. */ diff --git a/packages/@aws-cdk/aws-iam/lib/policy.ts b/packages/@aws-cdk/aws-iam/lib/policy.ts index 1857ddc866728..334d80205116c 100644 --- a/packages/@aws-cdk/aws-iam/lib/policy.ts +++ b/packages/@aws-cdk/aws-iam/lib/policy.ts @@ -103,8 +103,8 @@ export class Policy extends Construct implements IDependable { private readonly users = new Array(); private readonly groups = new Array(); - constructor(parent: Construct, name: string, props: PolicyProps = {}) { - super(parent, name); + constructor(scope: Construct, id: string, props: PolicyProps = {}) { + super(scope, id); const resource = new CfnPolicy(this, 'Resource', { policyDocument: this.document, diff --git a/packages/@aws-cdk/aws-iam/lib/role.ts b/packages/@aws-cdk/aws-iam/lib/role.ts index 63a81907e4576..11fb37a834529 100644 --- a/packages/@aws-cdk/aws-iam/lib/role.ts +++ b/packages/@aws-cdk/aws-iam/lib/role.ts @@ -1,4 +1,4 @@ -import { Construct, IDependable } from '@aws-cdk/cdk'; +import { Construct, IConstruct, IDependable, Output } from '@aws-cdk/cdk'; import { CfnRole } from './iam.generated'; import { IPrincipal, Policy } from './policy'; import { ArnPrincipal, PolicyDocument, PolicyPrincipal, PolicyStatement } from './policy-document'; @@ -94,8 +94,8 @@ export class Role extends Construct implements IRole { /** * Import a role that already exists */ - public static import(parent: Construct, id: string, props: ImportedRoleProps): IRole { - return new ImportedRole(parent, id, props); + public static import(scope: Construct, id: string, props: RoleImportProps): IRole { + return new ImportedRole(scope, id, props); } /** @@ -108,6 +108,12 @@ export class Role extends Construct implements IRole { */ public readonly roleArn: string; + /** + * Returns the stable and unique string identifying the role. For example, + * AIDAJQABLZS4A3QDU576Q. + */ + public readonly roleId: string; + /** * Returns the name of the role. */ @@ -127,8 +133,8 @@ export class Role extends Construct implements IRole { private readonly managedPolicyArns: string[]; private readonly attachedPolicies = new AttachedPolicies(); - constructor(parent: Construct, name: string, props: RoleProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: RoleProps) { + super(scope, id); this.assumeRolePolicy = createAssumeRolePolicy(props.assumedBy, props.externalId); this.managedPolicyArns = props.managedPolicyArns || [ ]; @@ -144,6 +150,7 @@ export class Role extends Construct implements IRole { maxSessionDuration: props.maxSessionDurationSec, }); + this.roleId = role.roleId; this.roleArn = role.roleArn; this.principal = new ArnPrincipal(this.roleArn); this.roleName = role.roleName; @@ -162,6 +169,13 @@ export class Role extends Construct implements IRole { } } + public export(): RoleImportProps { + return { + roleArn: new Output(this, 'RoleArn', { value: this.roleArn }).makeImportValue(), + roleId: new Output(this, 'RoleId', { value: this.roleId }).makeImportValue() + }; + } + /** * Adds a permission to the role's default policy document. * If there is no default policy attached to this role, it will be created. @@ -197,11 +211,22 @@ export class Role extends Construct implements IRole { /** * A Role object */ -export interface IRole extends IPrincipal, IDependable { +export interface IRole extends IConstruct, IPrincipal, IDependable { /** * Returns the ARN of this role. */ readonly roleArn: string; + + /** + * Returns the stable and unique string identifying the role. For example, + * AIDAJQABLZS4A3QDU576Q. + */ + readonly roleId: string; + + /** + * Export this role to another stack. + */ + export(): RoleImportProps; } function createAssumeRolePolicy(principal: PolicyPrincipal, externalId?: string) { @@ -230,11 +255,20 @@ function validateMaxSessionDuration(duration?: number) { /** * Properties to import a Role */ -export interface ImportedRoleProps { +export interface RoleImportProps { /** * The role's ARN */ roleArn: string; + + /** + * The stable and unique string identifying the role. For example, + * AIDAJQABLZS4A3QDU576Q. + * + * @default If "roleId" is not specified for an imported role, then + * `role.roleId` will throw an exception. In most cases, role ID is not really needed. + */ + roleId?: string; } /** @@ -245,12 +279,26 @@ class ImportedRole extends Construct implements IRole { public readonly principal: PolicyPrincipal; public readonly dependencyElements: IDependable[] = []; - constructor(parent: Construct, id: string, props: ImportedRoleProps) { - super(parent, id); + private readonly _roleId?: string; + + constructor(scope: Construct, id: string, private readonly props: RoleImportProps) { + super(scope, id); this.roleArn = props.roleArn; + this._roleId = props.roleId; this.principal = new ArnPrincipal(this.roleArn); } + public get roleId() { + if (!this._roleId) { + throw new Error(`No roleId specified for imported role`); + } + return this._roleId; + } + + public export() { + return this.props; + } + public addToPolicy(_statement: PolicyStatement): void { // FIXME: Add warning that we're ignoring this } diff --git a/packages/@aws-cdk/aws-iam/lib/user.ts b/packages/@aws-cdk/aws-iam/lib/user.ts index c2cc0c84faa1a..9ddca09349783 100644 --- a/packages/@aws-cdk/aws-iam/lib/user.ts +++ b/packages/@aws-cdk/aws-iam/lib/user.ts @@ -84,8 +84,8 @@ export class User extends Construct implements IPrincipal { private readonly attachedPolicies = new AttachedPolicies(); private defaultPolicy?: Policy; - constructor(parent: Construct, name: string, props: UserProps = {}) { - super(parent, name); + constructor(scope: Construct, id: string, props: UserProps = {}) { + super(scope, id); const user = new CfnUser(this, 'Resource', { userName: props.userName, diff --git a/packages/@aws-cdk/aws-iam/test/example.attaching.lit.ts b/packages/@aws-cdk/aws-iam/test/example.attaching.lit.ts index d59f7a9d2299a..78480ec54b3a8 100644 --- a/packages/@aws-cdk/aws-iam/test/example.attaching.lit.ts +++ b/packages/@aws-cdk/aws-iam/test/example.attaching.lit.ts @@ -2,8 +2,8 @@ import cdk = require('@aws-cdk/cdk'); import { Group, Policy, User } from '../lib'; export class ExampleConstruct extends cdk.Construct { - constructor(parent: cdk.Construct, id: string) { - super(parent, id); + constructor(scope: cdk.Construct, id: string) { + super(scope, id); /// !show const user = new User(this, 'MyUser', { password: '1234' }); diff --git a/packages/@aws-cdk/aws-iam/test/example.external-id.lit.ts b/packages/@aws-cdk/aws-iam/test/example.external-id.lit.ts index 879f16867f4eb..11f313559707b 100644 --- a/packages/@aws-cdk/aws-iam/test/example.external-id.lit.ts +++ b/packages/@aws-cdk/aws-iam/test/example.external-id.lit.ts @@ -2,8 +2,8 @@ import cdk = require('@aws-cdk/cdk'); import iam = require('../lib'); export class ExampleConstruct extends cdk.Construct { - constructor(parent: cdk.Construct, id: string) { - super(parent, id); + constructor(scope: cdk.Construct, id: string) { + super(scope, id); /// !show const role = new iam.Role(this, 'MyRole', { diff --git a/packages/@aws-cdk/aws-iam/test/example.managedpolicy.lit.ts b/packages/@aws-cdk/aws-iam/test/example.managedpolicy.lit.ts index 771081b0827ce..f05c5a2446bf2 100644 --- a/packages/@aws-cdk/aws-iam/test/example.managedpolicy.lit.ts +++ b/packages/@aws-cdk/aws-iam/test/example.managedpolicy.lit.ts @@ -2,8 +2,8 @@ import cdk = require('@aws-cdk/cdk'); import { Group } from '../lib'; export class ExampleConstruct extends cdk.Construct { - constructor(parent: cdk.Construct, id: string) { - super(parent, id); + constructor(scope: cdk.Construct, id: string) { + super(scope, id); /// !show const group = new Group(this, 'MyGroup'); diff --git a/packages/@aws-cdk/aws-iam/test/example.role.lit.ts b/packages/@aws-cdk/aws-iam/test/example.role.lit.ts index 3fe2b40ebbc58..1edbc98df4398 100644 --- a/packages/@aws-cdk/aws-iam/test/example.role.lit.ts +++ b/packages/@aws-cdk/aws-iam/test/example.role.lit.ts @@ -2,8 +2,8 @@ import cdk = require('@aws-cdk/cdk'); import { PolicyStatement, Role, ServicePrincipal } from '../lib'; export class ExampleConstruct extends cdk.Construct { - constructor(parent: cdk.Construct, id: string) { - super(parent, id); + constructor(scope: cdk.Construct, id: string) { + super(scope, id); /// !show const role = new Role(this, 'MyRole', { diff --git a/packages/@aws-cdk/aws-iam/test/integ.composite-principal.ts b/packages/@aws-cdk/aws-iam/test/integ.composite-principal.ts index 2d02a81300662..e8de39a7c300d 100644 --- a/packages/@aws-cdk/aws-iam/test/integ.composite-principal.ts +++ b/packages/@aws-cdk/aws-iam/test/integ.composite-principal.ts @@ -2,8 +2,8 @@ import cdk = require('@aws-cdk/cdk'); import iam = require('../lib'); class TestStack extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); new iam.Role(this, 'RoleWithCompositePrincipal', { assumedBy: new iam.CompositePrincipal( diff --git a/packages/@aws-cdk/aws-iam/test/test.role.ts b/packages/@aws-cdk/aws-iam/test/test.role.ts index 13302fea2077c..b78deac2bb514 100644 --- a/packages/@aws-cdk/aws-iam/test/test.role.ts +++ b/packages/@aws-cdk/aws-iam/test/test.role.ts @@ -1,5 +1,5 @@ import { expect, haveResource } from '@aws-cdk/assert'; -import { Resource, Stack } from '@aws-cdk/cdk'; +import { resolve, Resource, Stack } from '@aws-cdk/cdk'; import { Test } from 'nodeunit'; import { ArnPrincipal, CompositePrincipal, FederatedPrincipal, PolicyStatement, Role, ServicePrincipal } from '../lib'; @@ -235,6 +235,27 @@ export = { })); test.done(); - } + }, + 'import/export'(test: Test) { + // GIVEN + const stack = new Stack(); + const myRole = new Role(stack, 'MyRole', { + assumedBy: new ServicePrincipal('boom.boom.boom') + }); + + // WHEN + const exportedRole = myRole.export(); + const importedRole = Role.import(stack, 'ImportedRole', exportedRole); + + // THEN + test.deepEqual(resolve(exportedRole), { + roleArn: { 'Fn::ImportValue': 'MyRoleRoleArn3388B7E2' }, + roleId: { 'Fn::ImportValue': 'MyRoleRoleIdF7B258D8' } + }); + + test.deepEqual(resolve(importedRole.roleArn), { 'Fn::ImportValue': 'MyRoleRoleArn3388B7E2' }); + test.deepEqual(resolve(importedRole.roleId), { 'Fn::ImportValue': 'MyRoleRoleIdF7B258D8' }); + test.done(); + } }; diff --git a/packages/@aws-cdk/aws-iot1click/.npmignore b/packages/@aws-cdk/aws-iot1click/.npmignore index a38f4a5187806..aedb60356c270 100644 --- a/packages/@aws-cdk/aws-iot1click/.npmignore +++ b/packages/@aws-cdk/aws-iot1click/.npmignore @@ -15,4 +15,7 @@ dist .LAST_PACKAGE .jsii -*.snk \ No newline at end of file +*.snk + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/aws-iotanalytics/.npmignore b/packages/@aws-cdk/aws-iotanalytics/.npmignore index 0ed32f4a4a755..2895a406c8e61 100644 --- a/packages/@aws-cdk/aws-iotanalytics/.npmignore +++ b/packages/@aws-cdk/aws-iotanalytics/.npmignore @@ -15,3 +15,7 @@ dist .LAST_BUILD .LAST_PACKAGE .jsii + + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/aws-kinesis/lib/stream.ts b/packages/@aws-cdk/aws-kinesis/lib/stream.ts index 01d272cf24cb4..4cdda2e39a634 100644 --- a/packages/@aws-cdk/aws-kinesis/lib/stream.ts +++ b/packages/@aws-cdk/aws-kinesis/lib/stream.ts @@ -4,7 +4,7 @@ import logs = require('@aws-cdk/aws-logs'); import cdk = require('@aws-cdk/cdk'); import { CfnStream } from './kinesis.generated'; -export interface IStream extends logs.ILogSubscriptionDestination { +export interface IStream extends cdk.IConstruct, logs.ILogSubscriptionDestination { /** * The ARN of the stream. */ @@ -235,7 +235,10 @@ export abstract class StreamBase extends cdk.Construct implements IStream { // Take some effort to construct a unique ID for the destination that is unique to the // combination of (stream, loggroup). - const uniqueId = new cdk.HashedAddressingScheme().allocateAddress([sourceLogGroupConstruct.path.replace('/', ''), sourceStack.env.account!]); + const uniqueId = new cdk.HashedAddressingScheme().allocateAddress([ + sourceLogGroupConstruct.node.path.replace('/', ''), + sourceStack.env.account! + ]); // The destination lives in the target account const dest = new logs.CrossAccountDestination(this, `CWLDestination${uniqueId}`, { @@ -312,13 +315,13 @@ export class Stream extends StreamBase { /** * Creates a Stream construct that represents an external stream. * - * @param parent The parent creating construct (usually `this`). - * @param name The construct's name. + * @param scope The parent creating construct (usually `this`). + * @param id The construct's name. * @param ref A `StreamAttributes` object. Can be obtained from a call to * `stream.export()`. */ - public static import(parent: cdk.Construct, name: string, props: StreamImportProps): IStream { - return new ImportedStream(parent, name, props); + public static import(scope: cdk.Construct, id: string, props: StreamImportProps): IStream { + return new ImportedStream(scope, id, props); } public readonly streamArn: string; @@ -327,8 +330,8 @@ export class Stream extends StreamBase { private readonly stream: CfnStream; - constructor(parent: cdk.Construct, name: string, props: StreamProps = {}) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: StreamProps = {}) { + super(scope, id); const shardCount = props.shardCount || 1; const retentionPeriodHours = props.retentionPeriodHours || 24; @@ -348,7 +351,7 @@ export class Stream extends StreamBase { this.streamName = this.stream.streamId; this.encryptionKey = encryptionKey; - if (props.streamName) { this.addMetadata('aws:cdk:hasPhysicalName', props.streamName); } + if (props.streamName) { this.node.addMetadata('aws:cdk:hasPhysicalName', props.streamName); } } /** @@ -384,7 +387,7 @@ export class Stream extends StreamBase { if (encryptionType === StreamEncryption.Kms) { const encryptionKey = props.encryptionKey || new kms.EncryptionKey(this, 'Key', { - description: `Created by ${this.path}` + description: `Created by ${this.node.path}` }); const streamEncryption: CfnStream.StreamEncryptionProperty = { @@ -419,8 +422,8 @@ class ImportedStream extends StreamBase { public readonly streamName: string; public readonly encryptionKey?: kms.IEncryptionKey; - constructor(parent: cdk.Construct, name: string, private readonly props: StreamImportProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, private readonly props: StreamImportProps) { + super(scope, id); this.streamArn = props.streamArn; @@ -428,7 +431,8 @@ class ImportedStream extends StreamBase { this.streamName = cdk.ArnUtils.parse(props.streamArn).resourceName!; if (props.encryptionKey) { - this.encryptionKey = kms.EncryptionKey.import(parent, 'Key', props.encryptionKey); + // TODO: import "scope" should be changed to "this" + this.encryptionKey = kms.EncryptionKey.import(scope, 'Key', props.encryptionKey); } else { this.encryptionKey = undefined; } diff --git a/packages/@aws-cdk/aws-kms/lib/alias.ts b/packages/@aws-cdk/aws-kms/lib/alias.ts index dcb810b32de2c..d0a522a0b9748 100644 --- a/packages/@aws-cdk/aws-kms/lib/alias.ts +++ b/packages/@aws-cdk/aws-kms/lib/alias.ts @@ -36,8 +36,8 @@ export class EncryptionKeyAlias extends Construct { */ public aliasName: string; - constructor(parent: Construct, name: string, props: EncryptionKeyAliasProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: EncryptionKeyAliasProps) { + super(scope, id); if (!props.alias.startsWith(REQUIRED_ALIAS_PREFIX)) { throw new Error(`Alias must start with the prefix "${REQUIRED_ALIAS_PREFIX}": ${props.alias}`); diff --git a/packages/@aws-cdk/aws-kms/lib/key.ts b/packages/@aws-cdk/aws-kms/lib/key.ts index 5bd50a5d531a5..e55deee0ccb85 100644 --- a/packages/@aws-cdk/aws-kms/lib/key.ts +++ b/packages/@aws-cdk/aws-kms/lib/key.ts @@ -1,9 +1,9 @@ import { PolicyDocument, PolicyStatement } from '@aws-cdk/aws-iam'; -import { Construct, DeletionPolicy, Output, resolve } from '@aws-cdk/cdk'; +import { Construct, DeletionPolicy, IConstruct, Output, resolve } from '@aws-cdk/cdk'; import { EncryptionKeyAlias } from './alias'; import { CfnKey } from './kms.generated'; -export interface IEncryptionKey { +export interface IEncryptionKey extends IConstruct { /** * The ARN of the key. */ @@ -126,19 +126,19 @@ export class EncryptionKey extends EncryptionKeyBase { * keyArn: new KeyArn('arn:aws:kms:...') * }); * - * @param parent The parent construct. - * @param name The name of the construct. + * @param scope The parent construct. + * @param id The name of the construct. * @param props The key reference. */ - public static import(parent: Construct, name: string, props: EncryptionKeyImportProps): IEncryptionKey { - return new ImportedEncryptionKey(parent, name, props); + public static import(scope: Construct, id: string, props: EncryptionKeyImportProps): IEncryptionKey { + return new ImportedEncryptionKey(scope, id, props); } public readonly keyArn: string; protected readonly policy?: PolicyDocument; - constructor(parent: Construct, name: string, props: EncryptionKeyProps = {}) { - super(parent, name); + constructor(scope: Construct, id: string, props: EncryptionKeyProps = {}) { + super(scope, id); if (props.policy) { this.policy = props.policy; @@ -199,8 +199,8 @@ class ImportedEncryptionKey extends EncryptionKeyBase { public readonly keyArn: string; protected readonly policy = undefined; // no policy associated with an imported key - constructor(parent: Construct, name: string, private readonly props: EncryptionKeyImportProps) { - super(parent, name); + constructor(scope: Construct, id: string, private readonly props: EncryptionKeyImportProps) { + super(scope, id); this.keyArn = props.keyArn; } diff --git a/packages/@aws-cdk/aws-lambda-event-sources/lib/sqs.ts b/packages/@aws-cdk/aws-lambda-event-sources/lib/sqs.ts index faf7576047f68..a02dd4fb430fb 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/lib/sqs.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/lib/sqs.ts @@ -25,7 +25,7 @@ export class SqsEventSource implements lambda.IEventSource { } public bind(target: lambda.FunctionBase) { - new lambda.EventSourceMapping(target, `SqsEventSource:${this.queue.uniqueId}`, { + new lambda.EventSourceMapping(target, `SqsEventSource:${this.queue.node.uniqueId}`, { target, batchSize: this.props.batchSize, eventSourceArn: this.queue.queueArn, diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.s3.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.s3.ts index 9ab93f1884993..e94a832cf3a13 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.s3.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.s3.ts @@ -4,8 +4,8 @@ import { S3EventSource } from '../lib'; import { TestFunction } from './test-function'; class S3EventSourceTest extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); const fn = new TestFunction(this, 'F'); const bucket = new s3.Bucket(this, 'B', { diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.sns.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.sns.ts index 790b4bcc265e8..261f825611a5b 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.sns.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.sns.ts @@ -4,8 +4,8 @@ import { SnsEventSource } from '../lib'; import { TestFunction } from './test-function'; class SqsEventSourceTest extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); const fn = new TestFunction(this, 'F'); const topic = new sns.Topic(this, 'T'); diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.sqs.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.sqs.ts index 77ab3556b5d2a..42f5157b60af8 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/integ.sqs.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/integ.sqs.ts @@ -4,8 +4,8 @@ import { SqsEventSource } from '../lib'; import { TestFunction } from './test-function'; class SqsEventSourceTest extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); const fn = new TestFunction(this, 'F'); const queue = new sqs.Queue(this, 'Q'); diff --git a/packages/@aws-cdk/aws-lambda-event-sources/test/test-function.ts b/packages/@aws-cdk/aws-lambda-event-sources/test/test-function.ts index 962f2929bc7e6..b3ba0c456cfcd 100644 --- a/packages/@aws-cdk/aws-lambda-event-sources/test/test-function.ts +++ b/packages/@aws-cdk/aws-lambda-event-sources/test/test-function.ts @@ -2,8 +2,8 @@ import lambda = require('@aws-cdk/aws-lambda'); import cdk = require('@aws-cdk/cdk'); export class TestFunction extends lambda.Function { - constructor(parent: cdk.Construct, id: string) { - super(parent, id, { + constructor(scope: cdk.Construct, id: string) { + super(scope, id, { handler: 'index.handler', code: lambda.Code.inline(`exports.handler = ${handler.toString()}`), runtime: lambda.Runtime.NodeJS810 diff --git a/packages/@aws-cdk/aws-lambda/lib/alias.ts b/packages/@aws-cdk/aws-lambda/lib/alias.ts index a1d728b3b87c3..afe95955754cd 100644 --- a/packages/@aws-cdk/aws-lambda/lib/alias.ts +++ b/packages/@aws-cdk/aws-lambda/lib/alias.ts @@ -80,8 +80,8 @@ export class Alias extends FunctionBase { */ private readonly underlyingLambda: IFunction; - constructor(parent: cdk.Construct, id: string, props: AliasProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: AliasProps) { + super(scope, id); this.underlyingLambda = props.version.lambda; diff --git a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts index 784777c1218f7..c619efdfad891 100644 --- a/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts +++ b/packages/@aws-cdk/aws-lambda/lib/event-source-mapping.ts @@ -55,8 +55,8 @@ export interface EventSourceMappingProps { * modify the Lambda's execution role so it can consume messages from the queue. */ export class EventSourceMapping extends cdk.Construct { - constructor(parent: cdk.Construct, id: string, props: EventSourceMappingProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: EventSourceMappingProps) { + super(scope, id); new CfnEventSourceMapping(this, 'Resource', { batchSize: props.batchSize, diff --git a/packages/@aws-cdk/aws-lambda/lib/lambda-ref.ts b/packages/@aws-cdk/aws-lambda/lib/lambda-ref.ts index 5f4f1f7d621a8..ae954a9db205c 100644 --- a/packages/@aws-cdk/aws-lambda/lib/lambda-ref.ts +++ b/packages/@aws-cdk/aws-lambda/lib/lambda-ref.ts @@ -12,7 +12,7 @@ import { CfnPermission } from './lambda.generated'; import { Permission } from './permission'; import { CommonPipelineInvokeActionProps, PipelineInvokeAction } from './pipeline-action'; -export interface IFunction extends events.IEventRuleTarget, logs.ILogSubscriptionDestination, +export interface IFunction extends cdk.IConstruct, events.IEventRuleTarget, logs.ILogSubscriptionDestination, s3n.IBucketNotificationDestination, ec2.IConnectable, stepfunctions.IStepFunctionsTaskResource { /** @@ -193,6 +193,10 @@ export abstract class FunctionBase extends cdk.Construct implements IFunction { }); } + public get id() { + return this.node.id; + } + /** * Convenience method for creating a new {@link PipelineInvokeAction}, * and adding it to the given Stage. @@ -246,7 +250,7 @@ export abstract class FunctionBase extends cdk.Construct implements IFunction { */ public asEventRuleTarget(ruleArn: string, ruleId: string): events.EventRuleTargetProps { const permissionId = `AllowEventRule${ruleId}`; - if (!this.tryFindChild(permissionId)) { + if (!this.node.tryFindChild(permissionId)) { this.addPermission(permissionId, { action: 'lambda:InvokeFunction', principal: new iam.ServicePrincipal('events.amazonaws.com'), @@ -255,7 +259,7 @@ export abstract class FunctionBase extends cdk.Construct implements IFunction { } return { - id: this.id, + id: this.node.id, arn: this.functionArn, }; } @@ -347,7 +351,7 @@ export abstract class FunctionBase extends cdk.Construct implements IFunction { */ public asBucketNotificationDestination(bucketArn: string, bucketId: string): s3n.BucketNotificationDestinationProps { const permissionId = `AllowBucketNotificationsFrom${bucketId}`; - if (!this.tryFindChild(permissionId)) { + if (!this.node.tryFindChild(permissionId)) { this.addPermission(permissionId, { sourceAccount: new cdk.AwsAccountId().toString(), principal: new iam.ServicePrincipal('s3.amazonaws.com'), @@ -357,7 +361,7 @@ export abstract class FunctionBase extends cdk.Construct implements IFunction { // if we have a permission resource for this relationship, add it as a dependency // to the bucket notifications resource, so it will be created first. - const permission = this.tryFindChild(permissionId) as cdk.Resource; + const permission = this.node.tryFindChild(permissionId) as cdk.Resource; return { type: s3n.BucketNotificationDestinationType.Lambda, diff --git a/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts b/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts index 652f91442e77d..015513bc92317 100644 --- a/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts +++ b/packages/@aws-cdk/aws-lambda/lib/lambda-version.ts @@ -55,8 +55,8 @@ export class Version extends Construct { */ public readonly lambda: IFunction; - constructor(parent: Construct, id: string, props: VersionProps) { - super(parent, id); + constructor(scope: Construct, id: string, props: VersionProps) { + super(scope, id); const version = new CfnVersion(this, 'Resource', { codeSha256: props.codeSha256, diff --git a/packages/@aws-cdk/aws-lambda/lib/lambda.ts b/packages/@aws-cdk/aws-lambda/lib/lambda.ts index 34e52e03b09be..22536616043b9 100644 --- a/packages/@aws-cdk/aws-lambda/lib/lambda.ts +++ b/packages/@aws-cdk/aws-lambda/lib/lambda.ts @@ -194,11 +194,11 @@ export class Function extends FunctionBase { * * @param parent The parent construct * @param id The name of the lambda construct - * @param attrs A reference to a Lambda function. Can be created manually (see + * @param props A reference to a Lambda function. Can be created manually (see * example above) or obtained through a call to `lambda.export()`. */ - public static import(parent: cdk.Construct, id: string, attrs: FunctionImportProps): IFunction { - return new ImportedFunction(parent, id, attrs); + public static import(scope: cdk.Construct, id: string, props: FunctionImportProps): IFunction { + return new ImportedFunction(scope, id, props); } /** @@ -303,8 +303,8 @@ export class Function extends FunctionBase { */ private readonly environment?: { [key: string]: any }; - constructor(parent: cdk.Construct, id: string, props: FunctionProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: FunctionProps) { + super(scope, id); this.environment = props.environment || { }; @@ -432,7 +432,7 @@ export class Function extends FunctionBase { const securityGroup = props.securityGroup || new ec2.SecurityGroup(this, 'SecurityGroup', { vpc: props.vpc, - description: 'Automatic security group for Lambda Function ' + this.uniqueId, + description: 'Automatic security group for Lambda Function ' + this.node.uniqueId, allowAllOutbound: props.allowAllOutbound }); @@ -497,8 +497,8 @@ export class ImportedFunction extends FunctionBase { protected readonly canCreatePermissions = false; - constructor(parent: cdk.Construct, id: string, private readonly props: FunctionImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: FunctionImportProps) { + super(scope, id); this.functionArn = props.functionArn; this.functionName = extractNameFromArn(props.functionArn); diff --git a/packages/@aws-cdk/aws-lambda/lib/pipeline-action.ts b/packages/@aws-cdk/aws-lambda/lib/pipeline-action.ts index 256c7c0d8f4d6..ac14ea505feb0 100644 --- a/packages/@aws-cdk/aws-lambda/lib/pipeline-action.ts +++ b/packages/@aws-cdk/aws-lambda/lib/pipeline-action.ts @@ -81,8 +81,8 @@ export interface PipelineInvokeActionProps extends CommonPipelineInvokeActionPro * @see https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-invoke-lambda-function.html */ export class PipelineInvokeAction extends codepipeline.Action { - constructor(parent: cdk.Construct, name: string, props: PipelineInvokeActionProps) { - super(parent, name, { + constructor(scope: cdk.Construct, id: string, props: PipelineInvokeActionProps) { + super(scope, id, { stage: props.stage, runOrder: props.runOrder, category: codepipeline.ActionCategory.Invoke, diff --git a/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts b/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts index 8f5abe4b9eb7e..ff65d1f66565c 100644 --- a/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts +++ b/packages/@aws-cdk/aws-lambda/lib/singleton-lambda.ts @@ -41,8 +41,8 @@ export class SingletonFunction extends FunctionBase { protected readonly canCreatePermissions: boolean; private lambdaFunction: IFunction; - constructor(parent: cdk.Construct, name: string, props: SingletonFunctionProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: SingletonFunctionProps) { + super(scope, id); this.lambdaFunction = this.ensureLambda(props); @@ -64,7 +64,7 @@ export class SingletonFunction extends FunctionBase { private ensureLambda(props: SingletonFunctionProps): IFunction { const constructName = (props.lambdaPurpose || 'SingletonLambda') + slugify(props.uuid); const stack = cdk.Stack.find(this); - const existing = stack.tryFindChild(constructName); + const existing = stack.node.tryFindChild(constructName); if (existing) { // Just assume this is true return existing as FunctionBase; diff --git a/packages/@aws-cdk/aws-lambda/test/integ.assets.file.ts b/packages/@aws-cdk/aws-lambda/test/integ.assets.file.ts index d6b2bfdd034e4..e9ad0745198cc 100644 --- a/packages/@aws-cdk/aws-lambda/test/integ.assets.file.ts +++ b/packages/@aws-cdk/aws-lambda/test/integ.assets.file.ts @@ -3,8 +3,8 @@ import path = require('path'); import lambda = require('../lib'); class TestStack extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); /// !show new lambda.Function(this, 'MyLambda', { diff --git a/packages/@aws-cdk/aws-lambda/test/integ.assets.lit.ts b/packages/@aws-cdk/aws-lambda/test/integ.assets.lit.ts index e63168562c226..56c3eab4a86bd 100644 --- a/packages/@aws-cdk/aws-lambda/test/integ.assets.lit.ts +++ b/packages/@aws-cdk/aws-lambda/test/integ.assets.lit.ts @@ -3,8 +3,8 @@ import path = require('path'); import lambda = require('../lib'); class TestStack extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); /// !show new lambda.Function(this, 'MyLambda', { diff --git a/packages/@aws-cdk/aws-lambda/test/test.code.ts b/packages/@aws-cdk/aws-lambda/test/test.code.ts index d9d58efd39b08..ea08dd02d83e3 100644 --- a/packages/@aws-cdk/aws-lambda/test/test.code.ts +++ b/packages/@aws-cdk/aws-lambda/test/test.code.ts @@ -73,7 +73,7 @@ export = { 'adds code asset metadata'(test: Test) { // GIVEN const stack = new cdk.Stack(); - stack.setContext(cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT, true); + stack.node.setContext(cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT, true); const location = path.join(__dirname, 'my-lambda-handler'); @@ -110,4 +110,4 @@ function generateRandomString(bytes: number) { s += String.fromCharCode(Math.round(Math.random() * 256)); } return s; -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/aws-lambda/test/test.lambda.ts b/packages/@aws-cdk/aws-lambda/test/test.lambda.ts index 38c6a81a4c21e..e1f8e4526013b 100644 --- a/packages/@aws-cdk/aws-lambda/test/test.lambda.ts +++ b/packages/@aws-cdk/aws-lambda/test/test.lambda.ts @@ -1124,8 +1124,8 @@ export = { } }; -function newTestLambda(parent: cdk.Construct) { - return new lambda.Function(parent, 'MyLambda', { +function newTestLambda(scope: cdk.Construct) { + return new lambda.Function(scope, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'bar', runtime: lambda.Runtime.Python27 diff --git a/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts b/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts index 230775ab598a3..881f6e0769da0 100644 --- a/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts +++ b/packages/@aws-cdk/aws-logs/lib/cross-account-destination.ts @@ -56,8 +56,8 @@ export class CrossAccountDestination extends cdk.Construct implements ILogSubscr */ private readonly resource: CfnDestination; - constructor(parent: cdk.Construct, id: string, props: CrossAccountDestinationProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: CrossAccountDestinationProps) { + super(scope, id); // In the underlying model, the name is not optional, but we make it so anyway. const destinationName = props.destinationName || new cdk.Token(() => this.generateUniqueName()); diff --git a/packages/@aws-cdk/aws-logs/lib/log-group.ts b/packages/@aws-cdk/aws-logs/lib/log-group.ts index 29999317512dc..dec077a84d1b3 100644 --- a/packages/@aws-cdk/aws-logs/lib/log-group.ts +++ b/packages/@aws-cdk/aws-logs/lib/log-group.ts @@ -7,7 +7,7 @@ import { MetricFilter } from './metric-filter'; import { FilterPattern, IFilterPattern } from './pattern'; import { ILogSubscriptionDestination, SubscriptionFilter } from './subscription-filter'; -export interface ILogGroup { +export interface ILogGroup extends cdk.IConstruct { /** * The ARN of this log group */ @@ -21,29 +21,29 @@ export interface ILogGroup { /** * Create a new Log Stream for this Log Group * - * @param parent Parent construct + * @param scope Parent construct * @param id Unique identifier for the construct in its parent * @param props Properties for creating the LogStream */ - newStream(parent: cdk.Construct, id: string, props?: NewLogStreamProps): LogStream; + newStream(scope: cdk.Construct, id: string, props?: NewLogStreamProps): LogStream; /** * Create a new Subscription Filter on this Log Group * - * @param parent Parent construct + * @param scope Parent construct * @param id Unique identifier for the construct in its parent * @param props Properties for creating the SubscriptionFilter */ - newSubscriptionFilter(parent: cdk.Construct, id: string, props: NewSubscriptionFilterProps): SubscriptionFilter; + newSubscriptionFilter(scope: cdk.Construct, id: string, props: NewSubscriptionFilterProps): SubscriptionFilter; /** * Create a new Metric Filter on this Log Group * - * @param parent Parent construct + * @param scope Parent construct * @param id Unique identifier for the construct in its parent * @param props Properties for creating the MetricFilter */ - newMetricFilter(parent: cdk.Construct, id: string, props: NewMetricFilterProps): MetricFilter; + newMetricFilter(scope: cdk.Construct, id: string, props: NewMetricFilterProps): MetricFilter; /** * Export this LogGroup @@ -101,12 +101,12 @@ export abstract class LogGroupBase extends cdk.Construct implements ILogGroup { /** * Create a new Log Stream for this Log Group * - * @param parent Parent construct + * @param scope Parent construct * @param id Unique identifier for the construct in its parent * @param props Properties for creating the LogStream */ - public newStream(parent: cdk.Construct, id: string, props: NewLogStreamProps = {}): LogStream { - return new LogStream(parent, id, { + public newStream(scope: cdk.Construct, id: string, props: NewLogStreamProps = {}): LogStream { + return new LogStream(scope, id, { logGroup: this, ...props }); @@ -115,12 +115,12 @@ export abstract class LogGroupBase extends cdk.Construct implements ILogGroup { /** * Create a new Subscription Filter on this Log Group * - * @param parent Parent construct + * @param scope Parent construct * @param id Unique identifier for the construct in its parent * @param props Properties for creating the SubscriptionFilter */ - public newSubscriptionFilter(parent: cdk.Construct, id: string, props: NewSubscriptionFilterProps): SubscriptionFilter { - return new SubscriptionFilter(parent, id, { + public newSubscriptionFilter(scope: cdk.Construct, id: string, props: NewSubscriptionFilterProps): SubscriptionFilter { + return new SubscriptionFilter(scope, id, { logGroup: this, ...props }); @@ -129,12 +129,12 @@ export abstract class LogGroupBase extends cdk.Construct implements ILogGroup { /** * Create a new Metric Filter on this Log Group * - * @param parent Parent construct + * @param scope Parent construct * @param id Unique identifier for the construct in its parent * @param props Properties for creating the MetricFilter */ - public newMetricFilter(parent: cdk.Construct, id: string, props: NewMetricFilterProps): MetricFilter { - return new MetricFilter(parent, id, { + public newMetricFilter(scope: cdk.Construct, id: string, props: NewMetricFilterProps): MetricFilter { + return new MetricFilter(scope, id, { logGroup: this, ...props }); @@ -229,8 +229,8 @@ export class LogGroup extends LogGroupBase { /** * Import an existing LogGroup */ - public static import(parent: cdk.Construct, id: string, props: LogGroupImportProps): ILogGroup { - return new ImportedLogGroup(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: LogGroupImportProps): ILogGroup { + return new ImportedLogGroup(scope, id, props); } /** @@ -243,8 +243,8 @@ export class LogGroup extends LogGroupBase { */ public readonly logGroupName: string; - constructor(parent: cdk.Construct, id: string, props: LogGroupProps = {}) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: LogGroupProps = {}) { + super(scope, id); let retentionInDays = props.retentionDays; if (retentionInDays === undefined) { retentionInDays = 731; } @@ -291,8 +291,8 @@ class ImportedLogGroup extends LogGroupBase { */ public readonly logGroupName: string; - constructor(parent: cdk.Construct, id: string, private readonly props: LogGroupImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: LogGroupImportProps) { + super(scope, id); this.logGroupArn = props.logGroupArn; this.logGroupName = cdk.ArnUtils.resourceNameComponent(props.logGroupArn, ':'); diff --git a/packages/@aws-cdk/aws-logs/lib/log-stream.ts b/packages/@aws-cdk/aws-logs/lib/log-stream.ts index 33d6b36688192..e8ee08078233e 100644 --- a/packages/@aws-cdk/aws-logs/lib/log-stream.ts +++ b/packages/@aws-cdk/aws-logs/lib/log-stream.ts @@ -2,7 +2,7 @@ import cdk = require('@aws-cdk/cdk'); import { ILogGroup } from './log-group'; import { CfnLogStream } from './logs.generated'; -export interface ILogStream { +export interface ILogStream extends cdk.IConstruct { /** * The name of this log stream */ @@ -60,8 +60,8 @@ export class LogStream extends cdk.Construct implements ILogStream { /** * Import an existing LogGroup */ - public static import(parent: cdk.Construct, id: string, props: LogStreamImportProps): ILogStream { - return new ImportedLogStream(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: LogStreamImportProps): ILogStream { + return new ImportedLogStream(scope, id, props); } /** @@ -69,8 +69,8 @@ export class LogStream extends cdk.Construct implements ILogStream { */ public readonly logStreamName: string; - constructor(parent: cdk.Construct, id: string, props: LogStreamProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: LogStreamProps) { + super(scope, id); const resource = new CfnLogStream(this, 'Resource', { logGroupName: props.logGroup.logGroupName, @@ -103,8 +103,8 @@ class ImportedLogStream extends cdk.Construct implements ILogStream { */ public readonly logStreamName: string; - constructor(parent: cdk.Construct, id: string, private readonly props: LogStreamImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: LogStreamImportProps) { + super(scope, id); this.logStreamName = props.logStreamName; } diff --git a/packages/@aws-cdk/aws-logs/lib/metric-filter.ts b/packages/@aws-cdk/aws-logs/lib/metric-filter.ts index 797273e241613..b8cfb2832d1d7 100644 --- a/packages/@aws-cdk/aws-logs/lib/metric-filter.ts +++ b/packages/@aws-cdk/aws-logs/lib/metric-filter.ts @@ -56,8 +56,8 @@ export interface MetricFilterProps { * A filter that extracts information from CloudWatch Logs and emits to CloudWatch Metrics */ export class MetricFilter extends cdk.Construct { - constructor(parent: cdk.Construct, id: string, props: MetricFilterProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: MetricFilterProps) { + super(scope, id); // It looks odd to map this object to a singleton list, but that's how // we're supposed to do it according to the docs. diff --git a/packages/@aws-cdk/aws-logs/lib/subscription-filter.ts b/packages/@aws-cdk/aws-logs/lib/subscription-filter.ts index e85ee7986076c..f6c9528777e3f 100644 --- a/packages/@aws-cdk/aws-logs/lib/subscription-filter.ts +++ b/packages/@aws-cdk/aws-logs/lib/subscription-filter.ts @@ -64,8 +64,8 @@ export interface SubscriptionFilterProps { * A new Subscription on a CloudWatch log group. */ export class SubscriptionFilter extends cdk.Construct { - constructor(parent: cdk.Construct, id: string, props: SubscriptionFilterProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: SubscriptionFilterProps) { + super(scope, id); const destProps = props.destination.logSubscriptionDestination(props.logGroup); diff --git a/packages/@aws-cdk/aws-logs/test/integ.metricfilter.lit.ts b/packages/@aws-cdk/aws-logs/test/integ.metricfilter.lit.ts index 8b2966461a9db..1b48dce9e0e45 100644 --- a/packages/@aws-cdk/aws-logs/test/integ.metricfilter.lit.ts +++ b/packages/@aws-cdk/aws-logs/test/integ.metricfilter.lit.ts @@ -2,8 +2,8 @@ import { App, Stack, StackProps } from '@aws-cdk/cdk'; import { FilterPattern, LogGroup, MetricFilter } from '../lib'; class MetricFilterIntegStack extends Stack { - constructor(parent: App, name: string, props?: StackProps) { - super(parent, name, props); + constructor(scope: App, id: string, props?: StackProps) { + super(scope, id, props); const logGroup = new LogGroup(this, 'LogGroup', { retainLogGroup: false diff --git a/packages/@aws-cdk/aws-neptune/.npmignore b/packages/@aws-cdk/aws-neptune/.npmignore index a38f4a5187806..aedb60356c270 100644 --- a/packages/@aws-cdk/aws-neptune/.npmignore +++ b/packages/@aws-cdk/aws-neptune/.npmignore @@ -15,4 +15,7 @@ dist .LAST_PACKAGE .jsii -*.snk \ No newline at end of file +*.snk + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/aws-quickstarts/lib/database.ts b/packages/@aws-cdk/aws-quickstarts/lib/database.ts index 03c7c8e4aa788..4b142bb413c15 100644 --- a/packages/@aws-cdk/aws-quickstarts/lib/database.ts +++ b/packages/@aws-cdk/aws-quickstarts/lib/database.ts @@ -20,8 +20,8 @@ export class SqlServer extends cdk.Construct implements ec2.IConnectable { private static readonly PORT = 1433; public readonly connections: ec2.Connections; - constructor(parent: cdk.Construct, name: string, props: SqlServerProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: SqlServerProps) { + super(scope, id); const securityGroup = new ec2.SecurityGroup(this, 'SecurityGroup', { vpc: props.vpc, diff --git a/packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts b/packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts index 0855618af1117..4d959b272138a 100644 --- a/packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts +++ b/packages/@aws-cdk/aws-quickstarts/lib/rdgw.ts @@ -24,8 +24,8 @@ export class RemoteDesktopGateway extends cdk.Construct implements ec2.IConnecta private static readonly PORT = 3389; public readonly connections: ec2.Connections; - constructor(parent: cdk.Construct, name: string, props: RemoteDesktopGatewayProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: RemoteDesktopGatewayProps) { + super(scope, id); const params: any = { RDGWCIDR: props.rdgwCIDR, diff --git a/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group-ref.ts b/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group-ref.ts new file mode 100644 index 0000000000000..2acc2fc5a1940 --- /dev/null +++ b/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group-ref.ts @@ -0,0 +1,46 @@ +import cdk = require('@aws-cdk/cdk'); + +/** + * A cluster parameter group + */ +export abstract class ClusterParameterGroupRef extends cdk.Construct { + /** + * Import a parameter group + */ + public static import(scope: cdk.Construct, id: string, props: ClusterParameterGroupRefProps): ClusterParameterGroupRef { + return new ImportedClusterParameterGroup(scope, id, props); + } + + /** + * Name of this parameter group + */ + public abstract readonly parameterGroupName: string; + + /** + * Export this parameter group + */ + public export(): ClusterParameterGroupRefProps { + return { + parameterGroupName: new cdk.Output(this, 'ParameterGroupName', { value: this.parameterGroupName }).makeImportValue().toString() + }; + } +} + +/** + * Properties to reference a cluster parameter group + */ +export interface ClusterParameterGroupRefProps { + parameterGroupName: string; +} + +/** + * An imported cluster parameter group + */ +class ImportedClusterParameterGroup extends ClusterParameterGroupRef { + public readonly parameterGroupName: string; + + constructor(scope: cdk.Construct, id: string, props: ClusterParameterGroupRefProps) { + super(scope, id); + this.parameterGroupName = props.parameterGroupName; + } +} diff --git a/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group.ts b/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group.ts index d5b35b3553beb..59d0c1afb2441 100644 --- a/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group.ts +++ b/packages/@aws-cdk/aws-rds/lib/cluster-parameter-group.ts @@ -5,7 +5,7 @@ import { CfnDBClusterParameterGroup } from './rds.generated'; /** * A cluster parameter group */ -export interface IClusterParameterGroup { +export interface IClusterParameterGroup extends cdk.IConstruct { /** * Name of this parameter group */ @@ -51,15 +51,15 @@ export class ClusterParameterGroup extends cdk.Construct implements IClusterPara /** * Import a parameter group */ - public static import(parent: cdk.Construct, id: string, props: ClusterParameterGroupImportProps): IClusterParameterGroup { - return new ImportedClusterParameterGroup(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: ClusterParameterGroupImportProps): IClusterParameterGroup { + return new ImportedClusterParameterGroup(scope, id, props); } public readonly parameterGroupName: string; private readonly parameters: Parameters = {}; - constructor(parent: cdk.Construct, id: string, props: ClusterParameterGroupProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: ClusterParameterGroupProps) { + super(scope, id); const resource = new CfnDBClusterParameterGroup(this, 'Resource', { description: props.description, @@ -119,8 +119,8 @@ export class ClusterParameterGroup extends cdk.Construct implements IClusterPara class ImportedClusterParameterGroup extends cdk.Construct implements IClusterParameterGroup { public readonly parameterGroupName: string; - constructor(parent: cdk.Construct, id: string, private readonly props: ClusterParameterGroupImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: ClusterParameterGroupImportProps) { + super(scope, id); this.parameterGroupName = props.parameterGroupName; } diff --git a/packages/@aws-cdk/aws-rds/lib/cluster-ref.ts b/packages/@aws-cdk/aws-rds/lib/cluster-ref.ts index 4e4c8a4766c39..3a6803c587ecb 100644 --- a/packages/@aws-cdk/aws-rds/lib/cluster-ref.ts +++ b/packages/@aws-cdk/aws-rds/lib/cluster-ref.ts @@ -1,9 +1,10 @@ import ec2 = require('@aws-cdk/aws-ec2'); +import cdk = require('@aws-cdk/cdk'); /** * Create a clustered database with a given number of instances. */ -export interface IDatabaseCluster extends ec2.IConnectable { +export interface IDatabaseCluster extends cdk.IConstruct, ec2.IConnectable { /** * Identifier of the cluster */ diff --git a/packages/@aws-cdk/aws-rds/lib/cluster.ts b/packages/@aws-cdk/aws-rds/lib/cluster.ts index 0b92b2be67362..aca08f27055c0 100644 --- a/packages/@aws-cdk/aws-rds/lib/cluster.ts +++ b/packages/@aws-cdk/aws-rds/lib/cluster.ts @@ -97,8 +97,8 @@ export class DatabaseCluster extends cdk.Construct implements IDatabaseCluster { /** * Import an existing DatabaseCluster from properties */ - public static import(parent: cdk.Construct, name: string, props: DatabaseClusterImportProps): IDatabaseCluster { - return new ImportedDatabaseCluster(parent, name, props); + public static import(scope: cdk.Construct, id: string, props: DatabaseClusterImportProps): IDatabaseCluster { + return new ImportedDatabaseCluster(scope, id, props); } /** @@ -136,8 +136,8 @@ export class DatabaseCluster extends cdk.Construct implements IDatabaseCluster { */ public readonly securityGroupId: string; - constructor(parent: cdk.Construct, name: string, props: DatabaseClusterProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: DatabaseClusterProps) { + super(scope, id); const subnets = props.instanceProps.vpc.subnets(props.instanceProps.vpcPlacement); @@ -147,7 +147,7 @@ export class DatabaseCluster extends cdk.Construct implements IDatabaseCluster { } const subnetGroup = new CfnDBSubnetGroup(this, 'Subnets', { - dbSubnetGroupDescription: `Subnets for ${name} database`, + dbSubnetGroupDescription: `Subnets for ${id} database`, subnetIds: subnets.map(s => s.subnetId) }); @@ -292,8 +292,8 @@ class ImportedDatabaseCluster extends cdk.Construct implements IDatabaseCluster */ public readonly securityGroupId: string; - constructor(parent: cdk.Construct, name: string, private readonly props: DatabaseClusterImportProps) { - super(parent, name); + constructor(scope: cdk.Construct, name: string, private readonly props: DatabaseClusterImportProps) { + super(scope, name); this.securityGroupId = props.securityGroupId; this.defaultPortRange = new ec2.TcpPortFromAttribute(props.port); diff --git a/packages/@aws-cdk/aws-rds/test/test.cluster.ts b/packages/@aws-cdk/aws-rds/test/test.cluster.ts index fad6e775c460a..841a6b2776d04 100644 --- a/packages/@aws-cdk/aws-rds/test/test.cluster.ts +++ b/packages/@aws-cdk/aws-rds/test/test.cluster.ts @@ -122,10 +122,28 @@ export = { test.done(); }, + + 'import/export cluster parameter group'(test: Test) { + // GIVEN + const stack = testStack(); + const group = new ClusterParameterGroup(stack, 'Params', { + family: 'hello', + description: 'desc' + }); + + // WHEN + const exported = group.export(); + const imported = ClusterParameterGroup.import(stack, 'ImportParams', exported); + + // THEN + test.deepEqual(cdk.resolve(exported), { parameterGroupName: { 'Fn::ImportValue': 'ParamsParameterGroupNameA6B808D7' } }); + test.deepEqual(cdk.resolve(imported.parameterGroupName), { 'Fn::ImportValue': 'ParamsParameterGroupNameA6B808D7' }); + test.done(); + } }; function testStack() { const stack = new cdk.Stack(undefined, undefined, { env: { account: '12345', region: 'us-test-1' }}); - stack.setContext('availability-zones:12345:us-test-1', ['us-test-1a', 'us-test-1b']); + stack.node.setContext('availability-zones:12345:us-test-1', ['us-test-1a', 'us-test-1b']); return stack; } diff --git a/packages/@aws-cdk/aws-route53/lib/hosted-zone-provider.ts b/packages/@aws-cdk/aws-route53/lib/hosted-zone-provider.ts index cb54ebe820ebf..c2f4d221e9724 100644 --- a/packages/@aws-cdk/aws-route53/lib/hosted-zone-provider.ts +++ b/packages/@aws-cdk/aws-route53/lib/hosted-zone-provider.ts @@ -40,8 +40,8 @@ export class HostedZoneProvider { /** * This method calls `findHostedZone` and returns the imported hosted zone */ - public findAndImport(parent: cdk.Construct, id: string): IHostedZone { - return HostedZone.import(parent, id, this.findHostedZone()); + public findAndImport(scope: cdk.Construct, id: string): IHostedZone { + return HostedZone.import(scope, id, this.findHostedZone()); } /** * Return the hosted zone meeting the filter diff --git a/packages/@aws-cdk/aws-route53/lib/hosted-zone-ref.ts b/packages/@aws-cdk/aws-route53/lib/hosted-zone-ref.ts index 25602d6132c05..a007f97db19d2 100644 --- a/packages/@aws-cdk/aws-route53/lib/hosted-zone-ref.ts +++ b/packages/@aws-cdk/aws-route53/lib/hosted-zone-ref.ts @@ -1,7 +1,9 @@ +import cdk = require('@aws-cdk/cdk'); + /** * Imported or created hosted zone */ -export interface IHostedZone { +export interface IHostedZone extends cdk.IConstruct { /** * ID of this hosted zone */ diff --git a/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts b/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts index d0c6579d9d907..a4b7c1e865ef2 100644 --- a/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts +++ b/packages/@aws-cdk/aws-route53/lib/hosted-zone.ts @@ -29,8 +29,8 @@ export interface PublicHostedZoneProps { } export abstract class HostedZone extends cdk.Construct implements IHostedZone { - public static import(parent: cdk.Construct, name: string, props: HostedZoneImportProps): IHostedZone { - return new ImportedHostedZone(parent, name, props); + public static import(scope: cdk.Construct, id: string, props: HostedZoneImportProps): IHostedZone { + return new ImportedHostedZone(scope, id, props); } public abstract readonly hostedZoneId: string; @@ -63,8 +63,8 @@ export class PublicHostedZone extends HostedZone { */ public readonly nameServers: HostedZoneNameServers; - constructor(parent: cdk.Construct, name: string, props: PublicHostedZoneProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: PublicHostedZoneProps) { + super(scope, id); validateZoneName(props.zoneName); @@ -110,8 +110,8 @@ export class PrivateHostedZone extends HostedZone { */ private readonly vpcs: CfnHostedZone.VPCProperty[] = []; - constructor(parent: cdk.Construct, name: string, props: PrivateHostedZoneProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: PrivateHostedZoneProps) { + super(scope, id); validateZoneName(props.zoneName); @@ -156,8 +156,8 @@ class ImportedHostedZone extends cdk.Construct implements IHostedZone { public readonly zoneName: string; - constructor(parent: cdk.Construct, name: string, private readonly props: HostedZoneImportProps) { - super(parent, name); + constructor(scope: cdk.Construct, name: string, private readonly props: HostedZoneImportProps) { + super(scope, name); this.hostedZoneId = props.hostedZoneId; this.zoneName = props.zoneName; diff --git a/packages/@aws-cdk/aws-route53/lib/records/alias.ts b/packages/@aws-cdk/aws-route53/lib/records/alias.ts index d861e8bd6caa0..ba892113e1478 100644 --- a/packages/@aws-cdk/aws-route53/lib/records/alias.ts +++ b/packages/@aws-cdk/aws-route53/lib/records/alias.ts @@ -49,8 +49,8 @@ export interface AliasRecordProps { * A Route53 alias record */ export class AliasRecord extends Construct { - constructor(parent: Construct, id: string, props: AliasRecordProps) { - super(parent, id); + constructor(scope: Construct, id: string, props: AliasRecordProps) { + super(scope, id); new CfnRecordSet(this, 'Resource', { hostedZoneId: props.zone.hostedZoneId, diff --git a/packages/@aws-cdk/aws-route53/lib/records/txt.ts b/packages/@aws-cdk/aws-route53/lib/records/txt.ts index 731b94e3d883a..b227e277e3dde 100644 --- a/packages/@aws-cdk/aws-route53/lib/records/txt.ts +++ b/packages/@aws-cdk/aws-route53/lib/records/txt.ts @@ -15,8 +15,8 @@ export interface TXTRecordProps { * A DNS TXT record */ export class TXTRecord extends Construct { - constructor(parent: Construct, name: string, props: TXTRecordProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: TXTRecordProps) { + super(scope, id); // JSON.stringify conveniently wraps strings in " and escapes ". const recordValue = JSON.stringify(props.recordValue); diff --git a/packages/@aws-cdk/aws-route53/lib/records/zone-delegation.ts b/packages/@aws-cdk/aws-route53/lib/records/zone-delegation.ts index 2b634634005e9..d29d84dd7dba3 100644 --- a/packages/@aws-cdk/aws-route53/lib/records/zone-delegation.ts +++ b/packages/@aws-cdk/aws-route53/lib/records/zone-delegation.ts @@ -37,8 +37,8 @@ export interface ZoneDelegationRecordProps { * A record to delegate further lookups to a different set of name servers */ export class ZoneDelegationRecord extends Construct { - constructor(parent: Construct, name: string, props: ZoneDelegationRecordProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: ZoneDelegationRecordProps) { + super(scope, id); const ttl = props.ttl === undefined ? 172_800 : props.ttl; diff --git a/packages/@aws-cdk/aws-route53/test/test.hosted-zone-provider.ts b/packages/@aws-cdk/aws-route53/test/test.hosted-zone-provider.ts index 202710d47b9ad..c22c49cbedd79 100644 --- a/packages/@aws-cdk/aws-route53/test/test.hosted-zone-provider.ts +++ b/packages/@aws-cdk/aws-route53/test/test.hosted-zone-provider.ts @@ -22,7 +22,7 @@ export = { ResourceRecordSetCount: 3 }; - stack.setContext(key, fakeZone); + stack.node.setContext(key, fakeZone); const cdkZoneProps: HostedZoneImportProps = { hostedZoneId: fakeZone.Id, diff --git a/packages/@aws-cdk/aws-route53/test/test.route53.ts b/packages/@aws-cdk/aws-route53/test/test.route53.ts index 7cb0c53c9c687..3a18465c1ff03 100644 --- a/packages/@aws-cdk/aws-route53/test/test.route53.ts +++ b/packages/@aws-cdk/aws-route53/test/test.route53.ts @@ -120,7 +120,7 @@ class TestApp { constructor() { const account = '123456789012'; const region = 'bermuda-triangle'; - this.app.setContext(`availability-zones:${account}:${region}`, + this.app.node.setContext(`availability-zones:${account}:${region}`, [`${region}-1a`]); this.stack = new cdk.Stack(this.app, 'MyStack', { env: { account, region } }); } diff --git a/packages/@aws-cdk/aws-route53/test/test.txt-record.ts b/packages/@aws-cdk/aws-route53/test/test.txt-record.ts index 54b2dc4418d82..47222bb6406b7 100644 --- a/packages/@aws-cdk/aws-route53/test/test.txt-record.ts +++ b/packages/@aws-cdk/aws-route53/test/test.txt-record.ts @@ -43,7 +43,7 @@ class TestApp { constructor() { const account = '123456789012'; const region = 'bermuda-triangle'; - this.app.setContext(`availability-zones:${account}:${region}`, + this.app.node.setContext(`availability-zones:${account}:${region}`, [`${region}-1a`]); this.stack = new Stack(this.app, 'MyStack', { env: { account, region } }); } diff --git a/packages/@aws-cdk/aws-route53/test/test.zone-delegation-record.ts b/packages/@aws-cdk/aws-route53/test/test.zone-delegation-record.ts index 37c437a655f4a..a1d3087a8a94e 100644 --- a/packages/@aws-cdk/aws-route53/test/test.zone-delegation-record.ts +++ b/packages/@aws-cdk/aws-route53/test/test.zone-delegation-record.ts @@ -47,7 +47,7 @@ class TestApp { constructor() { const account = '123456789012'; const region = 'bermuda-triangle'; - this.app.setContext(`availability-zones:${account}:${region}`, + this.app.node.setContext(`availability-zones:${account}:${region}`, [`${region}-1a`]); this.stack = new Stack(this.app, 'MyStack', { env: { account, region } }); } diff --git a/packages/@aws-cdk/aws-route53resolver/.npmignore b/packages/@aws-cdk/aws-route53resolver/.npmignore index 0ed32f4a4a755..2895a406c8e61 100644 --- a/packages/@aws-cdk/aws-route53resolver/.npmignore +++ b/packages/@aws-cdk/aws-route53resolver/.npmignore @@ -15,3 +15,7 @@ dist .LAST_BUILD .LAST_PACKAGE .jsii + + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts index 2862c450b9cb5..cb2c3cc4dd61f 100644 --- a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts +++ b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts @@ -40,8 +40,8 @@ export interface BucketDeploymentProps { } export class BucketDeployment extends cdk.Construct { - constructor(parent: cdk.Construct, id: string, props: BucketDeploymentProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: BucketDeploymentProps) { + super(scope, id); const handler = new lambda.SingletonFunction(this, 'CustomResourceHandler', { uuid: '8693BB64-9689-44B6-9AAF-B0CC9EB8756C', diff --git a/packages/@aws-cdk/aws-s3-deployment/test/integ.bucket-deployment.ts b/packages/@aws-cdk/aws-s3-deployment/test/integ.bucket-deployment.ts index 73ea23aba0483..bee9f00872a27 100644 --- a/packages/@aws-cdk/aws-s3-deployment/test/integ.bucket-deployment.ts +++ b/packages/@aws-cdk/aws-s3-deployment/test/integ.bucket-deployment.ts @@ -4,8 +4,8 @@ import path = require('path'); import s3deploy = require('../lib'); class TestBucketDeployment extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); const destinationBucket = new s3.Bucket(this, 'Destination', { websiteIndexDocument: 'index.html', diff --git a/packages/@aws-cdk/aws-s3/lib/bucket-policy.ts b/packages/@aws-cdk/aws-s3/lib/bucket-policy.ts index 1f9a21a283c33..c56ce1982bd2c 100644 --- a/packages/@aws-cdk/aws-s3/lib/bucket-policy.ts +++ b/packages/@aws-cdk/aws-s3/lib/bucket-policy.ts @@ -22,8 +22,8 @@ export class BucketPolicy extends Construct { */ public readonly document = new PolicyDocument(); - constructor(parent: Construct, name: string, props: BucketPolicyProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: BucketPolicyProps) { + super(scope, id); if (!props.bucket.bucketName) { throw new Error('Bucket doesn\'t have a bucketName defined'); diff --git a/packages/@aws-cdk/aws-s3/lib/bucket.ts b/packages/@aws-cdk/aws-s3/lib/bucket.ts index efba50fde88fc..ec53b1ee88ea9 100644 --- a/packages/@aws-cdk/aws-s3/lib/bucket.ts +++ b/packages/@aws-cdk/aws-s3/lib/bucket.ts @@ -11,7 +11,7 @@ import { LifecycleRule } from './rule'; import { CfnBucket } from './s3.generated'; import { parseBucketArn, parseBucketName } from './util'; -export interface IBucket { +export interface IBucket extends cdk.IConstruct { /** * The ARN of the bucket. */ @@ -560,11 +560,11 @@ export class Bucket extends BucketBase { * * @param parent The parent creating construct (usually `this`). * @param id The construct's name. - * @param attrs A `BucketAttributes` object. Can be obtained from a call to + * @param props A `BucketAttributes` object. Can be obtained from a call to * `bucket.export()` or manually created. */ - public static import(parent: cdk.Construct, id: string, attrs: BucketImportProps): IBucket { - return new ImportedBucket(parent, id, attrs); + public static import(scope: cdk.Construct, id: string, props: BucketImportProps): IBucket { + return new ImportedBucket(scope, id, props); } public readonly bucketArn: string; @@ -578,8 +578,8 @@ export class Bucket extends BucketBase { private readonly versioned?: boolean; private readonly notifications: BucketNotifications; - constructor(parent: cdk.Construct, name: string, props: BucketProps = {}) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: BucketProps = {}) { + super(scope, id); const { bucketEncryption, encryptionKey } = this.parseEncryption(props); @@ -708,7 +708,7 @@ export class Bucket extends BucketBase { if (encryptionType === BucketEncryption.Kms) { const encryptionKey = props.encryptionKey || new kms.EncryptionKey(this, 'Key', { - description: `Created by ${this.path}` + description: `Created by ${this.node.path}` }); const bucketEncryption = { @@ -960,8 +960,8 @@ class ImportedBucket extends BucketBase { public policy?: BucketPolicy; protected autoCreatePolicy: boolean; - constructor(parent: cdk.Construct, name: string, private readonly props: BucketImportProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, private readonly props: BucketImportProps) { + super(scope, id); const bucketName = parseBucketName(props); if (!bucketName) { diff --git a/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts b/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts index dd0f1a91d8101..a3c04c426b26a 100644 --- a/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts +++ b/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource-handler.ts @@ -30,7 +30,7 @@ export class NotificationsResourceHandler extends cdk.Construct { // well-known logical id to ensure stack singletonity const logicalId = 'BucketNotificationsHandler050a0587b7544547bf325f094a3db834'; - let lambda = root.tryFindChild(logicalId) as NotificationsResourceHandler; + let lambda = root.node.tryFindChild(logicalId) as NotificationsResourceHandler; if (!lambda) { lambda = new NotificationsResourceHandler(root, logicalId); } @@ -44,8 +44,8 @@ export class NotificationsResourceHandler extends cdk.Construct { */ public readonly functionArn: string; - constructor(parent: cdk.Construct, id: string) { - super(parent, id); + constructor(scope: cdk.Construct, id: string) { + super(scope, id); const role = new iam.Role(this, 'Role', { assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), diff --git a/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource.ts b/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource.ts index 4e824f7447920..8173447a4187a 100644 --- a/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource.ts +++ b/packages/@aws-cdk/aws-s3/lib/notifications-resource/notifications-resource.ts @@ -35,8 +35,8 @@ export class BucketNotifications extends cdk.Construct { private resource?: cdk.Resource; private readonly bucket: Bucket; - constructor(parent: cdk.Construct, id: string, props: NotificationsProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: NotificationsProps) { + super(scope, id); this.bucket = props.bucket; } @@ -53,7 +53,7 @@ export class BucketNotifications extends cdk.Construct { // resolve target. this also provides an opportunity for the target to e.g. update // policies to allow this notification to happen. - const targetProps = target.asBucketNotificationDestination(this.bucket.bucketArn, this.bucket.uniqueId); + const targetProps = target.asBucketNotificationDestination(this.bucket.bucketArn, this.bucket.node.uniqueId); const commonConfig: CommonConfiguration = { Events: [ event ], Filter: renderFilters(filters), diff --git a/packages/@aws-cdk/aws-s3/lib/pipeline-action.ts b/packages/@aws-cdk/aws-s3/lib/pipeline-action.ts index 43aa1a94a836c..5fb5ca522547c 100644 --- a/packages/@aws-cdk/aws-s3/lib/pipeline-action.ts +++ b/packages/@aws-cdk/aws-s3/lib/pipeline-action.ts @@ -47,8 +47,8 @@ export interface PipelineSourceActionProps extends CommonPipelineSourceActionPro * Source that is provided by a specific Amazon S3 object. */ export class PipelineSourceAction extends codepipeline.SourceAction { - constructor(parent: cdk.Construct, name: string, props: PipelineSourceActionProps) { - super(parent, name, { + constructor(scope: cdk.Construct, id: string, props: PipelineSourceActionProps) { + super(scope, id, { provider: 'S3', configuration: { S3Bucket: props.bucket.bucketName, diff --git a/packages/@aws-cdk/aws-s3/test/demo.import-export.ts b/packages/@aws-cdk/aws-s3/test/demo.import-export.ts index e05b9dc41eeda..07a2778e988dc 100644 --- a/packages/@aws-cdk/aws-s3/test/demo.import-export.ts +++ b/packages/@aws-cdk/aws-s3/test/demo.import-export.ts @@ -9,8 +9,8 @@ import s3 = require('../lib'); class Producer extends cdk.Stack { public readonly myBucketRef: s3.BucketImportProps; - constructor(parent: cdk.App, name: string) { - super(parent, name); + constructor(scope: cdk.App, id: string) { + super(scope, id); const bucket = new s3.Bucket(this, 'MyBucket'); this.myBucketRef = bucket.export(); @@ -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, id: string, props: ConsumerConstructProps) { + super(scope, id); props.bucket.addToResourcePolicy(new iam.PolicyStatement().addAction('*')); } @@ -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, id: string, props: ConsumerProps) { + super(scope, id); const user = new iam.User(this, 'MyUser'); const userBucket = s3.Bucket.import(this, 'ImportBucket', props.userBucketRef); diff --git a/packages/@aws-cdk/aws-s3/test/integ.bucket.domain-name.ts b/packages/@aws-cdk/aws-s3/test/integ.bucket.domain-name.ts index b13389efade4e..1cf02bc2acc7c 100644 --- a/packages/@aws-cdk/aws-s3/test/integ.bucket.domain-name.ts +++ b/packages/@aws-cdk/aws-s3/test/integ.bucket.domain-name.ts @@ -2,8 +2,8 @@ import cdk = require('@aws-cdk/cdk'); import s3 = require('../lib'); class TestStack extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); /// !show const bucket = new s3.Bucket(this, 'MyBucket', { diff --git a/packages/@aws-cdk/aws-s3/test/integ.bucket.url.lit.ts b/packages/@aws-cdk/aws-s3/test/integ.bucket.url.lit.ts index b7886301c54d0..09949dca7c71a 100644 --- a/packages/@aws-cdk/aws-s3/test/integ.bucket.url.lit.ts +++ b/packages/@aws-cdk/aws-s3/test/integ.bucket.url.lit.ts @@ -2,8 +2,8 @@ import cdk = require('@aws-cdk/cdk'); import s3 = require('../lib'); class TestStack extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); /// !show const bucket = new s3.Bucket(this, 'MyBucket', { diff --git a/packages/@aws-cdk/aws-s3/test/notification-dests.ts b/packages/@aws-cdk/aws-s3/test/notification-dests.ts index 1750d941d1dd2..acdda43f26b46 100644 --- a/packages/@aws-cdk/aws-s3/test/notification-dests.ts +++ b/packages/@aws-cdk/aws-s3/test/notification-dests.ts @@ -11,8 +11,8 @@ export class Topic extends cdk.Construct implements s3notifications.IBucketNotif private readonly policy = new iam.PolicyDocument(); private readonly notifyingBucketPaths = new Set(); - constructor(parent: cdk.Construct, id: string) { - super(parent, id); + constructor(scope: cdk.Construct, id: string) { + super(scope, id); const resource = new cdk.Resource(this, 'Resource', { type: 'AWS::SNS::Topic' }); const topicArn = resource.ref; diff --git a/packages/@aws-cdk/aws-secretsmanager/.npmignore b/packages/@aws-cdk/aws-secretsmanager/.npmignore index 0ed32f4a4a755..2895a406c8e61 100644 --- a/packages/@aws-cdk/aws-secretsmanager/.npmignore +++ b/packages/@aws-cdk/aws-secretsmanager/.npmignore @@ -15,3 +15,7 @@ dist .LAST_BUILD .LAST_PACKAGE .jsii + + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/aws-secretsmanager/lib/secret-string.ts b/packages/@aws-cdk/aws-secretsmanager/lib/secret-string.ts index df1774eeb4cfe..fc001572bc574 100644 --- a/packages/@aws-cdk/aws-secretsmanager/lib/secret-string.ts +++ b/packages/@aws-cdk/aws-secretsmanager/lib/secret-string.ts @@ -34,8 +34,8 @@ export interface SecretStringProps { * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-secret.html */ export class SecretString extends cdk.DynamicReference { - constructor(parent: cdk.Construct, id: string, private readonly props: SecretStringProps) { - super(parent, id, { + constructor(scope: cdk.Construct, id: string, private readonly props: SecretStringProps) { + super(scope, id, { service: cdk.DynamicReferenceService.SecretsManager, referenceKey: '', }); diff --git a/packages/@aws-cdk/aws-serverless/.npmignore b/packages/@aws-cdk/aws-serverless/.npmignore index a38f4a5187806..aedb60356c270 100644 --- a/packages/@aws-cdk/aws-serverless/.npmignore +++ b/packages/@aws-cdk/aws-serverless/.npmignore @@ -15,4 +15,7 @@ dist .LAST_PACKAGE .jsii -*.snk \ No newline at end of file +*.snk + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/aws-sns/examples/sns-codecommit-event-rule-target.lit.ts b/packages/@aws-cdk/aws-sns/examples/sns-codecommit-event-rule-target.lit.ts index fbd00168040b3..7a7a6471361e6 100644 --- a/packages/@aws-cdk/aws-sns/examples/sns-codecommit-event-rule-target.lit.ts +++ b/packages/@aws-cdk/aws-sns/examples/sns-codecommit-event-rule-target.lit.ts @@ -4,8 +4,8 @@ import cdk = require('@aws-cdk/cdk'); import { Topic } from '../lib'; class IntegStack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { + super(scope, id, props); const codeCommitRepo = new codecommit.Repository(this, 'Repo', { repositoryName: 'TestRepo' diff --git a/packages/@aws-cdk/aws-sns/lib/policy.ts b/packages/@aws-cdk/aws-sns/lib/policy.ts index 07c2767d49ff4..812335f2b83fa 100644 --- a/packages/@aws-cdk/aws-sns/lib/policy.ts +++ b/packages/@aws-cdk/aws-sns/lib/policy.ts @@ -24,8 +24,8 @@ export class TopicPolicy extends Construct implements IDependable { */ public readonly dependencyElements = new Array(); - constructor(parent: Construct, id: string, props: TopicPolicyProps) { - super(parent, id); + constructor(scope: Construct, id: string, props: TopicPolicyProps) { + super(scope, id); const resource = new CfnTopicPolicy(this, 'Resource', { policyDocument: this.document, diff --git a/packages/@aws-cdk/aws-sns/lib/subscription.ts b/packages/@aws-cdk/aws-sns/lib/subscription.ts index 6a6d5d2d3b192..f2896ea9e4297 100644 --- a/packages/@aws-cdk/aws-sns/lib/subscription.ts +++ b/packages/@aws-cdk/aws-sns/lib/subscription.ts @@ -31,8 +31,8 @@ export interface SubscriptionProps { * this class. */ export class Subscription extends Construct { - constructor(parent: Construct, id: string, props: SubscriptionProps) { - super(parent, id); + constructor(scope: Construct, id: string, props: SubscriptionProps) { + super(scope, id); new CfnSubscription(this, 'Resource', { endpoint: props.endpoint, diff --git a/packages/@aws-cdk/aws-sns/lib/topic-ref.ts b/packages/@aws-cdk/aws-sns/lib/topic-ref.ts index c8cd0f83875a4..4a562651af442 100644 --- a/packages/@aws-cdk/aws-sns/lib/topic-ref.ts +++ b/packages/@aws-cdk/aws-sns/lib/topic-ref.ts @@ -10,6 +10,7 @@ import { TopicPolicy } from './policy'; import { Subscription, SubscriptionProtocol } from './subscription'; export interface ITopic extends + cdk.IConstruct, events.IEventRuleTarget, cloudwatch.IAlarmAction, s3n.IBucketNotificationDestination, @@ -168,9 +169,9 @@ export abstract class TopicBase extends cdk.Construct implements ITopic { * @param queue The target queue */ public subscribeQueue(queue: sqs.IQueue): Subscription { - const subscriptionName = queue.id + 'Subscription'; - if (this.tryFindChild(subscriptionName)) { - throw new Error(`A subscription between the topic ${this.id} and the queue ${queue.id} already exists`); + const subscriptionName = queue.node.id + 'Subscription'; + if (this.node.tryFindChild(subscriptionName)) { + throw new Error(`A subscription between the topic ${this.node.id} and the queue ${queue.node.id} already exists`); } // we use the queue name as the subscription's. there's no meaning to subscribing @@ -204,8 +205,8 @@ export abstract class TopicBase extends cdk.Construct implements ITopic { public subscribeLambda(lambdaFunction: lambda.IFunction): Subscription { const subscriptionName = lambdaFunction.id + 'Subscription'; - if (this.tryFindChild(subscriptionName)) { - throw new Error(`A subscription between the topic ${this.id} and the lambda ${lambdaFunction.id} already exists`); + if (this.node.tryFindChild(subscriptionName)) { + throw new Error(`A subscription between the topic ${this.node.id} and the lambda ${lambdaFunction.id} already exists`); } const sub = new Subscription(this, subscriptionName, { @@ -214,7 +215,7 @@ export abstract class TopicBase extends cdk.Construct implements ITopic { protocol: SubscriptionProtocol.Lambda }); - lambdaFunction.addPermission(this.id, { + lambdaFunction.addPermission(this.node.id, { sourceArn: this.topicArn, principal: new iam.ServicePrincipal('sns.amazonaws.com'), }); @@ -311,7 +312,7 @@ export abstract class TopicBase extends cdk.Construct implements ITopic { } return { - id: this.id, + id: this.node.id, arn: this.topicArn, }; } diff --git a/packages/@aws-cdk/aws-sns/lib/topic.ts b/packages/@aws-cdk/aws-sns/lib/topic.ts index 3c51e8717ef74..cb3de71abda79 100644 --- a/packages/@aws-cdk/aws-sns/lib/topic.ts +++ b/packages/@aws-cdk/aws-sns/lib/topic.ts @@ -32,8 +32,8 @@ export class Topic extends TopicBase { /** * Import a Topic defined elsewhere */ - public static import(parent: Construct, name: string, props: TopicImportProps): ITopic { - return new ImportedTopic(parent, name, props); + public static import(scope: Construct, id: string, props: TopicImportProps): ITopic { + return new ImportedTopic(scope, id, props); } public readonly topicArn: string; @@ -41,8 +41,8 @@ export class Topic extends TopicBase { protected readonly autoCreatePolicy: boolean = true; - constructor(parent: Construct, name: string, props: TopicProps = {}) { - super(parent, name); + constructor(scope: Construct, id: string, props: TopicProps = {}) { + super(scope, id); const resource = new CfnTopic(this, 'Resource', { displayName: props.displayName, @@ -73,8 +73,8 @@ class ImportedTopic extends TopicBase { protected autoCreatePolicy: boolean = false; - constructor(parent: Construct, id: string, private readonly props: TopicImportProps) { - super(parent, id); + constructor(scope: Construct, id: string, private readonly props: TopicImportProps) { + super(scope, id); this.topicArn = props.topicArn; this.topicName = props.topicName; } diff --git a/packages/@aws-cdk/aws-sns/test/integ.sns-bucket-notifications.ts b/packages/@aws-cdk/aws-sns/test/integ.sns-bucket-notifications.ts index f6793908880f8..1a702b4b89d52 100644 --- a/packages/@aws-cdk/aws-sns/test/integ.sns-bucket-notifications.ts +++ b/packages/@aws-cdk/aws-sns/test/integ.sns-bucket-notifications.ts @@ -3,8 +3,8 @@ import cdk = require('@aws-cdk/cdk'); import sns = require('../lib'); class MyStack extends cdk.Stack { - constructor(parent: cdk.App, id: string) { - super(parent, id); + constructor(scope: cdk.App, id: string) { + super(scope, id); const objectCreateTopic = new sns.Topic(this, 'ObjectCreatedTopic'); const objectRemovedTopic = new sns.Topic(this, 'ObjectDeletedTopic'); diff --git a/packages/@aws-cdk/aws-sns/test/integ.sns-lambda.ts b/packages/@aws-cdk/aws-sns/test/integ.sns-lambda.ts index 9929a95046f47..315934248e98c 100644 --- a/packages/@aws-cdk/aws-sns/test/integ.sns-lambda.ts +++ b/packages/@aws-cdk/aws-sns/test/integ.sns-lambda.ts @@ -3,8 +3,8 @@ import cdk = require('@aws-cdk/cdk'); import sns = require('../lib'); class SnsToSqs extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { + super(scope, id, props); const topic = new sns.Topic(this, 'MyTopic'); diff --git a/packages/@aws-cdk/aws-sns/test/integ.sns-sqs.lit.ts b/packages/@aws-cdk/aws-sns/test/integ.sns-sqs.lit.ts index 13360fde556b0..451c05da349a5 100644 --- a/packages/@aws-cdk/aws-sns/test/integ.sns-sqs.lit.ts +++ b/packages/@aws-cdk/aws-sns/test/integ.sns-sqs.lit.ts @@ -3,8 +3,8 @@ import cdk = require('@aws-cdk/cdk'); import sns = require('../lib'); class SnsToSqs extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { + super(scope, id, props); /// !show const topic = new sns.Topic(this, 'MyTopic'); diff --git a/packages/@aws-cdk/aws-sns/test/integ.sns.ts b/packages/@aws-cdk/aws-sns/test/integ.sns.ts index 36c128ae0a58f..e8d5e2e054289 100644 --- a/packages/@aws-cdk/aws-sns/test/integ.sns.ts +++ b/packages/@aws-cdk/aws-sns/test/integ.sns.ts @@ -2,8 +2,8 @@ import { App, Stack, StackProps } from '@aws-cdk/cdk'; import { Topic } from '../lib'; class SNSInteg extends Stack { - constructor(parent: App, name: string, props?: StackProps) { - super(parent, name, props); + constructor(scope: App, id: string, props?: StackProps) { + super(scope, id, props); new Topic(this, 'MyTopic', { topicName: 'fooTopic', diff --git a/packages/@aws-cdk/aws-sns/test/test.sns.ts b/packages/@aws-cdk/aws-sns/test/test.sns.ts index 9ca00798b18ad..ad7f6bdbc5a27 100644 --- a/packages/@aws-cdk/aws-sns/test/test.sns.ts +++ b/packages/@aws-cdk/aws-sns/test/test.sns.ts @@ -719,7 +719,7 @@ export = { test.deepEqual(dest1.type, s3n.BucketNotificationDestinationType.Topic); const dep: cdk.Construct = dest1.dependencies![0] as any; - test.deepEqual((dep.children[0] as any).logicalId, 'MyTopicPolicy12A5EC17', 'verify topic policy is added as dependency'); + test.deepEqual((dep.node.children[0] as any).logicalId, 'MyTopicPolicy12A5EC17', 'verify topic policy is added as dependency'); // calling again on the same bucket yields is idempotent const dest2 = topic.asBucketNotificationDestination(bucketArn, bucketId); diff --git a/packages/@aws-cdk/aws-sqs/lib/policy.ts b/packages/@aws-cdk/aws-sqs/lib/policy.ts index ba8a69b821a66..4a70f34a5c3a7 100644 --- a/packages/@aws-cdk/aws-sqs/lib/policy.ts +++ b/packages/@aws-cdk/aws-sqs/lib/policy.ts @@ -24,8 +24,8 @@ export class QueuePolicy extends Construct implements IDependable { */ public readonly dependencyElements = new Array(); - constructor(parent: Construct, name: string, props: QueuePolicyProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: QueuePolicyProps) { + super(scope, id); const resource = new CfnQueuePolicy(this, 'Resource', { policyDocument: this.document, diff --git a/packages/@aws-cdk/aws-sqs/lib/queue-ref.ts b/packages/@aws-cdk/aws-sqs/lib/queue-ref.ts index 84287c71f1dc6..69391f1257850 100644 --- a/packages/@aws-cdk/aws-sqs/lib/queue-ref.ts +++ b/packages/@aws-cdk/aws-sqs/lib/queue-ref.ts @@ -5,17 +5,7 @@ import s3n = require('@aws-cdk/aws-s3-notifications'); import cdk = require('@aws-cdk/cdk'); import { QueuePolicy } from './policy'; -export interface IQueue extends s3n.IBucketNotificationDestination, autoscaling_api.ILifecycleHookTarget { - /** - * Local logical ID. - */ - readonly id: string; - - /** - * Unique logical ID. - */ - readonly uniqueId: string; - +export interface IQueue extends cdk.IConstruct, s3n.IBucketNotificationDestination, autoscaling_api.ILifecycleHookTarget { /** * The ARN of this queue */ diff --git a/packages/@aws-cdk/aws-sqs/lib/queue.ts b/packages/@aws-cdk/aws-sqs/lib/queue.ts index e066040fc3efd..e935fbb57df1c 100644 --- a/packages/@aws-cdk/aws-sqs/lib/queue.ts +++ b/packages/@aws-cdk/aws-sqs/lib/queue.ts @@ -183,8 +183,8 @@ export class Queue extends QueueBase { /** * Import an existing queue */ - public static import(parent: cdk.Construct, name: string, props: QueueImportProps): IQueue { - return new ImportedQueue(parent, name, props); + public static import(scope: cdk.Construct, id: string, props: QueueImportProps): IQueue { + return new ImportedQueue(scope, id, props); } /** @@ -209,8 +209,8 @@ export class Queue extends QueueBase { protected readonly autoCreatePolicy = true; - constructor(parent: cdk.Construct, name: string, props: QueueProps = {}) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: QueueProps = {}) { + super(scope, id); validateProps(props); @@ -266,7 +266,7 @@ export class Queue extends QueueBase { if (encryption === QueueEncryption.Kms) { const masterKey = props.encryptionMasterKey || new kms.EncryptionKey(this, 'Key', { - description: `Created by ${this.path}` + description: `Created by ${this.node.path}` }); return { @@ -345,8 +345,8 @@ class ImportedQueue extends QueueBase { protected readonly autoCreatePolicy = false; - constructor(parent: cdk.Construct, name: string, private readonly props: QueueImportProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, private readonly props: QueueImportProps) { + super(scope, id); this.queueArn = props.queueArn; this.queueUrl = props.queueUrl; diff --git a/packages/@aws-cdk/aws-ssm/lib/parameter-store-string.ts b/packages/@aws-cdk/aws-ssm/lib/parameter-store-string.ts index e1ebe77ddc446..1ac1263b27830 100644 --- a/packages/@aws-cdk/aws-ssm/lib/parameter-store-string.ts +++ b/packages/@aws-cdk/aws-ssm/lib/parameter-store-string.ts @@ -21,8 +21,8 @@ export interface ParameterStoreStringProps { * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html */ export class ParameterStoreString extends cdk.DynamicReference { - constructor(parent: cdk.Construct, id: string, props: ParameterStoreStringProps) { - super(parent, id, { + constructor(scope: cdk.Construct, id: string, props: ParameterStoreStringProps) { + super(scope, id, { service: cdk.DynamicReferenceService.Ssm, referenceKey: `${props.parameterName}:${props.version}`, }); @@ -50,8 +50,8 @@ export interface ParameterStoreSecureStringProps { * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html */ export class ParameterStoreSecureString extends cdk.DynamicReference { - constructor(parent: cdk.Construct, id: string, props: ParameterStoreStringProps) { - super(parent, id, { + constructor(scope: cdk.Construct, id: string, props: ParameterStoreSecureStringProps) { + super(scope, id, { service: cdk.DynamicReferenceService.SsmSecure, referenceKey: `${props.parameterName}:${props.version}`, }); diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/activity.ts b/packages/@aws-cdk/aws-stepfunctions/lib/activity.ts index a8bf045ad13c8..ef0fe1b9db326 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/activity.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/activity.ts @@ -19,8 +19,8 @@ export class Activity extends cdk.Construct implements IStepFunctionsTaskResourc public readonly activityArn: string; public readonly activityName: string; - constructor(parent: cdk.Construct, id: string, props: ActivityProps = {}) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: ActivityProps = {}) { + super(scope, id); const resource = new CfnActivity(this, 'Resource', { name: props.activityName || this.generateName() @@ -137,7 +137,7 @@ export class Activity extends cdk.Construct implements IStepFunctionsTaskResourc } private generateName(): string { - const name = this.uniqueId; + const name = this.node.uniqueId; if (name.length > 80) { return name.substring(0, 40) + name.substring(name.length - 40); } diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine-fragment.ts b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine-fragment.ts index 56177dcbbb57c..72586781c3028 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine-fragment.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine-fragment.ts @@ -18,6 +18,10 @@ export abstract class StateMachineFragment extends cdk.Construct implements ICha */ public abstract readonly endStates: INextable[]; + public get id() { + return this.node.id; + } + /** * Prefix the IDs of all states in this state machine fragment * diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts index ea016a18217f6..696f5a04c5ddb 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts @@ -44,8 +44,8 @@ export class StateMachine extends cdk.Construct implements IStateMachine { /** * Import a state machine */ - public static import(parent: cdk.Construct, id: string, props: StateMachineImportProps): IStateMachine { - return new ImportedStateMachine(parent, id, props); + public static import(scope: cdk.Construct, id: string, props: StateMachineImportProps): IStateMachine { + return new ImportedStateMachine(scope, id, props); } /** @@ -68,8 +68,8 @@ export class StateMachine extends cdk.Construct implements IStateMachine { */ private eventsRole?: iam.Role; - constructor(parent: cdk.Construct, id: string, props: StateMachineProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: StateMachineProps) { + super(scope, id); this.role = props.role || new iam.Role(this, 'Role', { assumedBy: new iam.ServicePrincipal(`states.${new cdk.AwsRegion()}.amazonaws.com`), @@ -114,7 +114,7 @@ export class StateMachine extends cdk.Construct implements IStateMachine { } return { - id: this.id, + id: this.node.id, arn: this.stateMachineArn, roleArn: this.eventsRole.roleArn, }; @@ -202,7 +202,7 @@ export class StateMachine extends cdk.Construct implements IStateMachine { /** * A State Machine */ -export interface IStateMachine { +export interface IStateMachine extends cdk.IConstruct { /** * The ARN of the state machine */ @@ -226,12 +226,12 @@ export interface StateMachineImportProps { class ImportedStateMachine extends cdk.Construct implements IStateMachine { public readonly stateMachineArn: string; - constructor(parent: cdk.Construct, id: string, private readonly props: StateMachineImportProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, private readonly props: StateMachineImportProps) { + super(scope, id); this.stateMachineArn = props.stateMachineArn; } public export() { return this.props; } -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/states/choice.ts b/packages/@aws-cdk/aws-stepfunctions/lib/states/choice.ts index 54cbf54cb4919..2352dfc4e5e6c 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/states/choice.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/states/choice.ts @@ -45,8 +45,8 @@ export interface ChoiceProps { export class Choice extends State { public readonly endStates: INextable[] = []; - constructor(parent: cdk.Construct, id: string, props: ChoiceProps = {}) { - super(parent, id, props); + constructor(scope: cdk.Construct, id: string, props: ChoiceProps = {}) { + super(scope, id, props); } /** diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/states/fail.ts b/packages/@aws-cdk/aws-stepfunctions/lib/states/fail.ts index 4dd5cbd5fd261..f033e32d7cd43 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/states/fail.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/states/fail.ts @@ -37,8 +37,8 @@ export class Fail extends State { private readonly error: string; private readonly cause?: string; - constructor(parent: cdk.Construct, id: string, props: FailProps) { - super(parent, id, props); + constructor(scope: cdk.Construct, id: string, props: FailProps) { + super(scope, id, props); this.error = props.error; this.cause = props.cause; diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/states/parallel.ts b/packages/@aws-cdk/aws-stepfunctions/lib/states/parallel.ts index 5891fa0033b32..1833dbf5988b5 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/states/parallel.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/states/parallel.ts @@ -57,8 +57,8 @@ export interface ParallelProps { export class Parallel extends State implements INextable { public readonly endStates: INextable[]; - constructor(parent: cdk.Construct, id: string, props: ParallelProps = {}) { - super(parent, id, props); + constructor(scope: cdk.Construct, id: string, props: ParallelProps = {}) { + super(scope, id, props); this.endStates = [this]; } diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts b/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts index 65ab9561ca742..04954b3a2ca9b 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts @@ -64,8 +64,8 @@ export class Pass extends State implements INextable { private readonly result?: any; - constructor(parent: cdk.Construct, id: string, props: PassProps = {}) { - super(parent, id, props); + constructor(scope: cdk.Construct, id: string, props: PassProps = {}) { + super(scope, id, props); this.result = props.result; this.endStates = [this]; diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/states/state.ts b/packages/@aws-cdk/aws-stepfunctions/lib/states/state.ts index 3ef8b28d27746..dfc9f8f75c246 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/states/state.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/states/state.ts @@ -52,14 +52,14 @@ export abstract class State extends cdk.Construct implements IChainable { /** * Add a prefix to the stateId of all States found in a construct tree */ - public static prefixStates(root: cdk.Construct, prefix: string) { + public static prefixStates(root: cdk.IConstruct, prefix: string) { const queue = [root]; while (queue.length > 0) { const el = queue.splice(0, 1)[0]!; if (isPrefixable(el)) { el.addPrefix(prefix); } - queue.push(...el.children); + queue.push(...el.node.children); } } @@ -137,8 +137,8 @@ export abstract class State extends cdk.Construct implements IChainable { */ private readonly incomingStates: State[] = []; - constructor(parent: cdk.Construct, id: string, props: StateProps) { - super(parent, id); + constructor(scope: cdk.Construct, id: string, props: StateProps) { + super(scope, id); this.startState = this; @@ -148,6 +148,10 @@ export abstract class State extends cdk.Construct implements IChainable { this.resultPath = props.resultPath; } + public get id() { + return this.node.id; + } + /** * Tokenized string that evaluates to the state's ID */ diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/states/succeed.ts b/packages/@aws-cdk/aws-stepfunctions/lib/states/succeed.ts index f19d63156e99d..f884a07d426a9 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/states/succeed.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/states/succeed.ts @@ -43,8 +43,8 @@ export interface SucceedProps { export class Succeed extends State { public readonly endStates: INextable[] = []; - constructor(parent: cdk.Construct, id: string, props: SucceedProps = {}) { - super(parent, id, props); + constructor(scope: cdk.Construct, id: string, props: SucceedProps = {}) { + super(scope, id, props); } /** diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/states/task.ts b/packages/@aws-cdk/aws-stepfunctions/lib/states/task.ts index 2612ce33b305b..b540dacf30787 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/states/task.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/states/task.ts @@ -87,8 +87,8 @@ export class Task extends State implements INextable { private readonly timeoutSeconds?: number; private readonly heartbeatSeconds?: number; - constructor(parent: cdk.Construct, id: string, props: TaskProps) { - super(parent, id, props); + constructor(scope: cdk.Construct, id: string, props: TaskProps) { + super(scope, id, props); this.timeoutSeconds = props.timeoutSeconds; this.heartbeatSeconds = props.heartbeatSeconds; diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/states/wait.ts b/packages/@aws-cdk/aws-stepfunctions/lib/states/wait.ts index 6dfc327fbe600..cc0f8ce507fdd 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/states/wait.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/states/wait.ts @@ -62,8 +62,8 @@ export class Wait extends State implements INextable { private readonly secondsPath?: string; private readonly timestampPath?: string; - constructor(parent: cdk.Construct, id: string, props: WaitProps) { - super(parent, id, props); + constructor(scope: cdk.Construct, id: string, props: WaitProps) { + super(scope, id, props); this.seconds = props.seconds; this.timestamp = props.timestamp; diff --git a/packages/@aws-cdk/aws-stepfunctions/test/integ.job-poller.ts b/packages/@aws-cdk/aws-stepfunctions/test/integ.job-poller.ts index 8110a39431c17..816374995abe8 100644 --- a/packages/@aws-cdk/aws-stepfunctions/test/integ.job-poller.ts +++ b/packages/@aws-cdk/aws-stepfunctions/test/integ.job-poller.ts @@ -2,8 +2,8 @@ import cdk = require( '@aws-cdk/cdk'); import stepfunctions = require('../lib'); class JobPollerStack extends cdk.Stack { - constructor(parent: cdk.App, id: string, props: cdk.StackProps = {}) { - super(parent, id, props); + constructor(scope: cdk.App, id: string, props: cdk.StackProps = {}) { + super(scope, id, props); const submitJobActivity = new stepfunctions.Activity(this, 'SubmitJob'); const checkJobActivity = new stepfunctions.Activity(this, 'CheckJob'); diff --git a/packages/@aws-cdk/aws-stepfunctions/test/test.states-language.ts b/packages/@aws-cdk/aws-stepfunctions/test/test.states-language.ts index beeb6dc04d857..fd30ca17a1d59 100644 --- a/packages/@aws-cdk/aws-stepfunctions/test/test.states-language.ts +++ b/packages/@aws-cdk/aws-stepfunctions/test/test.states-language.ts @@ -685,8 +685,8 @@ export = { class ReusableStateMachine extends stepfunctions.StateMachineFragment { public readonly startState: stepfunctions.State; public readonly endStates: stepfunctions.INextable[]; - constructor(parent: cdk.Construct, id: string) { - super(parent, id); + constructor(scope: cdk.Construct, id: string) { + super(scope, id); const choice = new stepfunctions.Choice(this, 'Choice') .when(stepfunctions.Condition.stringEquals('$.branch', 'left'), new stepfunctions.Pass(this, 'Left Branch')) @@ -702,8 +702,8 @@ class SimpleChain extends stepfunctions.StateMachineFragment { public readonly endStates: stepfunctions.INextable[]; private readonly task2: stepfunctions.Task; - constructor(parent: cdk.Construct, id: string) { - super(parent, id); + constructor(scope: cdk.Construct, id: string) { + super(scope, id); const task1 = new stepfunctions.Task(this, 'Task1', { resource: new FakeResource() }); this.task2 = new stepfunctions.Task(this, 'Task2', { resource: new FakeResource() }); diff --git a/packages/@aws-cdk/cdk/lib/app.ts b/packages/@aws-cdk/cdk/lib/app.ts index bdf013f5091ac..7cf7fbecc478f 100644 --- a/packages/@aws-cdk/cdk/lib/app.ts +++ b/packages/@aws-cdk/cdk/lib/app.ts @@ -2,7 +2,7 @@ import cxapi = require('@aws-cdk/cx-api'); import fs = require('fs'); import path = require('path'); import { Stack } from './cloudformation/stack'; -import { Construct, MetadataEntry, PATH_SEP, Root } from './core/construct'; +import { IConstruct, MetadataEntry, PATH_SEP, Root } from './core/construct'; import { resolve } from './core/tokens'; /** @@ -20,12 +20,12 @@ export class App extends Root { private get stacks() { const out: { [name: string]: Stack } = { }; - for (const child of this.children) { + for (const child of this.node.children) { if (!Stack.isStack(child)) { throw new Error(`The child ${child.toString()} of App must be a Stack`); } - out[child.id] = child as Stack; + out[child.node.id] = child as Stack; } return out; } @@ -60,9 +60,9 @@ export class App extends Root { const stack = this.getStack(stackName); // first, validate this stack and stop if there are errors. - const errors = stack.validateTree(); + const errors = stack.node.validateTree(); if (errors.length > 0) { - const errorList = errors.map(e => `[${e.source.path}] ${e.message}`).join('\n '); + const errorList = errors.map(e => `[${e.source.node.path}] ${e.message}`).join('\n '); throw new Error(`Stack validation failed with the following errors:\n ${errorList}`); } @@ -77,7 +77,7 @@ export class App extends Root { const missing = Object.keys(stack.missingContext).length ? stack.missingContext : undefined; return { - name: stack.id, + name: stack.node.id, environment, missing, template: stack.toCloudFormation(), @@ -105,19 +105,19 @@ export class App extends Root { visit(stack); // add app-level metadata under "." - if (this.metadata.length > 0) { - output[PATH_SEP] = this.metadata; + if (this.node.metadata.length > 0) { + output[PATH_SEP] = this.node.metadata; } return output; - function visit(node: Construct) { - if (node.metadata.length > 0) { + function visit(node: IConstruct) { + if (node.node.metadata.length > 0) { // Make the path absolute - output[PATH_SEP + node.path] = node.metadata.map(md => resolve(md) as MetadataEntry); + output[PATH_SEP + node.node.path] = node.node.metadata.map(md => resolve(md) as MetadataEntry); } - for (const child of node.children) { + for (const child of node.node.children) { visit(child); } } @@ -162,7 +162,7 @@ export class App extends Root { const contextJson = process.env[cxapi.CONTEXT_ENV]; const context = !contextJson ? { } : JSON.parse(contextJson); for (const key of Object.keys(context)) { - this.setContext(key, context[key]); + this.node.setContext(key, context[key]); } } } diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/condition.ts b/packages/@aws-cdk/cdk/lib/cloudformation/condition.ts index 0d78f4191a071..706b352c90d86 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/condition.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/condition.ts @@ -20,8 +20,8 @@ export class Condition extends Referenceable { * Build a new condition. The condition must be constructed with a condition token, * that the condition is based on. */ - constructor(parent: Construct, name: string, props?: ConditionProps) { - super(parent, name); + constructor(scope: Construct, id: string, props?: ConditionProps) { + super(scope, id); this.expression = props && props.expression; } diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/dynamic-reference.ts b/packages/@aws-cdk/cdk/lib/cloudformation/dynamic-reference.ts index 0f890bbca96c9..c319317c16153 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/dynamic-reference.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/dynamic-reference.ts @@ -27,8 +27,8 @@ export interface DynamicReferenceProps { export class DynamicReference extends Construct { private readonly _value: string; - constructor(parent: Construct, id: string, props: DynamicReferenceProps) { - super(parent, id); + constructor(scope: Construct, id: string, props: DynamicReferenceProps) { + super(scope, id); this._value = this.makeResolveValue(props.service, props.referenceKey); } diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/include.ts b/packages/@aws-cdk/cdk/lib/cloudformation/include.ts index 18756222de393..ba307cd58b475 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/include.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/include.ts @@ -26,8 +26,8 @@ export class Include extends StackElement { * @param id The ID of this construct * @param template The template to adopt. */ - constructor(parent: Construct, name: string, props: IncludeProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: IncludeProps) { + super(scope, id); this.template = props.template; } diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/mapping.ts b/packages/@aws-cdk/cdk/lib/cloudformation/mapping.ts index 8601012b60d47..65f4025bdd2a3 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/mapping.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/mapping.ts @@ -12,8 +12,8 @@ export interface MappingProps { export class Mapping extends Referenceable { private mapping: { [k1: string]: { [k2: string]: any } } = { }; - constructor(parent: Construct, name: string, props: MappingProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: MappingProps) { + super(scope, id); this.mapping = props.mapping || { }; } diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/output.ts b/packages/@aws-cdk/cdk/lib/cloudformation/output.ts index ecaedb4ef488c..bacb463f17dc1 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/output.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/output.ts @@ -76,8 +76,8 @@ export class Output extends StackElement { * @param parent The parent construct. * @param props Output properties. */ - constructor(parent: Construct, name: string, props: OutputProps = {}) { - super(parent, name); + constructor(scope: Construct, id: string, props: OutputProps = {}) { + super(scope, id); this.description = props.description; this.value = props.value; @@ -90,7 +90,7 @@ export class Output extends StackElement { this.export = props.export; } else if (!props.disableExport) { // prefix export name with stack name since exports are global within account + region. - const stackName = Stack.find(this).id; + const stackName = Stack.find(this).node.id; this.export = stackName ? stackName + ':' : ''; this.export += this.logicalId; } @@ -195,8 +195,8 @@ export class StringListOutput extends Construct { */ private readonly output: Output; - constructor(parent: Construct, name: string, props: StringListOutputProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: StringListOutputProps) { + super(scope, id); this.separator = props.separator || ','; this.length = props.values.length; diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/parameter.ts b/packages/@aws-cdk/cdk/lib/cloudformation/parameter.ts index 9605363188fd3..0a22b6779cf74 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/parameter.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/parameter.ts @@ -96,8 +96,8 @@ export class Parameter extends Referenceable { * @param parent The parent construct. * @param props The parameter properties. */ - constructor(parent: Construct, name: string, props: ParameterProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: ParameterProps) { + super(scope, id); this.properties = props; this.value = new Ref(this); this.valueAsString = this.value.toString(); diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/removal-policy.ts b/packages/@aws-cdk/cdk/lib/cloudformation/removal-policy.ts index 64077cbb9ddc4..bfbc297dc59fc 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/removal-policy.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/removal-policy.ts @@ -29,6 +29,6 @@ export function applyRemovalPolicy(resource: Resource, removalPolicy: RemovalPol // attach metadata that will tell the toolkit to protect this resource by // applying an appropriate stack update policy. if (removalPolicy === RemovalPolicy.Forbid) { - resource.addMetadata('aws:cdk:protected', true); + resource.node.addMetadata('aws:cdk:protected', true); } } diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts b/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts index 06895929f647f..92cdd25eeb99e 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/resource.ts @@ -78,8 +78,8 @@ export class Resource extends Referenceable { * Creates a resource construct. * @param resourceType The CloudFormation type of this resource (e.g. AWS::DynamoDB::Table) */ - constructor(parent: Construct, name: string, props: ResourceProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: ResourceProps) { + super(scope, id); if (!props.type) { throw new Error('The `type` property is required'); @@ -91,9 +91,9 @@ export class Resource extends Referenceable { // if aws:cdk:enable-path-metadata is set, embed the current construct's // path in the CloudFormation template, so it will be possible to trace // back to the actual construct path. - if (this.getContext(cxapi.PATH_METADATA_ENABLE_CONTEXT)) { + if (this.node.getContext(cxapi.PATH_METADATA_ENABLE_CONTEXT)) { this.options.metadata = { - [cxapi.PATH_METADATA_KEY]: this.path + [cxapi.PATH_METADATA_KEY]: this.node.path }; } } @@ -199,7 +199,7 @@ export class Resource extends Referenceable { }; } catch (e) { // Change message - e.message = `While synthesizing ${this.path}: ${e.message}`; + e.message = `While synthesizing ${this.node.path}: ${e.message}`; // Adjust stack trace (make it look like node built it, too...) const creationStack = ['--- resource created at ---', ...this.creationStackTrace].join('\n at '); const problemTrace = e.stack.substr(e.stack.indexOf(e.message) + e.message.length); diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/rule.ts b/packages/@aws-cdk/cdk/lib/cloudformation/rule.ts index 039d32381e8ad..85ff566366897 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/rule.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/rule.ts @@ -69,8 +69,8 @@ export class Rule extends Referenceable { * @param parent The parent construct. * @param props The rule props. */ - constructor(parent: Construct, name: string, props?: RuleProps) { - super(parent, name); + constructor(scope: Construct, id: string, props?: RuleProps) { + super(scope, id); this.ruleCondition = props && props.ruleCondition; this.assertions = props && props.assertions; diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/secret.ts b/packages/@aws-cdk/cdk/lib/cloudformation/secret.ts index 5bae8537c3800..5565bc72c883e 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/secret.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/secret.ts @@ -14,7 +14,7 @@ import { Parameter } from './parameter'; */ export class Secret extends Token { } -export interface SecretProps { +export interface SecretParameterProps { /** * The name of the SSM parameter where the secret value is stored. */ @@ -74,8 +74,8 @@ export class SecretParameter extends Construct { */ public value: Secret; - constructor(parent: Construct, name: string, props: SecretProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: SecretParameterProps) { + super(scope, id); const param = new Parameter(this, 'Parameter', { type: 'AWS::SSM::Parameter::Value', diff --git a/packages/@aws-cdk/cdk/lib/cloudformation/stack.ts b/packages/@aws-cdk/cdk/lib/cloudformation/stack.ts index c4305e8cd7b36..f7a3af4b62b05 100644 --- a/packages/@aws-cdk/cdk/lib/cloudformation/stack.ts +++ b/packages/@aws-cdk/cdk/lib/cloudformation/stack.ts @@ -1,6 +1,6 @@ import cxapi = require('@aws-cdk/cx-api'); import { App } from '../app'; -import { Construct, PATH_SEP } from '../core/construct'; +import { Construct, IConstruct, PATH_SEP } from '../core/construct'; import { resolve, Token } from '../core/tokens'; import { Environment } from '../environment'; import { CloudFormationToken } from './cloudformation-token'; @@ -34,9 +34,9 @@ export class Stack extends Construct { * @returns The Stack object (throws if the node is not part of a Stack-rooted tree) */ public static find(node: Construct): Stack { - let curr: Construct | undefined = node; + let curr: IConstruct | undefined = node; while (curr != null && !Stack.isStack(curr)) { - curr = curr.parent; + curr = curr.node.scope; } if (curr == null) { @@ -55,7 +55,7 @@ export class Stack extends Construct { return; } - construct.addMetadata('aws:cdk:physical-name', physicalName); + construct.node.addMetadata('aws:cdk:physical-name', physicalName); } /** @@ -63,7 +63,7 @@ export class Stack extends Construct { * * We do attribute detection since we can't reliably use 'instanceof'. */ - public static isStack(construct: Construct): construct is Stack { + public static isStack(construct: IConstruct): construct is Stack { return (construct as any)._isStack; } @@ -104,17 +104,22 @@ export class Stack extends Construct { /** * Creates a new stack. * - * @param parent Parent of this stack, usually a Program instance. + * @param scope Parent of this stack, usually a Program instance. * @param name The name of the CloudFormation stack. Defaults to "Stack". * @param props Stack properties. */ - public constructor(parent?: App, name?: string, props?: StackProps) { + public constructor(scope?: App, name?: string, props?: StackProps) { // For unit test convenience parents are optional, so bypass the type check when calling the parent. - super(parent!, name!); + super(scope!, name!); + + if (name && !Stack.VALID_STACK_NAME_REGEX.test(name)) { + throw new Error(`Stack name must match the regular expression: ${Stack.VALID_STACK_NAME_REGEX.toString()}, got '${name}'`); + } + this.env = this.parseEnvironment(props); this.logicalIds = new LogicalIDs(props && props.namingScheme ? props.namingScheme : new HashedAddressingScheme()); - this.name = this.id; + this.name = this.node.id; } /** @@ -123,7 +128,7 @@ export class Stack extends Construct { * @returns The Resource or undefined if not found */ public findResource(path: string): Resource | undefined { - const r = this.findChild(path); + const r = this.node.findChild(path); if (!r) { return undefined; } // found an element, check if it's a resource (duck-type) @@ -140,7 +145,7 @@ export class Stack extends Construct { */ public toCloudFormation() { // before we begin synthesis, we shall lock this stack, so children cannot be added - this.lock(); + this.node.lock(); try { const template: any = { @@ -166,7 +171,7 @@ export class Stack extends Construct { return ret; } finally { // allow mutations after synthesis is finished. - this.unlock(); + this.node.unlock(); } } @@ -200,7 +205,7 @@ export class Stack extends Construct { } public parentApp(): App | undefined { - const parent = this.parent; + const parent = this.node.scope; return parent instanceof App ? parent : undefined; @@ -222,25 +227,13 @@ export class Stack extends Construct { */ public renameLogical(oldId: string, newId: string) { // tslint:disable-next-line:no-console - if (this.children.length > 0) { + if (this.node.children.length > 0) { throw new Error("All renames must be set up before adding elements to the stack"); } this.logicalIds.renameLogical(oldId, newId); } - /** - * Validate stack name - * - * CloudFormation stack names can include dashes in addition to the regular identifier - * character classes, and we don't allow one of the magic markers. - */ - protected _validateId(name: string) { - if (name && !Stack.VALID_STACK_NAME_REGEX.test(name)) { - throw new Error(`Stack name must match the regular expression: ${Stack.VALID_STACK_NAME_REGEX.toString()}, got '${name}'`); - } - } - /** * Applied defaults to environment attributes. */ @@ -250,12 +243,12 @@ export class Stack extends Construct { // if account is not specified, attempt to read from context. if (!env.account) { - env.account = this.getContext(cxapi.DEFAULT_ACCOUNT_CONTEXT_KEY); + env.account = this.node.getContext(cxapi.DEFAULT_ACCOUNT_CONTEXT_KEY); } // if region is not specified, attempt to read from context. if (!env.region) { - env.region = this.getContext(cxapi.DEFAULT_REGION_CONTEXT_KEY); + env.region = this.node.getContext(cxapi.DEFAULT_REGION_CONTEXT_KEY); } return env; @@ -308,7 +301,7 @@ export abstract class StackElement extends Construct implements IDependable { * * @returns The construct as a stack element or undefined if it is not a stack element. */ - public static _asStackElement(construct: Construct): StackElement | undefined { + public static _asStackElement(construct: IConstruct): StackElement | undefined { if ('logicalId' in construct && 'toCloudFormation' in construct) { return construct as StackElement; } else { @@ -333,15 +326,15 @@ export abstract class StackElement extends Construct implements IDependable { * @param parent The parent construct * @param props Construct properties */ - constructor(parent: Construct, name: string) { - super(parent, name); + constructor(scope: Construct, id: string) { + super(scope, id); const s = Stack.find(this); if (!s) { throw new Error('The tree root must be derived from "Stack"'); } this.stack = s; - this.addMetadata(LOGICAL_ID_MD, new Token(() => this.logicalId), this.constructor); + this.node.addMetadata(LOGICAL_ID_MD, new Token(() => this.logicalId), this.constructor); this.logicalId = this.stack.logicalIds.getLogicalId(this); } @@ -352,7 +345,7 @@ export abstract class StackElement extends Construct implements IDependable { * node +internal+ entries filtered. */ public get creationStackTrace(): string[] { - return filterStackTrace(this.metadata.find(md => md.type === LOGICAL_ID_MD)!.trace); + return filterStackTrace(this.node.metadata.find(md => md.type === LOGICAL_ID_MD)!.trace); function filterStackTrace(stack: string[]): string[] { const result = Array.of(...stack); @@ -372,7 +365,7 @@ export abstract class StackElement extends Construct implements IDependable { * Return the path with respect to the stack */ public get stackPath(): string { - return this.ancestors(this.stack).map(c => c.id).join(PATH_SEP); + return this.node.ancestors(this.stack).map(c => c.node.id).join(PATH_SEP); } public get dependencyElements(): IDependable[] { @@ -449,13 +442,13 @@ export abstract class Referenceable extends StackElement { * @param into Array to append StackElements to * @returns The same array as is being collected into */ -function stackElements(node: Construct, into: StackElement[] = []): StackElement[] { +function stackElements(node: IConstruct, into: StackElement[] = []): StackElement[] { const element = StackElement._asStackElement(node); if (element) { into.push(element); } - for (const child of node.children) { + for (const child of node.node.children) { stackElements(child, into); } diff --git a/packages/@aws-cdk/cdk/lib/context.ts b/packages/@aws-cdk/cdk/lib/context.ts index b215e20193ee2..45e7b8bcfc79b 100644 --- a/packages/@aws-cdk/cdk/lib/context.ts +++ b/packages/@aws-cdk/cdk/lib/context.ts @@ -41,11 +41,11 @@ export class ContextProvider { // if account or region is not defined this is probably a test mode, so we just // return the default value if (!this.props.account || !this.props.region) { - this.context.addError(formatMissingScopeError(this.provider, this.props)); + this.context.node.addError(formatMissingScopeError(this.provider, this.props)); return defaultValue; } - const value = this.context.getContext(this.key); + const value = this.context.node.getContext(this.key); if (value != null) { return value; @@ -65,11 +65,11 @@ export class ContextProvider { // if scope is undefined, this is probably a test mode, so we just // return the default value if (!this.props.account || !this.props.region) { - this.context.addError(formatMissingScopeError(this.provider, this.props)); + this.context.node.addError(formatMissingScopeError(this.provider, this.props)); return defaultValue; } - const value = this.context.getContext(this.key); + const value = this.context.node.getContext(this.key); if (value != null) { if (typeof value !== 'string') { @@ -95,11 +95,11 @@ export class ContextProvider { // return the default value and report an error so this in not accidentally used // in the toolkit if (!this.props.account || !this.props.region) { - this.context.addError(formatMissingScopeError(this.provider, this.props)); + this.context.node.addError(formatMissingScopeError(this.provider, this.props)); return defaultValue; } - const value = this.context.getContext(this.key); + const value = this.context.node.getContext(this.key); if (value != null) { if (!value.map) { diff --git a/packages/@aws-cdk/cdk/lib/core/construct.ts b/packages/@aws-cdk/cdk/lib/core/construct.ts index 1fff75c333bbe..96b6453b35602 100644 --- a/packages/@aws-cdk/cdk/lib/core/construct.ts +++ b/packages/@aws-cdk/cdk/lib/core/construct.ts @@ -1,40 +1,38 @@ import cxapi = require('@aws-cdk/cx-api'); import { makeUniqueId } from '../util/uniqueid'; +import { unresolved } from './tokens'; export const PATH_SEP = '/'; /** - * Represents the building block of the construct graph. - * When a construct is created, it is always added as a child + * Represents a construct. */ -export class Construct { +export interface IConstruct { /** - * Returns the parent of this node or undefined if this is a root node. + * The construct node in the scope tree. */ - public readonly parent?: Construct; - - /** - * The local id of the construct. - * This id is unique amongst its siblings. - * To obtain a tree-global unique id for this construct, use `uniqueId`. - */ - public readonly id: string; + readonly node: ConstructNode; +} +/** + * Represents the construct node in the scope tree. + */ +export class ConstructNode { /** - * The full path of this construct in the tree. - * Components are separated by '/'. + * Returns the scope in which this construct is defined. */ - public readonly path: string; + public readonly scope?: IConstruct; /** - * A tree-global unique alphanumeric identifier for this construct. - * Includes all components of the tree. + * The scoped construct ID + * This ID is unique amongst all constructs defined in the same scope. + * To obtain a global unique id for this construct, use `uniqueId`. */ - public readonly uniqueId: string; + public readonly id: string; /** * List of children and their names */ - private readonly _children: { [name: string]: Construct } = { }; + private readonly _children: { [name: string]: IConstruct } = { }; private readonly context: { [key: string]: any } = { }; private readonly _metadata = new Array(); @@ -44,29 +42,21 @@ export class Construct { */ private _locked = false; - /** - * Creates a new construct node. - * - * @param parent The parent construct - * @param id The local logical ID of the construct. Must be unique amongst - * siblings. If the ID includes a path separator (`/`), then it will be - * replaced by double dash `--`. - */ - constructor(parent: Construct, id: string) { + constructor(private readonly host: Construct, scope: IConstruct, id: string) { id = id || ''; // if undefined, convert to empty string this.id = id; - this.parent = parent; + this.scope = scope; - // We say that parent is required, but some root constructs bypass the type checks and - // actually pass in 'undefined'. - if (parent != null) { + // We say that scope is required, but root scopes will bypass the type + // checks and actually pass in 'undefined'. + if (scope != null) { if (id === '') { throw new Error('Only root constructs may have an empty name'); } // Has side effect so must be very last thing in constructor - parent.addChild(this, this.id); + scope.node.addChild(host, this.id); } else { // This is a root construct. this.id = id; @@ -75,20 +65,27 @@ export class Construct { // escape any path separators so they don't wreck havoc this.id = this._escapePathSeparator(this.id); - // allow derived classes to validate the construct id - this._validateId(this.id); + if (unresolved(id)) { + throw new Error(`Cannot use tokens in construct ID: ${id}`); + } + } - const components = this.rootPath().map(c => c.id); - this.path = components.join(PATH_SEP); - this.uniqueId = components.length > 0 ? makeUniqueId(components) : ''; + /** + * The full path of this construct in the tree. + * Components are separated by '/'. + */ + public get path(): string { + const components = this.rootPath().map(c => c.node.id); + return components.join(PATH_SEP); } /** - * Returns a string representation of this construct. + * A tree-global unique alphanumeric identifier for this construct. + * Includes all components of the tree. */ - public toString() { - const path = this.path; - return this.typename + (path.length > 0 ? ` [${path}]` : ''); + public get uniqueId(): string { + const components = this.rootPath().map(c => c.node.id); + return components.length > 0 ? makeUniqueId(components) : ''; } /** @@ -102,7 +99,7 @@ export class Construct { const name = this.id || ''; out += `${this.typename}${name.length > 0 ? ' [' + name + ']' : ''}\n`; for (const child of this.children) { - out += child.toTreeString(depth + 1); + out += child.node.toTreeString(depth + 1); } return out; } @@ -116,16 +113,16 @@ export class Construct { * @param name Relative name of a direct or indirect child * @returns a child by path or undefined if not found. */ - public tryFindChild(path: string): Construct | undefined { + public tryFindChild(path: string): IConstruct | undefined { // tslint:disable-next-line:no-console if (path.startsWith(PATH_SEP)) { throw new Error('Path must be relative'); } const parts = path.split(PATH_SEP); - let curr: Construct|undefined = this; + let curr: IConstruct|undefined = this.host; while (curr != null && parts.length > 0) { - curr = curr._children[parts.shift()!]; + curr = curr.node._children[parts.shift()!]; } return curr; } @@ -141,7 +138,7 @@ export class Construct { * @param name Relative name of a direct or indirect child * @returns Child with the given path. */ - public findChild(path: string): Construct { + public findChild(path: string): IConstruct { const ret = this.tryFindChild(path); if (!ret) { throw new Error(`No child with path: '${path}'`); @@ -165,7 +162,7 @@ export class Construct { */ public setContext(key: string, value: any) { if (this.children.length > 0) { - const names = this.children.map(c => c.id); + const names = this.children.map(c => c.node.id); throw new Error('Cannot set context after children have been added: ' + names.join(',')); } this.context[key] = value; @@ -183,7 +180,7 @@ export class Construct { const value = this.context[key]; if (value !== undefined) { return value; } - return this.parent && this.parent.getContext(key); + return this.scope && this.scope.node.getContext(key); } /** @@ -219,13 +216,12 @@ export class Construct { * @param data the value of the metadata (can be a Token). If null/undefined, metadata will not be added. * @param from a function under which to restrict the metadata entry's stack trace (defaults to this.addMetadata) */ - public addMetadata(type: string, data: any, from?: any): Construct { + public addMetadata(type: string, data: any, from?: any): void { if (data == null) { - return this; + return; } const trace = createStackTrace(from || this.addMetadata); this._metadata.push({ type, data, trace }); - return this; } /** @@ -233,8 +229,8 @@ export class Construct { * The toolkit will display the info message when apps are synthesized. * @param message The info message. */ - public addInfo(message: string): Construct { - return this.addMetadata(cxapi.INFO_METADATA_KEY, message); + public addInfo(message: string): void { + this.addMetadata(cxapi.INFO_METADATA_KEY, message); } /** @@ -243,8 +239,8 @@ export class Construct { * if run in --strict mode. * @param message The warning message. */ - public addWarning(message: string): Construct { - return this.addMetadata(cxapi.WARNING_METADATA_KEY, message); + public addWarning(message: string): void { + this.addMetadata(cxapi.WARNING_METADATA_KEY, message); } /** @@ -252,18 +248,8 @@ export class Construct { * The toolkit will fail synthesis when errors are reported. * @param message The error message. */ - public addError(message: string): Construct { - return this.addMetadata(cxapi.ERROR_METADATA_KEY, message); - } - - /** - * This method can be implemented by derived constructs in order to perform - * validation logic. It is called on all constructs before synthesis. - * - * @returns An array of validation error messages, or an empty array if there the construct is valid. - */ - public validate(): string[] { - return []; + public addError(message: string) { + this.addMetadata(cxapi.ERROR_METADATA_KEY, message); } /** @@ -274,11 +260,11 @@ export class Construct { let errors = new Array(); for (const child of this.children) { - errors = errors.concat(child.validateTree()); + errors = errors.concat(child.node.validateTree()); } - const localErrors = this.validate(); - return errors.concat(localErrors.map(msg => new ValidationError(this, msg))); + const localErrors: string[] = this.host.validate(); + return errors.concat(localErrors.map(msg => new ValidationError(this.host, msg))); } /** @@ -287,26 +273,18 @@ export class Construct { * @param to The construct to return the path components relative to, or * the entire list of ancestors (including root) if omitted. */ - public ancestors(upTo?: Construct): Construct[] { - const ret = new Array(); + public ancestors(upTo?: Construct): IConstruct[] { + const ret = new Array(); - let curr: Construct | undefined = this; + let curr: IConstruct | undefined = this.host; while (curr && curr !== upTo) { ret.unshift(curr); - curr = curr.parent; + curr = curr.node && curr.node.scope; } return ret; } - /** - * Validate that the id of the construct legal. - * Construct IDs can be any characters besides the path separator. - */ - protected _validateId(_id: string) { - // can be used by derived classes to customize ID validation. - } - /** * Throws if the `props` bag doesn't include the property `name`. * In the future we can add some type-checking here, maybe even auto-generate during compilation. @@ -315,7 +293,7 @@ export class Construct { * * @deprecated use ``requireProperty`` from ``@aws-cdk/runtime`` instead. */ - protected required(props: any, name: string): any { + public required(props: any, name: string): any { if (!(name in props)) { throw new Error(`Construct of type ${this.typename} is missing required property: ${name}`); } @@ -327,8 +305,8 @@ export class Construct { /** * @returns The type name of this node. */ - private get typename(): string { - const ctor: any = this.constructor; + public get typename(): string { + const ctor: any = this.host.constructor; return ctor.name || 'Construct'; } @@ -339,7 +317,7 @@ export class Construct { * @param name The type name of the child construct. * @returns The resolved path part name of the child */ - protected addChild(child: Construct, childName: string) { + public addChild(child: IConstruct, childName: string) { if (this.locked) { // special error if root is locked @@ -361,36 +339,36 @@ export class Construct { * Locks this construct from allowing more children to be added. After this * call, no more children can be added to this construct or to any children. */ - protected lock() { + public lock() { this._locked = true; } /** * Unlocks this costruct and allows mutations (adding children). */ - protected unlock() { + public unlock() { this._locked = false; } /** * Return the path of components up to but excluding the root */ - private rootPath(): Construct[] { + private rootPath(): IConstruct[] { const ancestors = this.ancestors(); ancestors.shift(); return ancestors; } /** - * Returns true if this construct or any of it's parent constructs are + * Returns true if this construct or the scopes in which it is defined are * locked. */ - protected get locked() { + public get locked() { if (this._locked) { return true; } - if (this.parent && this.parent.locked) { + if (this.scope && this.scope.node.locked) { return true; } @@ -406,9 +384,52 @@ export class Construct { } } +/** + * Represents the building block of the construct graph. + * + * All constructs besides the root construct must be created within the scope of + * another construct. + */ +export class Construct implements IConstruct { + /** + * Construct node. + */ + public readonly node: ConstructNode; + + /** + * Creates a new construct node. + * + * @param scope The scope in which to define this construct + * @param id The scoped construct ID. Must be unique amongst siblings. If + * the ID includes a path separator (`/`), then it will be replaced by double + * dash `--`. + */ + constructor(scope: Construct, id: string) { + this.node = new ConstructNode(this, scope, id); + } + + /** + * Returns a string representation of this construct. + */ + public toString() { + const path = this.node.path; + return this.node.typename + (path.length > 0 ? ` [${path}]` : ''); + } + + /** + * This method can be implemented by derived constructs in order to perform + * validation logic. It is called on all constructs before synthesis. + * + * @returns An array of validation error messages, or an empty array if there the construct is valid. + */ + public validate(): string[] { + return []; + } +} + /** * Represents the root of a construct tree. - * No parent and no name. + * No scope and no name. */ export class Root extends Construct { constructor() { @@ -438,7 +459,7 @@ export interface MetadataEntry { } export class ValidationError { - constructor(public readonly source: Construct, public readonly message: string) { + constructor(public readonly source: IConstruct, public readonly message: string) { } } diff --git a/packages/@aws-cdk/cdk/lib/core/tag-manager.ts b/packages/@aws-cdk/cdk/lib/core/tag-manager.ts index 3b5ebf053320d..8ee0ab75b07e3 100644 --- a/packages/@aws-cdk/cdk/lib/core/tag-manager.ts +++ b/packages/@aws-cdk/cdk/lib/core/tag-manager.ts @@ -1,4 +1,4 @@ -import { Construct } from './construct'; +import { Construct, IConstruct } from './construct'; import { Token } from './tokens'; /** @@ -155,7 +155,7 @@ export class TagManager extends Token { */ private readonly blockedTags: string[] = []; - constructor(private readonly parent: Construct, props: TagManagerProps = {}) { + constructor(private readonly scope: Construct, props: TagManagerProps = {}) { super(); const initialTags = props.initialTags || {}; @@ -197,7 +197,7 @@ export class TagManager extends Token { return filteredTags; } - function propagatedTags(tagProviders: Construct[]): Tags { + function propagatedTags(tagProviders: IConstruct[]): Tags { const parentTags: Tags = {}; for (const ancestor of tagProviders) { if (TagManager.isTaggable(ancestor)) { @@ -211,7 +211,7 @@ export class TagManager extends Token { const nonStickyTags = filterTags(this._tags, {sticky: false}); const stickyTags = filterTags(this._tags, {sticky: true}); - const ancestors = this.parent.ancestors(); + const ancestors = this.scope.node.ancestors(); const ancestorTags = propagatedTags(ancestors); const propagateTags = filterTags(this._tags, {propagate: true}); return this.tagFormatResolve( { diff --git a/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts b/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts index c4feb2ee6d714..9debe742f70c5 100644 --- a/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts +++ b/packages/@aws-cdk/cdk/test/cloudformation/test.resource.ts @@ -279,8 +279,8 @@ export = { public readonly r2: Resource; public readonly r3: Resource; - constructor(parent: Construct, name: string) { - super(parent, name); + constructor(scope: Construct, id: string) { + super(scope, id); this.r1 = new Resource(this, 'R1', { type: 'T1' }); this.r2 = new Resource(this, 'R2', { type: 'T2' }); @@ -297,8 +297,8 @@ export = { public readonly r2: Resource; public readonly r3: Resource; - constructor(parent: Construct, name: string) { - super(parent, name); + constructor(scope: Construct, id: string) { + super(scope, id); this.r1 = new Resource(this, 'R1', { type: 'T1' }); this.r2 = new Resource(this, 'R2', { type: 'T2' }); @@ -315,8 +315,8 @@ export = { class C3 extends Construct implements IDependable { private readonly c2: C2; - constructor(parent: Construct, name: string) { - super(parent, name); + constructor(scope: Construct, id: string) { + super(scope, id); this.c2 = new C2(this, 'C2'); } @@ -588,7 +588,7 @@ export = { '"aws:cdk:path" metadata is added if "aws:cdk:path-metadata" context is set to true'(test: Test) { const stack = new Stack(); - stack.setContext(cxapi.PATH_METADATA_ENABLE_CONTEXT, true); + stack.node.setContext(cxapi.PATH_METADATA_ENABLE_CONTEXT, true); const parent = new Construct(stack, 'Parent'); @@ -614,8 +614,8 @@ class Counter extends Resource { public readonly arn: string; public readonly url: string; - constructor(parent: Construct, name: string, props: CounterProps) { - super(parent, name, { type: 'My::Counter', properties: { Count: props.Count } }); + constructor(scope: Construct, id: string, props: CounterProps) { + super(scope, id, { type: 'My::Counter', properties: { Count: props.Count } }); this.arn = this.getAtt('Arn').toString(); this.url = this.getAtt('URL').toString(); } @@ -630,8 +630,8 @@ function withoutHash(logId: string) { } class CustomizableResource extends Resource { - constructor(parent: Construct, id: string, props?: any) { - super(parent, id, { type: 'MyResourceType', properties: props }); + constructor(scope: Construct, id: string, props?: any) { + super(scope, id, { type: 'MyResourceType', properties: props }); } public setProperty(key: string, value: any) { diff --git a/packages/@aws-cdk/cdk/test/cloudformation/test.stack.ts b/packages/@aws-cdk/cdk/test/cloudformation/test.stack.ts index 4a60f6fa8376a..1561dfea92e0a 100644 --- a/packages/@aws-cdk/cdk/test/cloudformation/test.stack.ts +++ b/packages/@aws-cdk/cdk/test/cloudformation/test.stack.ts @@ -111,7 +111,7 @@ export = { 'Construct.findResource(logicalId) can be used to retrieve a resource by its path'(test: Test) { const stack = new Stack(); - test.ok(!stack.tryFindChild('foo'), 'empty stack'); + test.ok(!stack.node.tryFindChild('foo'), 'empty stack'); const r1 = new Resource(stack, 'Hello', { type: 'MyResource' }); test.equal(stack.findResource(r1.stackPath), r1, 'look up top-level'); @@ -129,7 +129,7 @@ export = { const p = new Parameter(stack, 'MyParam', { type: 'String' }); - test.throws(() => stack.findResource(p.path)); + test.throws(() => stack.findResource(p.node.path)); test.done(); }, @@ -141,9 +141,9 @@ export = { const o = new Output(stack, 'MyOutput'); const c = new Condition(stack, 'MyCondition'); - test.equal(stack.findChild(p.path), p); - test.equal(stack.findChild(o.path), o); - test.equal(stack.findChild(c.path), c); + test.equal(stack.node.findChild(p.node.path), p); + test.equal(stack.node.findChild(o.node.path), o); + test.equal(stack.node.findChild(c.node.path), c); test.done(); }, diff --git a/packages/@aws-cdk/cdk/test/core/test.construct.ts b/packages/@aws-cdk/cdk/test/core/test.construct.ts index 22146f69fd077..aa70c643d8e51 100644 --- a/packages/@aws-cdk/cdk/test/core/test.construct.ts +++ b/packages/@aws-cdk/cdk/test/core/test.construct.ts @@ -8,9 +8,9 @@ import { Construct, Root, Token } from '../../lib'; export = { 'the "Root" construct is a special construct which can be used as the root of the tree'(test: Test) { const root = new Root(); - test.equal(root.id, '', 'if not specified, name of a root construct is an empty string'); - test.ok(!root.parent, 'no parent'); - test.equal(root.children.length, 0, 'a construct is created without children'); // no children + test.equal(root.node.id, '', 'if not specified, name of a root construct is an empty string'); + test.ok(!root.node.scope, 'no parent'); + test.equal(root.node.children.length, 0, 'a construct is created without children'); // no children test.done(); }, @@ -23,12 +23,12 @@ export = { 'construct.name returns the name of the construct'(test: Test) { const t = createTree(); - test.equal(t.child1.id, 'Child1'); - test.equal(t.child2.id, 'Child2'); - test.equal(t.child1_1.id, 'Child11'); - test.equal(t.child1_2.id, 'Child12'); - test.equal(t.child1_1_1.id, 'Child111'); - test.equal(t.child2_1.id, 'Child21'); + test.equal(t.child1.node.id, 'Child1'); + test.equal(t.child2.node.id, 'Child2'); + test.equal(t.child1_1.node.id, 'Child11'); + test.equal(t.child1_2.node.id, 'Child12'); + test.equal(t.child1_1_1.node.id, 'Child111'); + test.equal(t.child2_1.node.id, 'Child21'); test.done(); }, @@ -53,13 +53,13 @@ export = { 'if construct id contains path seperators, they will be replaced by double-dash'(test: Test) { const root = new Root(); const c = new Construct(root, 'Boom/Boom/Bam'); - test.deepEqual(c.id, 'Boom--Boom--Bam'); + test.deepEqual(c.node.id, 'Boom--Boom--Bam'); test.done(); }, 'if "undefined" is forcefully used as an "id", it will be treated as an empty string'(test: Test) { const c = new Construct(undefined as any, undefined as any); - test.deepEqual(c.id, ''); + test.deepEqual(c.node.id, ''); test.done(); }, @@ -69,7 +69,7 @@ export = { const token = new Token(() => 'lazy'); // WHEN + THEN - test.throws(() => new Construct(root, `MyID: ${token}`), /ID components may not include unresolved tokens: MyID: \${Token/); + test.throws(() => new Construct(root, `MyID: ${token}`), /Cannot use tokens in construct ID: MyID: \${Token/); test.done(); }, @@ -81,16 +81,17 @@ export = { const c1 = new Construct(child2, 'My construct'); const c2 = new Construct(child1, 'My construct'); - test.deepEqual(c1.path, 'This is the first child/Second level/My construct'); - test.deepEqual(c2.path, 'This is the first child/My construct'); - test.deepEqual(c1.uniqueId, 'ThisisthefirstchildSecondlevelMyconstruct202131E0'); - test.deepEqual(c2.uniqueId, 'ThisisthefirstchildMyconstruct8C288DF9'); + test.deepEqual(c1.node.path, 'This is the first child/Second level/My construct'); + test.deepEqual(c2.node.path, 'This is the first child/My construct'); + test.deepEqual(c1.node.uniqueId, 'ThisisthefirstchildSecondlevelMyconstruct202131E0'); + test.deepEqual(c2.node.uniqueId, 'ThisisthefirstchildMyconstruct8C288DF9'); test.done(); }, 'cannot calculate uniqueId if the construct path is ["Default"]'(test: Test) { const root = new Root(); - test.throws(() => new Construct(root, 'Default'), /Unable to calculate a unique id for an empty set of components/); + const c = new Construct(root, 'Default'); + test.throws(() => c.node.uniqueId, /Unable to calculate a unique id for an empty set of components/); test.done(); }, @@ -98,25 +99,25 @@ export = { const root = new Root(); const child = new Construct(root, 'Child1'); new Construct(root, 'Child2'); - test.equal(child.children.length, 0, 'no children'); - test.equal(root.children.length, 2, 'two children are expected'); + test.equal(child.node.children.length, 0, 'no children'); + test.equal(root.node.children.length, 2, 'two children are expected'); test.done(); }, 'construct.findChild(name) can be used to retrieve a child from a parent'(test: Test) { const root = new Root(); const child = new Construct(root, 'Contruct'); - test.strictEqual(root.tryFindChild(child.id), child, 'findChild(name) can be used to retrieve the child from a parent'); - test.ok(!root.tryFindChild('NotFound'), 'findChild(name) returns undefined if the child is not found'); + test.strictEqual(root.node.tryFindChild(child.node.id), child, 'findChild(name) can be used to retrieve the child from a parent'); + test.ok(!root.node.tryFindChild('NotFound'), 'findChild(name) returns undefined if the child is not found'); test.done(); }, 'construct.getChild(name) can be used to retrieve a child from a parent'(test: Test) { const root = new Root(); const child = new Construct(root, 'Contruct'); - test.strictEqual(root.findChild(child.id), child, 'getChild(name) can be used to retrieve the child from a parent'); + test.strictEqual(root.node.findChild(child.node.id), child, 'getChild(name) can be used to retrieve the child from a parent'); test.throws(() => { - root.findChild('NotFound'); + root.node.findChild('NotFound'); }, '', 'getChild(name) returns undefined if the child is not found'); test.done(); }, @@ -127,7 +128,7 @@ export = { test.equal(t.root.toString(), 'Root'); test.equal(t.child1_1_1.toString(), 'Construct [Child1/Child11/Child111]'); test.equal(t.child2.toString(), 'Construct [Child2]'); - test.equal(t.root.toTreeString(), 'Root\n Construct [Child1]\n Construct [Child11]\n Construct [Child111]\n Construct [Child12]\n Construct [Child2]\n Construct [Child21]\n'); + test.equal(t.root.node.toTreeString(), 'Root\n Construct [Child1]\n Construct [Child11]\n Construct [Child111]\n Construct [Child12]\n Construct [Child2]\n Construct [Child21]\n'); test.done(); }, @@ -138,41 +139,41 @@ export = { }; const t = createTree(context); - test.equal(t.root.getContext('ctx1'), 12); - test.equal(t.child1_1_1.getContext('ctx2'), 'hello'); + test.equal(t.root.node.getContext('ctx1'), 12); + test.equal(t.child1_1_1.node.getContext('ctx2'), 'hello'); test.done(); }, 'construct.setContext(k,v) sets context at some level and construct.getContext(key) will return the lowermost value defined in the stack'(test: Test) { const root = new Root(); - root.setContext('c1', 'root'); - root.setContext('c2', 'root'); + root.node.setContext('c1', 'root'); + root.node.setContext('c2', 'root'); const child1 = new Construct(root, 'child1'); - child1.setContext('c2', 'child1'); - child1.setContext('c3', 'child1'); + child1.node.setContext('c2', 'child1'); + child1.node.setContext('c3', 'child1'); const child2 = new Construct(root, 'child2'); const child3 = new Construct(child1, 'child1child1'); - child3.setContext('c1', 'child3'); - child3.setContext('c4', 'child3'); + child3.node.setContext('c1', 'child3'); + child3.node.setContext('c4', 'child3'); - test.equal(root.getContext('c1'), 'root'); - test.equal(root.getContext('c2'), 'root'); - test.equal(root.getContext('c3'), undefined); + test.equal(root.node.getContext('c1'), 'root'); + test.equal(root.node.getContext('c2'), 'root'); + test.equal(root.node.getContext('c3'), undefined); - test.equal(child1.getContext('c1'), 'root'); - test.equal(child1.getContext('c2'), 'child1'); - test.equal(child1.getContext('c3'), 'child1'); + test.equal(child1.node.getContext('c1'), 'root'); + test.equal(child1.node.getContext('c2'), 'child1'); + test.equal(child1.node.getContext('c3'), 'child1'); - test.equal(child2.getContext('c1'), 'root'); - test.equal(child2.getContext('c2'), 'root'); - test.equal(child2.getContext('c3'), undefined); + test.equal(child2.node.getContext('c1'), 'root'); + test.equal(child2.node.getContext('c2'), 'root'); + test.equal(child2.node.getContext('c3'), undefined); - test.equal(child3.getContext('c1'), 'child3'); - test.equal(child3.getContext('c2'), 'child1'); - test.equal(child3.getContext('c3'), 'child1'); - test.equal(child3.getContext('c4'), 'child3'); + test.equal(child3.node.getContext('c1'), 'child3'); + test.equal(child3.node.getContext('c2'), 'child1'); + test.equal(child3.node.getContext('c3'), 'child1'); + test.equal(child3.node.getContext('c4'), 'child3'); test.done(); }, @@ -180,22 +181,22 @@ export = { 'construct.setContext(key, value) can only be called before adding any children'(test: Test) { const root = new Root(); new Construct(root, 'child1'); - test.throws(() => root.setContext('k', 'v')); + test.throws(() => root.node.setContext('k', 'v')); test.done(); }, 'construct.pathParts returns an array of strings of all names from root to node'(test: Test) { const tree = createTree(); - test.deepEqual(tree.root.path, ''); - test.deepEqual(tree.child1_1_1.path, 'Child1/Child11/Child111'); - test.deepEqual(tree.child2.path, 'Child2'); + test.deepEqual(tree.root.node.path, ''); + test.deepEqual(tree.child1_1_1.node.path, 'Child1/Child11/Child111'); + test.deepEqual(tree.child2.node.path, 'Child2'); test.done(); }, 'if a root construct has a name, it should be included in the path'(test: Test) { const tree = createTree({}); - test.deepEqual(tree.root.path, ''); - test.deepEqual(tree.child1_1_1.path, 'Child1/Child11/Child111'); + test.deepEqual(tree.root.node.path, ''); + test.deepEqual(tree.child1_1_1.node.path, 'Child1/Child11/Child111'); test.done(); }, @@ -216,30 +217,30 @@ export = { 'addMetadata(type, data) can be used to attach metadata to constructs FIND_ME'(test: Test) { const root = new Root(); const con = new Construct(root, 'MyConstruct'); - test.deepEqual(con.metadata, [], 'starts empty'); + test.deepEqual(con.node.metadata, [], 'starts empty'); - con.addMetadata('key', 'value'); - con.addMetadata('number', 103); - con.addMetadata('array', [ 123, 456 ]); + con.node.addMetadata('key', 'value'); + con.node.addMetadata('number', 103); + con.node.addMetadata('array', [ 123, 456 ]); - test.deepEqual(con.metadata[0].type, 'key'); - test.deepEqual(con.metadata[0].data, 'value'); - test.deepEqual(con.metadata[1].data, 103); - test.deepEqual(con.metadata[2].data, [ 123, 456 ]); - test.ok(con.metadata[0].trace[0].indexOf('FIND_ME') !== -1, 'First stack line should include this function\s name'); + test.deepEqual(con.node.metadata[0].type, 'key'); + test.deepEqual(con.node.metadata[0].data, 'value'); + test.deepEqual(con.node.metadata[1].data, 103); + test.deepEqual(con.node.metadata[2].data, [ 123, 456 ]); + test.ok(con.node.metadata[0].trace[0].indexOf('FIND_ME') !== -1, 'First stack line should include this function\s name'); test.done(); }, 'addMetadata(type, undefined/null) is ignored'(test: Test) { const root = new Root(); const con = new Construct(root, 'Foo'); - con.addMetadata('Null', null); - con.addMetadata('Undefined', undefined); - con.addMetadata('True', true); - con.addMetadata('False', false); - con.addMetadata('Empty', ''); + con.node.addMetadata('Null', null); + con.node.addMetadata('Undefined', undefined); + con.node.addMetadata('True', true); + con.node.addMetadata('False', false); + con.node.addMetadata('Empty', ''); - const exists = (key: string) => con.metadata.find(x => x.type === key); + const exists = (key: string) => con.node.metadata.find(x => x.type === key); test.ok(!exists('Null')); test.ok(!exists('Undefined')); @@ -252,30 +253,30 @@ export = { 'addWarning(message) can be used to add a "WARNING" message entry to the construct'(test: Test) { const root = new Root(); const con = new Construct(root, 'MyConstruct'); - con.addWarning('This construct is deprecated, use the other one instead'); - test.deepEqual(con.metadata[0].type, cxapi.WARNING_METADATA_KEY); - test.deepEqual(con.metadata[0].data, 'This construct is deprecated, use the other one instead'); - test.ok(con.metadata[0].trace.length > 0); + con.node.addWarning('This construct is deprecated, use the other one instead'); + test.deepEqual(con.node.metadata[0].type, cxapi.WARNING_METADATA_KEY); + test.deepEqual(con.node.metadata[0].data, 'This construct is deprecated, use the other one instead'); + test.ok(con.node.metadata[0].trace.length > 0); test.done(); }, 'addError(message) can be used to add a "ERROR" message entry to the construct'(test: Test) { const root = new Root(); const con = new Construct(root, 'MyConstruct'); - con.addError('Stop!'); - test.deepEqual(con.metadata[0].type, cxapi.ERROR_METADATA_KEY); - test.deepEqual(con.metadata[0].data, 'Stop!'); - test.ok(con.metadata[0].trace.length > 0); + con.node.addError('Stop!'); + test.deepEqual(con.node.metadata[0].type, cxapi.ERROR_METADATA_KEY); + test.deepEqual(con.node.metadata[0].data, 'Stop!'); + test.ok(con.node.metadata[0].trace.length > 0); test.done(); }, 'addInfo(message) can be used to add an "INFO" message entry to the construct'(test: Test) { const root = new Root(); const con = new Construct(root, 'MyConstruct'); - con.addInfo('Hey there, how do you do?'); - test.deepEqual(con.metadata[0].type, cxapi.INFO_METADATA_KEY); - test.deepEqual(con.metadata[0].data, 'Hey there, how do you do?'); - test.ok(con.metadata[0].trace.length > 0); + con.node.addInfo('Hey there, how do you do?'); + test.deepEqual(con.node.metadata[0].type, cxapi.INFO_METADATA_KEY); + test.deepEqual(con.node.metadata[0].data, 'Hey there, how do you do?'); + test.ok(con.node.metadata[0].trace.length > 0); test.done(); }, @@ -285,7 +286,7 @@ export = { new MyBeautifulConstruct(root, 'mbc2'); new MyBeautifulConstruct(root, 'mbc3'); new MyBeautifulConstruct(root, 'mbc4'); - test.equal(root.children.length, 4); + test.equal(root.node.children.length, 4); test.done(); }, @@ -302,15 +303,6 @@ export = { test.done(); }, - 'Construct name validation can be overridden'(test: Test) { - const root = new Root(); - - test.throws(() => new IAmSpartacusConstruct(root, "Caesar")); - new IAmSpartacusConstruct(root, "Spartacus"); - - test.done(); - }, - // tslint:disable-next-line:max-line-length 'construct.validate() can be implemented to perform validation, construct.validateTree() will return all errors from the subtree (DFS)'(test: Test) { @@ -327,8 +319,8 @@ export = { } class TheirConstruct extends Construct { - constructor(parent: Construct, name: string) { - super(parent, name); + constructor(scope: Construct, id: string) { + super(scope, id); new YourConstruct(this, 'YourConstruct'); } @@ -353,7 +345,7 @@ export = { const stack = new Stack(); - const errors = (stack.validateTree()).map(v => ({ path: v.source.path, message: v.message })); + const errors = (stack.node.validateTree()).map(v => ({ path: v.source.node.path, message: v.message })); // validate DFS test.deepEqual(errors, [ @@ -371,11 +363,11 @@ export = { class LockableConstruct extends Construct { public lockMe() { - this.lock(); + this.node.lock(); } public unlockMe() { - this.unlock(); + this.node.unlock(); } } @@ -408,7 +400,7 @@ export = { function createTree(context?: any) { const root = new Root(); if (context) { - Object.keys(context).forEach(key => root.setContext(key, context[key])); + Object.keys(context).forEach(key => root.node.setContext(key, context[key])); } const child1 = new Construct(root, 'Child1'); @@ -424,8 +416,8 @@ function createTree(context?: any) { } class MyBeautifulConstruct extends Construct { - constructor(parent: Construct, name: string) { - super(parent, name); + constructor(scope: Construct, id: string) { + super(scope, id); } } @@ -439,21 +431,10 @@ class ConstructWithRequired extends Construct { public readonly requiredProp: string; public readonly anotherRequiredProp: boolean; - constructor(parent: Construct, name: string, props: ConstructWithRequiredProps) { - super(parent, name); + constructor(scope: Construct, id: string, props: ConstructWithRequiredProps) { + super(scope, id); - this.requiredProp = this.required(props, 'requiredProp'); - this.anotherRequiredProp = this.required(props, 'anotherRequiredProp'); - } -} - -/** - * Construct that *must* be named "Spartacus" - */ -class IAmSpartacusConstruct extends Construct { - protected _validateId(name: string) { - if (name !== "Spartacus") { - throw new Error("Construct name must be 'Spartacus'"); - } + this.requiredProp = this.node.required(props, 'requiredProp'); + this.anotherRequiredProp = this.node.required(props, 'anotherRequiredProp'); } } diff --git a/packages/@aws-cdk/cdk/test/core/test.tag-manager.ts b/packages/@aws-cdk/cdk/test/core/test.tag-manager.ts index b34e57341772e..f78d98f233786 100644 --- a/packages/@aws-cdk/cdk/test/core/test.tag-manager.ts +++ b/packages/@aws-cdk/cdk/test/core/test.tag-manager.ts @@ -4,15 +4,15 @@ import { ITaggable, TagManager } from '../../lib/core/tag-manager'; class ChildTagger extends Construct implements ITaggable { public readonly tags: TagManager; - constructor(parent: Construct, name: string) { - super(parent, name); - this.tags = new TagManager(parent); + constructor(scope: Construct, id: string) { + super(scope, id); + this.tags = new TagManager(scope); } } class Child extends Construct { - constructor(parent: Construct, name: string) { - super(parent, name); + constructor(scope: Construct, id: string) { + super(scope, id); } } diff --git a/packages/@aws-cdk/cdk/test/test.app.ts b/packages/@aws-cdk/cdk/test/test.app.ts index 1f3712dfefc87..8c55bc8cc4d45 100644 --- a/packages/@aws-cdk/cdk/test/test.app.ts +++ b/packages/@aws-cdk/cdk/test/test.app.ts @@ -40,11 +40,11 @@ function synth(context?: { [key: string]: any }): cxapi.SynthesizeResponse { const c1 = new MyConstruct(stack2, 's1c2'); // add some metadata - stack1.addMetadata('meta', 111); - r2.addWarning('warning1'); - r2.addWarning('warning2'); - c1.addMetadata('meta', { key: 'value' }); - app.addMetadata('applevel', 123); // apps can also have metadata + stack1.node.addMetadata('meta', 111); + r2.node.addWarning('warning1'); + r2.node.addWarning('warning2'); + c1.node.addMetadata('meta', { key: 'value' }); + app.node.addMetadata('applevel', 123); // apps can also have metadata }); } @@ -148,8 +148,8 @@ export = { key2: 'val2' }); const prog = new App(); - test.deepEqual(prog.getContext('key1'), 'val1'); - test.deepEqual(prog.getContext('key2'), 'val2'); + test.deepEqual(prog.node.getContext('key1'), 'val1'); + test.deepEqual(prog.node.getContext('key2'), 'val2'); test.done(); }, @@ -180,15 +180,15 @@ export = { 'setContext(k,v) can be used to set context programmatically'(test: Test) { const prog = new App(); - prog.setContext('foo', 'bar'); - test.deepEqual(prog.getContext('foo'), 'bar'); + prog.node.setContext('foo', 'bar'); + test.deepEqual(prog.node.getContext('foo'), 'bar'); test.done(); }, 'setContext(k,v) cannot be called after stacks have been added because stacks may use the context'(test: Test) { const prog = new App(); new Stack(prog, 's1'); - test.throws(() => prog.setContext('foo', 'bar')); + test.throws(() => prog.node.setContext('foo', 'bar')); test.done(); }, @@ -196,7 +196,7 @@ export = { class Child extends Construct { public validate() { - return [ `Error from ${this.id}` ]; + return [ `Error from ${this.node.id}` ]; } } @@ -219,8 +219,8 @@ export = { 'app.synthesizeStack(stack) will return a list of missing contextual information'(test: Test) { class MyStack extends Stack { - constructor(parent: App, name: string, props?: StackProps) { - super(parent, name, props); + constructor(scope: App, id: string, props?: StackProps) { + super(scope, id, props); this.reportMissingContext('missing-context-key', { provider: 'fake', @@ -318,11 +318,11 @@ export = { }; class MyConstruct extends Construct { - constructor(parent: Construct, name: string) { - super(parent, name); + constructor(scope: Construct, id: string) { + super(scope, id); new Resource(this, 'r1', { type: 'ResourceType1' }); - new Resource(this, 'r2', { type: 'ResourceType2', properties: { FromContext: this.getContext('ctx1') } }); + new Resource(this, 'r2', { type: 'ResourceType2', properties: { FromContext: this.node.getContext('ctx1') } }); } } diff --git a/packages/@aws-cdk/cdk/test/test.context.ts b/packages/@aws-cdk/cdk/test/test.context.ts index f061a16c4b443..373c5e0dfcea4 100644 --- a/packages/@aws-cdk/cdk/test/test.context.ts +++ b/packages/@aws-cdk/cdk/test/test.context.ts @@ -18,7 +18,7 @@ export = { test.deepEqual(before, [ 'dummy1a', 'dummy1b', 'dummy1c' ]); const key = expectedContextKey(stack); - stack.setContext(key, ['us-east-1a', 'us-east-1b']); + stack.node.setContext(key, ['us-east-1a', 'us-east-1b']); const azs = new AvailabilityZoneProvider(stack).availabilityZones; test.deepEqual(azs, ['us-east-1a', 'us-east-1b']); @@ -32,7 +32,7 @@ export = { test.deepEqual(before, [ 'dummy1a', 'dummy1b', 'dummy1c' ]); const key = expectedContextKey(stack); - stack.setContext(key, 'not-a-list'); + stack.node.setContext(key, 'not-a-list'); test.throws( () => new AvailabilityZoneProvider(stack).availabilityZones @@ -83,7 +83,7 @@ export = { new SSMParameterProvider(stack, {parameterName: 'test'}).parameterValue(); const key = expectedContextKey(stack); - stack.setContext(key, 'abc'); + stack.node.setContext(key, 'abc'); const ssmp = new SSMParameterProvider(stack, {parameterName: 'test'}); const azs = resolve(ssmp.parameterValue()); @@ -101,7 +101,7 @@ export = { test.deepEqual(new AvailabilityZoneProvider(stack).availabilityZones, [ 'dummy1a', 'dummy1b', 'dummy1c' ]); test.deepEqual(new SSMParameterProvider(child, {parameterName: 'foo'}).parameterValue(), 'dummy'); - const output = app.synthesizeStack(stack.id); + const output = app.synthesizeStack(stack.node.id); const azError: MetadataEntry | undefined = output.metadata['/test-stack'].find(x => x.type === cxapi.ERROR_METADATA_KEY); const ssmError: MetadataEntry | undefined = output.metadata['/test-stack/ChildConstruct'].find(x => x.type === cxapi.ERROR_METADATA_KEY); diff --git a/packages/@aws-cdk/cdk/test/test.environment.ts b/packages/@aws-cdk/cdk/test/test.environment.ts index 1e47890f207c9..012c9f211994e 100644 --- a/packages/@aws-cdk/cdk/test/test.environment.ts +++ b/packages/@aws-cdk/cdk/test/test.environment.ts @@ -14,8 +14,8 @@ export = { 'Default account and region can be set in context (`aws:cdk:toolkit:default-account` and `aws:cdk:toolkit:default-region`)'(test: Test) { const app = new App(); - app.setContext(DEFAULT_ACCOUNT_CONTEXT_KEY, 'my-default-account'); - app.setContext(DEFAULT_REGION_CONTEXT_KEY, 'my-default-region'); + app.node.setContext(DEFAULT_ACCOUNT_CONTEXT_KEY, 'my-default-account'); + app.node.setContext(DEFAULT_REGION_CONTEXT_KEY, 'my-default-region'); const stack = new Stack(app, 'my-stack'); @@ -28,8 +28,8 @@ export = { 'If only `env.region` or `env.account` are specified, defaults will be used for the other'(test: Test) { const app = new App(); - app.setContext(DEFAULT_ACCOUNT_CONTEXT_KEY, 'my-default-account'); - app.setContext(DEFAULT_REGION_CONTEXT_KEY, 'my-default-region'); + app.node.setContext(DEFAULT_ACCOUNT_CONTEXT_KEY, 'my-default-account'); + app.node.setContext(DEFAULT_REGION_CONTEXT_KEY, 'my-default-region'); const stack1 = new Stack(app, 'S1', { env: { region: 'only-region' } }); const stack2 = new Stack(app, 'S2', { env: { account: 'only-account' } }); diff --git a/packages/@aws-cdk/runtime-values/lib/rtv.ts b/packages/@aws-cdk/runtime-values/lib/rtv.ts index d909df03cf86c..53be77ca90d30 100644 --- a/packages/@aws-cdk/runtime-values/lib/rtv.ts +++ b/packages/@aws-cdk/runtime-values/lib/rtv.ts @@ -51,10 +51,10 @@ export class RuntimeValue extends cdk.Construct { */ public readonly parameterArn: string; - constructor(parent: cdk.Construct, name: string, props: RuntimeValueProps) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: RuntimeValueProps) { + super(scope, id); - this.parameterName = `/rtv/${new cdk.AwsStackName()}/${props.package}/${name}`; + this.parameterName = `/rtv/${new cdk.AwsStackName()}/${props.package}/${id}`; new ssm.CfnParameter(this, 'Parameter', { name: this.parameterName, diff --git a/packages/@aws-cdk/runtime-values/test/integ.rtv.lambda.ts b/packages/@aws-cdk/runtime-values/test/integ.rtv.lambda.ts index 02a311f4e7d98..ab9432cb88353 100644 --- a/packages/@aws-cdk/runtime-values/test/integ.rtv.lambda.ts +++ b/packages/@aws-cdk/runtime-values/test/integ.rtv.lambda.ts @@ -8,8 +8,8 @@ function runtimeCode(_event: any, _context: any, callback: any) { } class TestStack extends cdk.Stack { - constructor(parent: cdk.App, name: string) { - super(parent, name); + constructor(scope: cdk.App, id: string) { + super(scope, id); const queue = new sqs.Queue(this, 'MyQueue'); const fn = new lambda.Function(this, 'MyFunction', { diff --git a/packages/@aws-cdk/runtime-values/test/test.rtv.ts b/packages/@aws-cdk/runtime-values/test/test.rtv.ts index dc88dc255f031..4cd4f6c6a95ab 100644 --- a/packages/@aws-cdk/runtime-values/test/test.rtv.ts +++ b/packages/@aws-cdk/runtime-values/test/test.rtv.ts @@ -20,8 +20,8 @@ export = { class RuntimeValueTest extends cdk.Construct { - constructor(parent: cdk.Construct, name: string) { - super(parent, name); + constructor(scope: cdk.Construct, id: string) { + super(scope, id); const queue = new sqs.CfnQueue(this, 'Queue', {}); diff --git a/packages/aws-cdk/lib/init-templates/app/typescript/lib/%name%-stack.template.ts b/packages/aws-cdk/lib/init-templates/app/typescript/lib/%name%-stack.template.ts index 00704b84cd968..20f82b7633fc9 100644 --- a/packages/aws-cdk/lib/init-templates/app/typescript/lib/%name%-stack.template.ts +++ b/packages/aws-cdk/lib/init-templates/app/typescript/lib/%name%-stack.template.ts @@ -1,8 +1,8 @@ import cdk = require('@aws-cdk/cdk'); export class %name.PascalCased%Stack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { + super(scope, id, props); // The code that defines your stack goes here } diff --git a/packages/aws-cdk/lib/init-templates/lib/typescript/lib/index.template.ts b/packages/aws-cdk/lib/init-templates/lib/typescript/lib/index.template.ts index f89e1abfa2343..b32dba1c03b57 100644 --- a/packages/aws-cdk/lib/init-templates/lib/typescript/lib/index.template.ts +++ b/packages/aws-cdk/lib/init-templates/lib/typescript/lib/index.template.ts @@ -15,8 +15,8 @@ export class %name.PascalCased% extends cdk.Construct { /** @returns the ARN of the SQS queue */ public readonly queueArn: string; - constructor(parent: cdk.Construct, name: string, props: %name.PascalCased%Props = {}) { - super(parent, name); + constructor(scope: cdk.Construct, id: string, props: %name.PascalCased%Props = {}) { + super(scope, id); const queue = new sqs.Queue(this, '%name.PascalCased%Queue', { visibilityTimeoutSec: props.visibilityTimeout || 300 diff --git a/packages/aws-cdk/lib/init-templates/sample-app/typescript/lib/%name%-stack.template.ts b/packages/aws-cdk/lib/init-templates/sample-app/typescript/lib/%name%-stack.template.ts index 9703102063490..4424f45064b21 100644 --- a/packages/aws-cdk/lib/init-templates/sample-app/typescript/lib/%name%-stack.template.ts +++ b/packages/aws-cdk/lib/init-templates/sample-app/typescript/lib/%name%-stack.template.ts @@ -3,8 +3,8 @@ import sqs = require('@aws-cdk/aws-sqs'); import cdk = require('@aws-cdk/cdk'); export class %name.PascalCased%Stack extends cdk.Stack { - constructor(parent: cdk.App, name: string, props?: cdk.StackProps) { - super(parent, name, props); + constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { + super(scope, id, props); const queue = new sqs.Queue(this, '%name.PascalCased%Queue', { visibilityTimeoutSec: 300 diff --git a/tools/cfn2ts/lib/codegen.ts b/tools/cfn2ts/lib/codegen.ts index 61e68d09d26a3..63a65507d666c 100644 --- a/tools/cfn2ts/lib/codegen.ts +++ b/tools/cfn2ts/lib/codegen.ts @@ -256,20 +256,20 @@ export default class CodeGenerator { this.code.line('/**'); this.code.line(` * Creates a new ${quoteCode(resourceName.specName!.fqn)}.`); this.code.line(' *'); - this.code.line(` * @param parent the ${quoteCode(CONSTRUCT_CLASS)} this ${quoteCode(resourceName.className)} is a part of`); - this.code.line(` * @param name the name of the resource in the ${quoteCode(CONSTRUCT_CLASS)} tree`); - this.code.line(` * @param properties the properties of this ${quoteCode(resourceName.className)}`); + this.code.line(` * @param scope scope in which this resource is defined`); + this.code.line(` * @param id scoped id of the resource`); + this.code.line(` * @param props resource properties`); this.code.line(' */'); const optionalProps = spec.Properties && !Object.values(spec.Properties).some(p => p.Required); - const propsArgument = propsType ? `, properties${optionalProps ? '?' : ''}: ${propsType.className}` : ''; - this.code.openBlock(`constructor(parent: ${CONSTRUCT_CLASS}, name: string${propsArgument})`); - this.code.line(`super(parent, name, { type: ${resourceName.className}.resourceTypeName${propsType ? ', properties' : ''} });`); + const propsArgument = propsType ? `, props${optionalProps ? '?' : ''}: ${propsType.className}` : ''; + this.code.openBlock(`constructor(scope: ${CONSTRUCT_CLASS}, id: string${propsArgument})`); + this.code.line(`super(scope, id, { type: ${resourceName.className}.resourceTypeName${propsType ? ', properties: props' : ''} });`); // verify all required properties if (spec.Properties) { for (const propName of Object.keys(spec.Properties)) { const prop = spec.Properties[propName]; if (prop.Required) { - this.code.line(`${CORE}.requireProperty(properties, '${genspec.cloudFormationToScriptName(propName)}', this);`); + this.code.line(`${CORE}.requireProperty(props, '${genspec.cloudFormationToScriptName(propName)}', this);`); } } } @@ -298,7 +298,7 @@ export default class CodeGenerator { } if (deprecated) { - this.code.line(`this.addWarning('DEPRECATION: ${deprecation}');`); + this.code.line(`this.node.addWarning('DEPRECATION: ${deprecation}');`); } this.code.closeBlock();