Skip to content

Commit

Permalink
feat(aws-cloudfront-mediastore): added cloudFrontLoggingBucketProp to…
Browse files Browse the repository at this point in the history
… cloudfront-mediastore (#457)

* added cloudFrontLoggingBucketProp to cloudfront-mediastore

* Added integ test for custom cloudfront bucket

* fixed typos in test names

* delete unknown symbol

Co-authored-by: root <root@ip-172-31-19-83.ec2.internal>
  • Loading branch information
mickychetta and root authored Oct 13, 2021
1 parent 5e42612 commit ffd8d17
Show file tree
Hide file tree
Showing 8 changed files with 466 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ test('Cloudfront logging bucket with destroy removal policy and auto delete obje
});

// --------------------------------------------------------------
// Cloudfront logging bucket error providing existing log bucket and logBuckerProps
// Cloudfront logging bucket error providing existing log bucket and logBucketProps
// --------------------------------------------------------------
test('Cloudfront logging bucket error when providing existing log bucket and logBuckerProps', () => {
test('Cloudfront logging bucket error when providing existing log bucket and logBucketProps', () => {
const stack = new cdk.Stack();
const logBucket = new s3.Bucket(stack, 'cloudfront-log-bucket', {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ test('Cloudfront logging bucket with destroy removal policy and auto delete obje
});

// --------------------------------------------------------------
// Cloudfront logging bucket error providing existing log bucket and logBuckerProps
// Cloudfront logging bucket error providing existing log bucket and logBucketProps
// --------------------------------------------------------------
test('Cloudfront logging bucket error when providing existing log bucket and logBuckerProps', () => {
test('Cloudfront logging bucket error when providing existing log bucket and logBucketProps', () => {
const stack = new cdk.Stack();

const inProps: lambda.FunctionProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ _Parameters_
|mediaStoreContainerProps?|[`mediastore.CfnContainerProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-mediastore.CfnContainerProps.html)|Optional user provided props to override the default props for the MediaStore Container.|
|cloudFrontDistributionProps?|[`cloudfront.DistributionProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.DistributionProps.html)\|`any`|Optional user provided props to override the default props for the CloudFront Distribution.|
|insertHttpSecurityHeaders?|`boolean`|Optional user provided props to turn on/off the automatic injection of best practice HTTP security headers in all responses from CloudFront|
|cloudFrontLoggingBucketProps?|[`s3.BucketProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.BucketProps.html)|Optional user provided props to override the default props for the CloudFront Logging Bucket.|

## Pattern Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as cloudfront from '@aws-cdk/aws-cloudfront';
import * as mediastore from '@aws-cdk/aws-mediastore';
import * as s3 from '@aws-cdk/aws-s3';
import * as defaults from '@aws-solutions-constructs/core';
import { Construct, Aws} from '@aws-cdk/core';
import { Construct, Aws } from '@aws-cdk/core';

/**
* @summary The properties for the CloudFrontToMediaStore Construct
Expand Down Expand Up @@ -46,6 +46,12 @@ export interface CloudFrontToMediaStoreProps {
* @default - true
*/
readonly insertHttpSecurityHeaders?: boolean;
/**
* Optional user provided props to override the default props for the CloudFront Logging Bucket.
*
* @default - Default props are used
*/
readonly cloudFrontLoggingBucketProps?: s3.BucketProps
}

export class CloudFrontToMediaStore extends Construct {
Expand All @@ -65,7 +71,7 @@ export class CloudFrontToMediaStore extends Construct {
* @access public
*/
constructor(scope: Construct, id: string, props: CloudFrontToMediaStoreProps) {
super (scope, id);
super(scope, id);
defaults.CheckProps(props);

let cloudFrontDistributionProps = props.cloudFrontDistributionProps;
Expand Down Expand Up @@ -122,6 +128,11 @@ export class CloudFrontToMediaStore extends Construct {
}

[this.cloudFrontWebDistribution, this.cloudFrontLoggingBucket, this.cloudFrontOriginRequestPolicy, this.cloudFrontFunction]
= defaults.CloudFrontDistributionForMediaStore(this, this.mediaStoreContainer, cloudFrontDistributionProps, props.insertHttpSecurityHeaders);
= defaults.CloudFrontDistributionForMediaStore(
this, this.mediaStoreContainer,
cloudFrontDistributionProps,
props.insertHttpSecurityHeaders,
props.cloudFrontLoggingBucketProps
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

// Imports
import '@aws-cdk/assert/jest';
import { Stack } from '@aws-cdk/core';
import { Stack, RemovalPolicy } from '@aws-cdk/core';
import * as mediastore from '@aws-cdk/aws-mediastore';
import * as cloudfront from '@aws-cdk/aws-cloudfront';
import * as s3 from '@aws-cdk/aws-s3';
import { CloudFrontToMediaStore } from '../lib';

// --------------------------------------------------------------
Expand Down Expand Up @@ -581,3 +582,54 @@ test('Test the deployment with the user provided CloudFront properties', () => {
}
});
});

// --------------------------------------------------------------
// Cloudfront logging bucket with destroy removal policy and auto delete objects
// --------------------------------------------------------------
test('Cloudfront logging bucket with destroy removal policy and auto delete objects', () => {
const stack = new Stack();

new CloudFrontToMediaStore(stack, 'cloudfront-mediatstore', {
cloudFrontLoggingBucketProps: {
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true
}
});

expect(stack).toHaveResource("AWS::S3::Bucket", {
AccessControl: "LogDeliveryWrite"
});

expect(stack).toHaveResource("Custom::S3AutoDeleteObjects", {
ServiceToken: {
"Fn::GetAtt": [
"CustomS3AutoDeleteObjectsCustomResourceProviderHandler9D90184F",
"Arn"
]
},
BucketName: {
Ref: "cloudfrontmediatstoreCloudfrontLoggingBucket2565C68A"
}
});
});

// --------------------------------------------------------------
// Cloudfront logging bucket error providing existing log bucket and logBucketProps
// --------------------------------------------------------------
test('Cloudfront logging bucket error when providing existing log bucket and logBucketProps', () => {
const stack = new Stack();
const logBucket = new s3.Bucket(stack, 'cloudfront-log-bucket', {});

const app = () => { new CloudFrontToMediaStore(stack, 'cloudfront-s3', {
cloudFrontDistributionProps: {
logBucket
},
cloudFrontLoggingBucketProps: {
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true
}
});
};

expect(app).toThrowError();
});
Loading

0 comments on commit ffd8d17

Please sign in to comment.