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(aws-cloudfront): support for associating a AWS WAF WebACL with a distribution #969

Merged
merged 1 commit into from
Oct 19, 2018
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
19 changes: 13 additions & 6 deletions packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export interface SourceConfiguration {
*
* @default no additional headers are passed
*/
readonly originHeaders?: {[key: string]: string};
readonly originHeaders?: { [key: string]: string };
}

/**
Expand Down Expand Up @@ -431,6 +431,12 @@ export interface CloudFrontWebDistributionProps {
* How CloudFront should handle requests that are no successful (eg PageNotFound)
*/
errorConfigurations?: cloudformation.DistributionResource.CustomErrorResponseProperty[];

/**
* Optional AWS WAF WebACL to associate with this CloudFront distribution
*/
webACLId?: string;

}

/**
Expand Down Expand Up @@ -528,6 +534,7 @@ export class CloudFrontWebDistribution extends cdk.Construct {
ipv6Enabled: props.enableIpV6 || true,
// tslint:disable-next-line:max-line-length
customErrorResponses: props.errorConfigurations, // TODO: validation : https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-customerrorresponse.html#cfn-cloudfront-distribution-customerrorresponse-errorcachingminttl
webAclId: props.webACLId,
};

const behaviors: BehaviorWithOrigin[] = [];
Expand Down Expand Up @@ -585,7 +592,7 @@ export class CloudFrontWebDistribution extends cdk.Construct {
};
}
for (const behavior of originConfig.behaviors) {
behaviors.push({...behavior, targetOriginId: originId});
behaviors.push({ ...behavior, targetOriginId: originId });
}
origins.push(originProperty);
originIndex++;
Expand Down Expand Up @@ -647,26 +654,26 @@ export class CloudFrontWebDistribution extends cdk.Construct {
};
}

const distribution = new cloudformation.DistributionResource(this, 'CFDistribution', {distributionConfig});
const distribution = new cloudformation.DistributionResource(this, 'CFDistribution', { distributionConfig });
this.domainName = distribution.distributionDomainName;
this.distributionId = distribution.distributionId;
}

private toBehavior(input: BehaviorWithOrigin, protoPolicy?: ViewerProtocolPolicy) {
let toReturn = {
let toReturn = {
allowedMethods: this.METHOD_LOOKUP_MAP[input.allowedMethods || CloudFrontAllowedMethods.GET_HEAD],
cachedMethods: this.METHOD_LOOKUP_MAP[input.cachedMethods || CloudFrontAllowedCachedMethods.GET_HEAD],
compress: input.compress,
defaultTtl: input.defaultTtlSeconds,
forwardedValues: input.forwardedValues || { queryString: false, cookies: {forward: "none"} },
forwardedValues: input.forwardedValues || { queryString: false, cookies: { forward: "none" } },
maxTtl: input.maxTtlSeconds,
minTtl: input.minTtlSeconds,
trustedSigners: input.trustedSigners,
targetOriginId: input.targetOriginId,
viewerProtocolPolicy: protoPolicy || ViewerProtocolPolicy.RedirectToHTTPS,
};
if (!input.isDefaultBehavior) {
toReturn = Object.assign(toReturn, {pathPattern: input.pathPattern});
toReturn = Object.assign(toReturn, { pathPattern: input.pathPattern });
}
return toReturn;
}
Expand Down