diff --git a/packages/static-hosting/lib/static-hosting.ts b/packages/static-hosting/lib/static-hosting.ts index 1299c0f3..a7bc58b3 100644 --- a/packages/static-hosting/lib/static-hosting.ts +++ b/packages/static-hosting/lib/static-hosting.ts @@ -119,6 +119,9 @@ export interface ResponseHeaderMappings { type Writeable = { -readonly [P in keyof T]: T[P] }; export class StaticHosting extends Construct { + public readonly distribution: IDistribution; + public readonly bucket: IBucket; + private staticFiles = [ "js", "css", @@ -172,7 +175,7 @@ export class StaticHosting extends Construct { }); } - const bucket = new Bucket(this, "ContentBucket", { + this.bucket = new Bucket(this, "ContentBucket", { bucketName: siteName, encryption: BucketEncryption.S3_MANAGED, blockPublicAccess: BlockPublicAccess.BLOCK_ALL, @@ -185,7 +188,7 @@ export class StaticHosting extends Construct { comment: "Allow CloudFront to access S3", }); - bucket.grantRead(oai); + this.bucket.grantRead(oai); new CfnOutput(this, "Bucket", { description: "BucketName", @@ -212,7 +215,7 @@ export class StaticHosting extends Construct { : undefined; if (publisherGroup) { - bucket.grantReadWrite(publisherGroup); + this.bucket.grantReadWrite(publisherGroup); new CfnOutput(this, "PublisherGroupName", { description: "PublisherGroup", @@ -394,7 +397,7 @@ export class StaticHosting extends Construct { "cloudfront:ListInvalidations", ], resources: [ - `arn:aws:cloudfront::*:distribution/${distribution.distributionId}`, + `arn:aws:cloudfront::*:distribution/${this.distribution.distributionId}`, ], }); @@ -409,12 +412,12 @@ export class StaticHosting extends Construct { } new CfnOutput(this, "DistributionId", { description: "DistributionId", - value: distribution.distributionId, + value: this.distribution.distributionId, exportName: `${exportPrefix}DistributionID`, }); new CfnOutput(this, "DistributionDomainName", { description: "DistributionDomainName", - value: distribution.distributionDomainName, + value: this.distribution.distributionDomainName, exportName: `${exportPrefix}DistributionName`, }); @@ -425,7 +428,7 @@ export class StaticHosting extends Construct { new ARecord(this, "SiteAliasRecord", { recordName: siteName, - target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)), + target: RecordTarget.fromAlias(new CloudFrontTarget(this.distribution)), zone: zone, }); }