Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose oai #1286

Merged
merged 1 commit into from
Jan 23, 2024
Merged
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
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
Loading