Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(example-library): update example resource #32802

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions packages/@aws-cdk/example-construct-library/lib/example-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -319,7 +319,7 @@ export interface ExampleResourceProps {
*
* @default RemovalPolicy.RETAIN
*/
readonly removalPolicy?: core.RemovalPolicy;
readonly removalPolicy?: RemovalPolicy;
}

/**
Expand Down Expand Up @@ -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));
}

Expand All @@ -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,
Expand Down Expand Up @@ -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}'`);
Expand All @@ -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',
Expand All @@ -460,7 +460,7 @@ export class ExampleResource extends ExampleResourceBase {
// and the ARN for your resource is of the form 'arn:aws:<service>:<region>:<account>: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 -
Expand All @@ -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));

Expand Down Expand Up @@ -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,
});
}
}
Loading