Skip to content

Commit

Permalink
feat: expose oai
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOrangePuff committed Jan 23, 2024
1 parent b7b423d commit 4946e87
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/static-hosting/lib/static-hosting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
LambdaEdgeEventType,
OriginAccessIdentity,
IDistribution,
IOriginAccessIdentity,
} from "aws-cdk-lib/aws-cloudfront";
import { HttpOrigin, S3Origin } from "aws-cdk-lib/aws-cloudfront-origins";
import {
Expand Down Expand Up @@ -133,6 +134,7 @@ type Writeable<T> = { -readonly [P in keyof T]: T[P] };
export class StaticHosting extends Construct {
public readonly distribution: IDistribution;
public readonly bucket: IBucket;
public readonly oai: IOriginAccessIdentity;

private staticFiles = [
"js",
Expand Down Expand Up @@ -196,11 +198,11 @@ export class StaticHosting extends Construct {
...props.s3ExtendedProps,
});

const oai = new OriginAccessIdentity(this, "OriginAccessIdentity", {
this.oai = new OriginAccessIdentity(this, "OriginAccessIdentity", {
comment: "Allow CloudFront to access S3",
});

this.bucket.grantRead(oai);
this.bucket.grantRead(this.oai);

new CfnOutput(this, "Bucket", {
description: "BucketName",
Expand Down Expand Up @@ -251,7 +253,7 @@ export class StaticHosting extends Construct {
: undefined;

if (loggingBucket) {
loggingBucket.grantWrite(oai);
loggingBucket.grantWrite(this.oai);

new CfnOutput(this, "LoggingBucketName", {
description: "CloudFront Logs",
Expand All @@ -261,7 +263,7 @@ export class StaticHosting extends Construct {
}

const s3Origin = new S3Origin(this.bucket, {
originAccessIdentity: oai,
originAccessIdentity: this.oai,
});
let backendOrigin = undefined;

Expand Down

0 comments on commit 4946e87

Please sign in to comment.