From 5351f765a1b13c9af890f4355f5a5c8dca76d28a Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Tue, 28 Nov 2023 17:19:49 -0500 Subject: [PATCH] chore(s3): use ICfnBucket --- packages/aws-cdk-lib/aws-s3/lib/bucket.ts | 32 +++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/aws-cdk-lib/aws-s3/lib/bucket.ts b/packages/aws-cdk-lib/aws-s3/lib/bucket.ts index 8b3e2fa5b6a61..c8a2a8dc2c45e 100644 --- a/packages/aws-cdk-lib/aws-s3/lib/bucket.ts +++ b/packages/aws-cdk-lib/aws-s3/lib/bucket.ts @@ -6,7 +6,7 @@ import { IBucketNotificationDestination } from './destination'; import { BucketNotifications } from './notifications-resource'; import * as perms from './perms'; import { LifecycleRule } from './rule'; -import { CfnBucket } from './s3.generated'; +import { CfnBucket, ICfnBucket } from './s3.generated'; import { parseBucketArn, parseBucketName } from './util'; import * as events from '../../aws-events'; import * as iam from '../../aws-iam'; @@ -36,7 +36,7 @@ import * as regionInformation from '../../region-info'; const AUTO_DELETE_OBJECTS_RESOURCE_TYPE = 'Custom::S3AutoDeleteObjects'; const AUTO_DELETE_OBJECTS_TAG = 'aws-cdk:auto-delete-objects'; -export interface IBucket extends IResource { +export interface IBucket extends IResource, ICfnBucket { /** * The ARN of the bucket. * @attribute @@ -498,7 +498,15 @@ export interface BucketAttributes { * */ export abstract class BucketBase extends Resource implements IBucket { + public abstract readonly attrArn: string; + public abstract readonly attrBucketName?: string; + /** + * @deprecated use attrArn + */ public abstract readonly bucketArn: string; + /** + * @deprecated use attrBucketName + */ public abstract readonly bucketName: string; public abstract readonly bucketDomainName: string; public abstract readonly bucketWebsiteUrl: string; @@ -1674,8 +1682,10 @@ export class Bucket extends BucketBase { const websiteDomain = `${bucketName}.${staticDomainEndpoint}`; class Import extends BucketBase { - public readonly bucketName = bucketName!; - public readonly bucketArn = parseBucketArn(scope, attrs); + public readonly attrArn = parseBucketArn(scope, attrs); + public readonly attrBucketName = bucketName!; + public readonly bucketName = this.attrBucketName; + public readonly bucketArn = this.attrArn; public readonly bucketDomainName = attrs.bucketDomainName || `${bucketName}.s3.${urlSuffix}`; public readonly bucketWebsiteUrl = attrs.bucketWebsiteUrl || `http://${websiteDomain}`; public readonly bucketWebsiteDomainName = attrs.bucketWebsiteUrl ? Fn.select(2, Fn.split('/', attrs.bucketWebsiteUrl)) : websiteDomain; @@ -1738,8 +1748,10 @@ export class Bucket extends BucketBase { } return new class extends BucketBase { - public readonly bucketArn = cfnBucket.attrArn; - public readonly bucketName = cfnBucket.ref; + public readonly attrArn = cfnBucket.attrArn; + public readonly bucketArn = this.attrArn; + public readonly attrBucketName = cfnBucket.ref; + public readonly bucketName = this.attrBucketName; public readonly bucketDomainName = cfnBucket.attrDomainName; public readonly bucketDualStackDomainName = cfnBucket.attrDualStackDomainName; public readonly bucketRegionalDomainName = cfnBucket.attrRegionalDomainName; @@ -1807,6 +1819,8 @@ export class Bucket extends BucketBase { } } + public readonly attrArn: string; + public readonly attrBucketName?: string; public readonly bucketArn: string; public readonly bucketName: string; public readonly bucketDomainName: string; @@ -1870,13 +1884,15 @@ export class Bucket extends BucketBase { this.encryptionKey = encryptionKey; this.eventBridgeEnabled = props.eventBridgeEnabled; - this.bucketName = this.getResourceNameAttribute(resource.ref); - this.bucketArn = this.getResourceArnAttribute(resource.attrArn, { + this.attrBucketName = this.getResourceNameAttribute(resource.ref); + this.bucketName = this.attrBucketName; + this.attrArn = this.getResourceArnAttribute(resource.attrArn, { region: '', account: '', service: 's3', resource: this.physicalName, }); + this.bucketArn = this.attrArn; this.bucketDomainName = resource.attrDomainName; this.bucketWebsiteUrl = resource.attrWebsiteUrl;