Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #176 from aligent/feature/s3-access-logs
Browse files Browse the repository at this point in the history
Add s3 access logging option
  • Loading branch information
John Smith authored Apr 4, 2022
2 parents 4498403 + 699754b commit ff28884
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/static-hosting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface StaticHostingProps {
createPublisherUser?: boolean;
extraDistributionCnames?: ReadonlyArray<string>;
enableCloudFrontAccessLogging?: boolean;
enableS3AccessLogging?: boolean;
zoneName?: string;
/**
* Used to add Custom origins and behaviors
Expand Down Expand Up @@ -46,10 +47,30 @@ export class StaticHosting extends Construct {
siteNameArray.concat(props.extraDistributionCnames) :
siteNameArray;


const s3LoggingBucket = (props.enableS3AccessLogging)
? new Bucket(this, 'S3LoggingBucket', {
bucketName: `${siteName}-s3-access-logs`,
encryption: BucketEncryption.S3_MANAGED,
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
removalPolicy: RemovalPolicy.RETAIN,
enforceSSL: true
})
: undefined;

if (s3LoggingBucket) {
new CfnOutput(this, 'S3LoggingBucketName', {
description: "S3 Logs",
value: s3LoggingBucket.bucketName,
});
}

const bucket = new Bucket(this, 'ContentBucket', {
bucketName: siteName,
encryption: BucketEncryption.S3_MANAGED,
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
serverAccessLogsBucket: s3LoggingBucket,
enforceSSL: true
});

new CfnOutput(this, 'Bucket', {
Expand Down Expand Up @@ -99,6 +120,7 @@ export class StaticHosting extends Construct {
encryption: BucketEncryption.S3_MANAGED,
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
removalPolicy: RemovalPolicy.RETAIN,
enforceSSL: true
})
: undefined;

Expand Down

0 comments on commit ff28884

Please sign in to comment.