11import type { IConstruct } from 'constructs' ;
22import * as s3 from 'aws-cdk-lib/aws-s3' ;
3- import { CustomResource , Stack , Tags } from 'aws-cdk-lib' ;
3+ import { CfnResource , CustomResource , Tags } from 'aws-cdk-lib' ;
44import { AutoDeleteObjectsProvider } from '../../custom-resource-handlers/aws-s3/auto-delete-objects-provider' ;
55import type { IMixin } from '../../core' ;
66
@@ -9,30 +9,30 @@ const AUTO_DELETE_OBJECTS_TAG = 'aws-cdk:auto-delete-objects';
99
1010/**
1111 * S3-specific mixin for auto-deleting objects.
12+ * @mixin true
1213 */
1314export class AutoDeleteObjects implements IMixin {
14- supports ( construct : IConstruct ) : boolean {
15- return construct instanceof s3 . CfnBucket ;
15+ supports ( construct : IConstruct ) : construct is s3 . CfnBucket {
16+ return CfnResource . isCfnResource ( construct ) && construct . cfnResourceType === s3 . CfnBucket . CFN_RESOURCE_TYPE_NAME ;
1617 }
1718
1819 applyTo ( construct : IConstruct ) : IConstruct {
19- if ( ! ( construct instanceof s3 . CfnBucket ) ) {
20+ if ( ! this . supports ( construct ) ) {
2021 return construct ;
2122 }
2223
23- const stack = Stack . of ( construct ) ;
24- const bucketName = construct . ref ;
24+ const ref = construct . bucketRef ;
2525
2626 const provider = AutoDeleteObjectsProvider . getOrCreateProvider ( construct , AUTO_DELETE_OBJECTS_RESOURCE_TYPE , {
2727 useCfnResponseWrapper : false ,
28- description : `Lambda function for auto-deleting objects in ${ bucketName } S3 bucket.` ,
28+ description : `Lambda function for auto-deleting objects in ${ ref . bucketName } S3 bucket.` ,
2929 } ) ;
3030
3131 // Get or create bucket policy
3232 let policy = construct . node . tryFindChild ( 'Policy' ) as s3 . CfnBucketPolicy | undefined ;
3333 if ( ! policy ) {
3434 policy = new s3 . CfnBucketPolicy ( construct , 'Policy' , {
35- bucket : bucketName ,
35+ bucket : ref . bucketName ,
3636 policyDocument : {
3737 Statement : [ ] ,
3838 } ,
@@ -54,16 +54,16 @@ export class AutoDeleteObjects implements IMixin {
5454 's3:DeleteObject*' ,
5555 ] ,
5656 Resource : [
57- stack . resolve ( `arn:aws:s3::: ${ bucketName } ` ) ,
58- stack . resolve ( `arn:aws:s3::: ${ bucketName } /*`) ,
57+ ref . bucketArn ,
58+ ` ${ ref . bucketArn } /*`,
5959 ] ,
6060 } ) ;
6161
6262 const customResource = new CustomResource ( construct , 'AutoDeleteObjectsCustomResource' , {
6363 resourceType : AUTO_DELETE_OBJECTS_RESOURCE_TYPE ,
6464 serviceToken : provider . serviceToken ,
6565 properties : {
66- BucketName : bucketName ,
66+ BucketName : ref . bucketName ,
6767 } ,
6868 } ) ;
6969
0 commit comments