-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into njlynch/pipelines-r…
…ole-optimization
- Loading branch information
Showing
31 changed files
with
741 additions
and
439 deletions.
There are no files selected for viewing
73 changes: 67 additions & 6 deletions
73
packages/@aws-cdk/aws-cloudfront-origins/lib/http-origin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,82 @@ | ||
import * as cloudfront from '@aws-cdk/aws-cloudfront'; | ||
import * as cdk from '@aws-cdk/core'; | ||
|
||
/** | ||
* Properties for an Origin backed by any HTTP server. | ||
* Properties for an Origin backed by an S3 website-configured bucket, load balancer, or custom HTTP server. | ||
* | ||
* @experimental | ||
*/ | ||
export interface HttpOriginProps extends cloudfront.HttpOriginProps { } | ||
export interface HttpOriginProps extends cloudfront.OriginProps { | ||
/** | ||
* Specifies the protocol (HTTP or HTTPS) that CloudFront uses to connect to the origin. | ||
* | ||
* @default OriginProtocolPolicy.HTTPS_ONLY | ||
*/ | ||
readonly protocolPolicy?: cloudfront.OriginProtocolPolicy; | ||
|
||
/** | ||
* The HTTP port that CloudFront uses to connect to the origin. | ||
* | ||
* @default 80 | ||
*/ | ||
readonly httpPort?: number; | ||
|
||
/** | ||
* The HTTPS port that CloudFront uses to connect to the origin. | ||
* | ||
* @default 443 | ||
*/ | ||
readonly httpsPort?: number; | ||
|
||
/** | ||
* Specifies how long, in seconds, CloudFront waits for a response from the origin, also known as the origin response timeout. | ||
* The valid range is from 1 to 60 seconds, inclusive. | ||
* | ||
* @default Duration.seconds(30) | ||
*/ | ||
readonly readTimeout?: cdk.Duration; | ||
|
||
/** | ||
* Specifies how long, in seconds, CloudFront persists its connection to the origin. | ||
* The valid range is from 1 to 60 seconds, inclusive. | ||
* | ||
* @default Duration.seconds(5) | ||
*/ | ||
readonly keepaliveTimeout?: cdk.Duration; | ||
} | ||
|
||
/** | ||
* An Origin for an HTTP server. | ||
* An Origin for an HTTP server or S3 bucket configured for website hosting. | ||
* | ||
* @experimental | ||
*/ | ||
export class HttpOrigin extends cloudfront.HttpOrigin { | ||
export class HttpOrigin extends cloudfront.OriginBase { | ||
|
||
constructor(domainName: string, private readonly props: HttpOriginProps = {}) { | ||
super(domainName, props); | ||
|
||
constructor(domainName: string, props: HttpOriginProps = {}) { | ||
super(domainName, { ...props }); | ||
validateSecondsInRangeOrUndefined('readTimeout', 1, 60, props.readTimeout); | ||
validateSecondsInRangeOrUndefined('keepaliveTimeout', 1, 60, props.keepaliveTimeout); | ||
} | ||
|
||
protected renderCustomOriginConfig(): cloudfront.CfnDistribution.CustomOriginConfigProperty | undefined { | ||
return { | ||
originProtocolPolicy: this.props.protocolPolicy ?? cloudfront.OriginProtocolPolicy.HTTPS_ONLY, | ||
httpPort: this.props.httpPort, | ||
httpsPort: this.props.httpsPort, | ||
originReadTimeout: this.props.readTimeout?.toSeconds(), | ||
originKeepaliveTimeout: this.props.keepaliveTimeout?.toSeconds(), | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Throws an error if a duration is defined and not an integer number of seconds within a range. | ||
*/ | ||
function validateSecondsInRangeOrUndefined(name: string, min: number, max: number, duration?: cdk.Duration) { | ||
if (duration === undefined) { return; } | ||
const value = duration.toSeconds(); | ||
if (!Number.isInteger(value) || value < min || value > max) { | ||
throw new Error(`${name}: Must be an int between ${min} and ${max} seconds (inclusive); received ${value}.`); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
packages/@aws-cdk/aws-cloudfront-origins/lib/load-balancer-origin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.