Skip to content
Open
Show file tree
Hide file tree
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
31 changes: 21 additions & 10 deletions packages/aws-cdk-lib/aws-kms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,31 @@ for the `AWS::KMS::Key` CloudFormation type:

```ts nofixture
import { CfnResource } from 'aws-cdk-lib';
import { IResourcePolicyFactory, IResourceWithPolicyV2, PolicyStatement, ResourceWithPolicies } from 'aws-cdk-lib/aws-iam';
import { Construct, IConstruct } from 'constructs';
import { AddToResourcePolicyResult, IResourcePolicyFactory, IResourceWithPolicyV2, PolicyStatement, ResourceWithPolicies } from 'aws-cdk-lib/aws-iam';
import { ResourceEnvironment } from 'aws-cdk-lib/interfaces';
import { Construct } from 'constructs';


declare const scope: Construct;

class MyResourceWithPolicy implements IResourceWithPolicyV2 {
public readonly env: ResourceEnvironment;
private readonly resource: CfnResource;

constructor(resource: CfnResource) {
this.resource = resource;
this.env = resource.env;
}

public addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResult {
// custom implementation to add the statement to the resource policy
return { statementAdded: true, policyDependable: this.resource };
}
}

class MyFactory implements IResourcePolicyFactory {
forResource(resource: CfnResource): IResourceWithPolicyV2 {
return {
env: resource.env,
addToResourcePolicy(statement: PolicyStatement) {
// custom implementation to add the statement to the resource policy
return { statementAdded: true, policyDependable: resource };
}
}
public forResource(resource: CfnResource): IResourceWithPolicyV2 {
return new MyResourceWithPolicy(resource);
}
}

Expand Down
31 changes: 21 additions & 10 deletions packages/aws-cdk-lib/aws-s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,30 @@ for the `AWS::S3::Bucket` CloudFormation type:

```ts nofixture
import { CfnResource } from 'aws-cdk-lib';
import { IResourcePolicyFactory, IResourceWithPolicyV2, PolicyStatement, ResourceWithPolicies } from 'aws-cdk-lib/aws-iam';
import { Construct, IConstruct } from 'constructs';
import { AddToResourcePolicyResult, IResourcePolicyFactory, IResourceWithPolicyV2, PolicyStatement, ResourceWithPolicies } from 'aws-cdk-lib/aws-iam';
import { ResourceEnvironment } from 'aws-cdk-lib/interfaces';
import { Construct } from 'constructs';

declare const scope: Construct;

class MyResourceWithPolicy implements IResourceWithPolicyV2 {
public readonly env: ResourceEnvironment;
private readonly resource: CfnResource;

constructor(resource: CfnResource) {
this.resource = resource;
this.env = resource.env;
}

public addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResult {
// custom implementation to add the statement to the resource policy
return { statementAdded: true, policyDependable: this.resource };
}
}

class MyFactory implements IResourcePolicyFactory {
forResource(resource: CfnResource): IResourceWithPolicyV2 {
return {
env: resource.env,
addToResourcePolicy(statement: PolicyStatement) {
// custom implementation to add the statement to the resource policy
return { statementAdded: true, policyDependable: resource };
}
}
public forResource(resource: CfnResource): IResourceWithPolicyV2 {
return new MyResourceWithPolicy(resource);
}
}

Expand Down
Loading