Skip to content

Commit f2ade56

Browse files
authored
chore(example-library): update example resource (#32802)
### Issue # (if applicable) N/A ### Reason for this change The `example-resource.ts` library is slightly out of date with how CDK is structured today. These changes aim to align the file with what we do today. ### Description of changes Altered the core import, as we do not (AFAIK) follow this convention any more: ```ts import * as core from 'aws-cdk-lib/core'; // before import { ... } from 'aws-cdk-lib/core'; // after ``` In addition, slightly changed around some comment phrasing. ### Describe any new or updated permissions being added N/A ### Description of how you validated changes Semantic changes; tests still continue to pass. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 8a96454 commit f2ade56

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

packages/@aws-cdk/example-construct-library/lib/example-resource.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2';
1111
import * as events from 'aws-cdk-lib/aws-events';
1212
import * as iam from 'aws-cdk-lib/aws-iam';
1313
import * as s3 from 'aws-cdk-lib/aws-s3';
14-
import * as core from 'aws-cdk-lib/core';
1514
import { Construct } from 'constructs';
16-
// for files that are part of this package, we do import individual classes or functions
15+
// for files that are part of this package or part of core, we do import individual classes or functions
16+
import { CfnWaitCondition, CfnWaitConditionHandle, Fn, IResource, RemovalPolicy, Resource, Stack, Token } from 'aws-cdk-lib/core';
1717
import { exampleResourceArnComponents } from './private/example-resource-common';
1818

1919
/**
@@ -58,7 +58,7 @@ import { exampleResourceArnComponents } from './private/example-resource-common'
5858
*/
5959
export interface IExampleResource extends
6060
// all L2 interfaces need to extend IResource
61-
core.IResource,
61+
IResource,
6262

6363
// Only for resources that have an associated IAM Role.
6464
// Allows this resource to be the target in calls like bucket.grantRead(exampleResource).
@@ -149,7 +149,7 @@ export interface IExampleResource extends
149149
*
150150
* Notice that the class is not exported - it's not part of the public API of this module!
151151
*/
152-
abstract class ExampleResourceBase extends core.Resource implements IExampleResource {
152+
abstract class ExampleResourceBase extends Resource implements IExampleResource {
153153
// these stay abstract at this level
154154
public abstract readonly exampleResourceArn: string;
155155
public abstract readonly exampleResourceName: string;
@@ -319,7 +319,7 @@ export interface ExampleResourceProps {
319319
*
320320
* @default RemovalPolicy.RETAIN
321321
*/
322-
readonly removalPolicy?: core.RemovalPolicy;
322+
readonly removalPolicy?: RemovalPolicy;
323323
}
324324

325325
/**
@@ -364,7 +364,7 @@ export class ExampleResource extends ExampleResourceBase {
364364
// using the Stack.formatArn helper method from the core library.
365365
// We have to know the ARN components of ExampleResource in a few places, so,
366366
// to avoid duplication, extract that into a module-private function
367-
public readonly exampleResourceArn = core.Stack.of(scope)
367+
public readonly exampleResourceArn = Stack.of(scope)
368368
.formatArn(exampleResourceArnComponents(exampleResourceName));
369369
}
370370

@@ -382,8 +382,8 @@ export class ExampleResource extends ExampleResourceBase {
382382

383383
/**
384384
* The constructor of a construct has always 3 arguments:
385-
* the parent Construct, the string identifier,
386-
* locally unique within the scope of the parent,
385+
* the parent Construct, the string identifier
386+
* (locally unique within the scope of the parent),
387387
* and a properties struct.
388388
*
389389
* If the props only have optional properties, like in our case,
@@ -412,7 +412,7 @@ export class ExampleResource extends ExampleResourceBase {
412412
// so, we need to use the Token.isUnresolved() method from the core library
413413
// to skip validation in that case.
414414
if (props.waitConditionHandleName !== undefined &&
415-
!core.Token.isUnresolved(props.waitConditionHandleName) &&
415+
!Token.isUnresolved(props.waitConditionHandleName) &&
416416
!/^[_a-zA-Z]+$/.test(props.waitConditionHandleName)) {
417417
throw new Error('waitConditionHandleName must be non-empty and contain only letters and underscores, ' +
418418
`got: '${props.waitConditionHandleName}'`);
@@ -435,12 +435,12 @@ export class ExampleResource extends ExampleResourceBase {
435435
// This guarantees that they get scoped correctly,
436436
// and the CDK will make sure their locally-unique identifiers
437437
// are globally unique, which makes your L2 compose.
438-
const waitConditionHandle = new core.CfnWaitConditionHandle(this, 'WaitConditionHandle');
438+
const waitConditionHandle = new CfnWaitConditionHandle(this, 'WaitConditionHandle');
439439

440440
// The 'main' L1 you create should always have the logical ID 'Resource'.
441441
// This is important, so that the ConstructNode.defaultChild method works correctly.
442442
// The local variable representing the L1 is often called 'resource' as well.
443-
const resource = new core.CfnWaitCondition(this, 'Resource', {
443+
const resource = new CfnWaitCondition(this, 'Resource', {
444444
count: 0,
445445
handle: waitConditionHandle.ref,
446446
timeout: '10',
@@ -460,7 +460,7 @@ export class ExampleResource extends ExampleResourceBase {
460460
// and the ARN for your resource is of the form 'arn:aws:<service>:<region>:<account>:resource/physical-name',
461461
// which is quite common,
462462
// you can use Fn::Select and Fn::Split to take out the part after the '/' from the ARN:
463-
core.Fn.select(1, core.Fn.split('/', resource.ref)),
463+
Fn.select(1, Fn.split('/', resource.ref)),
464464
);
465465
this.exampleResourceArn = this.getResourceArnAttribute(
466466
// A lot of the L1 classes have an 'attrArn' property -
@@ -469,7 +469,7 @@ export class ExampleResource extends ExampleResourceBase {
469469
// you can often formulate the ARN yourself,
470470
// using the Stack.formatArn helper function.
471471
// Here, we assume resource.ref returns the physical name of the resource.
472-
core.Stack.of(this).formatArn(exampleResourceArnComponents(resource.ref)),
472+
Stack.of(this).formatArn(exampleResourceArnComponents(resource.ref)),
473473
// always use the protected physicalName property for this second argument
474474
exampleResourceArnComponents(this.physicalName));
475475

@@ -505,7 +505,7 @@ export class ExampleResource extends ExampleResourceBase {
505505
// this is how you apply the removal policy
506506
resource.applyRemovalPolicy(props.removalPolicy, {
507507
// this is the default to apply if props.removalPolicy is undefined
508-
default: core.RemovalPolicy.RETAIN,
508+
default: RemovalPolicy.RETAIN,
509509
});
510510
}
511511
}

0 commit comments

Comments
 (0)