diff --git a/packages/@aws-cdk/example-construct-library/lib/example-resource.ts b/packages/@aws-cdk/example-construct-library/lib/example-resource.ts index 8308bb0a340f5..9715ef09581e9 100644 --- a/packages/@aws-cdk/example-construct-library/lib/example-resource.ts +++ b/packages/@aws-cdk/example-construct-library/lib/example-resource.ts @@ -11,9 +11,9 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2'; import * as events from 'aws-cdk-lib/aws-events'; import * as iam from 'aws-cdk-lib/aws-iam'; import * as s3 from 'aws-cdk-lib/aws-s3'; -import * as core from 'aws-cdk-lib/core'; import { Construct } from 'constructs'; -// for files that are part of this package, we do import individual classes or functions +// for files that are part of this package or part of core, we do import individual classes or functions +import { CfnWaitCondition, CfnWaitConditionHandle, Fn, IResource, RemovalPolicy, Resource, Stack, Token } from 'aws-cdk-lib/core'; import { exampleResourceArnComponents } from './private/example-resource-common'; /** @@ -58,7 +58,7 @@ import { exampleResourceArnComponents } from './private/example-resource-common' */ export interface IExampleResource extends // all L2 interfaces need to extend IResource - core.IResource, + IResource, // Only for resources that have an associated IAM Role. // Allows this resource to be the target in calls like bucket.grantRead(exampleResource). @@ -149,7 +149,7 @@ export interface IExampleResource extends * * Notice that the class is not exported - it's not part of the public API of this module! */ -abstract class ExampleResourceBase extends core.Resource implements IExampleResource { +abstract class ExampleResourceBase extends Resource implements IExampleResource { // these stay abstract at this level public abstract readonly exampleResourceArn: string; public abstract readonly exampleResourceName: string; @@ -319,7 +319,7 @@ export interface ExampleResourceProps { * * @default RemovalPolicy.RETAIN */ - readonly removalPolicy?: core.RemovalPolicy; + readonly removalPolicy?: RemovalPolicy; } /** @@ -364,7 +364,7 @@ export class ExampleResource extends ExampleResourceBase { // using the Stack.formatArn helper method from the core library. // We have to know the ARN components of ExampleResource in a few places, so, // to avoid duplication, extract that into a module-private function - public readonly exampleResourceArn = core.Stack.of(scope) + public readonly exampleResourceArn = Stack.of(scope) .formatArn(exampleResourceArnComponents(exampleResourceName)); } @@ -382,8 +382,8 @@ export class ExampleResource extends ExampleResourceBase { /** * The constructor of a construct has always 3 arguments: - * the parent Construct, the string identifier, - * locally unique within the scope of the parent, + * the parent Construct, the string identifier + * (locally unique within the scope of the parent), * and a properties struct. * * If the props only have optional properties, like in our case, @@ -412,7 +412,7 @@ export class ExampleResource extends ExampleResourceBase { // so, we need to use the Token.isUnresolved() method from the core library // to skip validation in that case. if (props.waitConditionHandleName !== undefined && - !core.Token.isUnresolved(props.waitConditionHandleName) && + !Token.isUnresolved(props.waitConditionHandleName) && !/^[_a-zA-Z]+$/.test(props.waitConditionHandleName)) { throw new Error('waitConditionHandleName must be non-empty and contain only letters and underscores, ' + `got: '${props.waitConditionHandleName}'`); @@ -435,12 +435,12 @@ export class ExampleResource extends ExampleResourceBase { // This guarantees that they get scoped correctly, // and the CDK will make sure their locally-unique identifiers // are globally unique, which makes your L2 compose. - const waitConditionHandle = new core.CfnWaitConditionHandle(this, 'WaitConditionHandle'); + const waitConditionHandle = new CfnWaitConditionHandle(this, 'WaitConditionHandle'); // The 'main' L1 you create should always have the logical ID 'Resource'. // This is important, so that the ConstructNode.defaultChild method works correctly. // The local variable representing the L1 is often called 'resource' as well. - const resource = new core.CfnWaitCondition(this, 'Resource', { + const resource = new CfnWaitCondition(this, 'Resource', { count: 0, handle: waitConditionHandle.ref, timeout: '10', @@ -460,7 +460,7 @@ export class ExampleResource extends ExampleResourceBase { // and the ARN for your resource is of the form 'arn:aws::::resource/physical-name', // which is quite common, // you can use Fn::Select and Fn::Split to take out the part after the '/' from the ARN: - core.Fn.select(1, core.Fn.split('/', resource.ref)), + Fn.select(1, Fn.split('/', resource.ref)), ); this.exampleResourceArn = this.getResourceArnAttribute( // A lot of the L1 classes have an 'attrArn' property - @@ -469,7 +469,7 @@ export class ExampleResource extends ExampleResourceBase { // you can often formulate the ARN yourself, // using the Stack.formatArn helper function. // Here, we assume resource.ref returns the physical name of the resource. - core.Stack.of(this).formatArn(exampleResourceArnComponents(resource.ref)), + Stack.of(this).formatArn(exampleResourceArnComponents(resource.ref)), // always use the protected physicalName property for this second argument exampleResourceArnComponents(this.physicalName)); @@ -505,7 +505,7 @@ export class ExampleResource extends ExampleResourceBase { // this is how you apply the removal policy resource.applyRemovalPolicy(props.removalPolicy, { // this is the default to apply if props.removalPolicy is undefined - default: core.RemovalPolicy.RETAIN, + default: RemovalPolicy.RETAIN, }); } }