Skip to content

Commit

Permalink
change for review
Browse files Browse the repository at this point in the history
  • Loading branch information
go-to-k committed Sep 7, 2023
1 parent 2a11dc4 commit 9e84888
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 292 deletions.
62 changes: 34 additions & 28 deletions packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,34 +1147,7 @@ export class Service extends cdk.Resource implements iam.IGrantable {
throw new Error('configurationValues cannot be provided if the ConfigurationSource is Repository');
}

if (this.props.healthCheckConfiguration?.path !== undefined) {
if (this.props.healthCheckConfiguration?.protocol !== HealthCheckProtocolType.HTTP) {
throw new Error('path is only applicable when you set Protocol to HTTP');
}
if (this.props.healthCheckConfiguration?.path.length === 0) {
throw new Error('path length must be greater than 0');
}
}
if (this.props.healthCheckConfiguration?.healthyThreshold !== undefined) {
if (this.props.healthCheckConfiguration?.healthyThreshold < 1 || this.props.healthCheckConfiguration?.healthyThreshold > 20) {
throw new Error('healthyThreshold must be greater than or equal to 1 and less than or equal to 20');
}
}
if (this.props.healthCheckConfiguration?.unhealthyThreshold !== undefined) {
if (this.props.healthCheckConfiguration?.unhealthyThreshold < 1 || this.props.healthCheckConfiguration?.unhealthyThreshold > 20) {
throw new Error('unhealthyThreshold must be greater than or equal to 1 and less than or equal to 20');
}
}
if (this.props.healthCheckConfiguration?.interval !== undefined) {
if (this.props.healthCheckConfiguration?.interval.toSeconds() < 1 || this.props.healthCheckConfiguration?.interval.toSeconds() > 20) {
throw new Error('interval must be greater than or equal to 1 and less than or equal to 20');
}
}
if (this.props.healthCheckConfiguration?.timeout !== undefined) {
if (this.props.healthCheckConfiguration?.timeout.toSeconds() < 1 || this.props.healthCheckConfiguration?.timeout.toSeconds() > 20) {
throw new Error('timeout must be greater than or equal to 1 and less than or equal to 20');
}
}
this.validateHealthCheckConfiguration(this.props.healthCheckConfiguration);

const resource = new CfnService(this, 'Resource', {
serviceName: this.props.serviceName,
Expand Down Expand Up @@ -1375,4 +1348,37 @@ export class Service extends cdk.Resource implements iam.IGrantable {
unhealthyThreshold: props.unhealthyThreshold,
};
}

private validateHealthCheckConfiguration(healthCheckConfiguration?: HealthCheckConfiguration) {
if (!healthCheckConfiguration) return;

if (healthCheckConfiguration.path !== undefined) {
if (healthCheckConfiguration.protocol !== HealthCheckProtocolType.HTTP) {
throw new Error('path is only applicable when you set Protocol to HTTP');
}
if (healthCheckConfiguration.path.length === 0) {
throw new Error('path length must be greater than 0');
}
}
if (healthCheckConfiguration.healthyThreshold !== undefined) {
if (healthCheckConfiguration.healthyThreshold < 1 || healthCheckConfiguration.healthyThreshold > 20) {
throw new Error(`healthyThreshold must be between 1 and 20, got ${healthCheckConfiguration.healthyThreshold}`);
}
}
if (healthCheckConfiguration.unhealthyThreshold !== undefined) {
if (healthCheckConfiguration.unhealthyThreshold < 1 || healthCheckConfiguration.unhealthyThreshold > 20) {
throw new Error(`unhealthyThreshold must be between 1 and 20, got ${healthCheckConfiguration.unhealthyThreshold}`);
}
}
if (healthCheckConfiguration.interval !== undefined) {
if (healthCheckConfiguration.interval.toSeconds() < 1 || healthCheckConfiguration.interval.toSeconds() > 20) {
throw new Error(`interval must be between 1 and 20 seconds, got ${healthCheckConfiguration.interval}`);

This comment has been minimized.

Copy link
@lpizzinidev

lpizzinidev Sep 7, 2023

Contributor

interval and timeout should be converted with toSeconds()

}
}
if (healthCheckConfiguration.timeout !== undefined) {
if (healthCheckConfiguration.timeout.toSeconds() < 1 || healthCheckConfiguration.timeout.toSeconds() > 20) {
throw new Error(`timeout must be between 1 and 20 seconds, got ${healthCheckConfiguration.timeout}`);
}
}
}
}
Loading

0 comments on commit 9e84888

Please sign in to comment.