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(route53): RecordSet routing policy properties, HeathCheck #4413

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
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
11 changes: 8 additions & 3 deletions packages/@aws-cdk/aws-ec2/lib/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CidrIPv4 implements IPeer {

constructor(private readonly cidrIp: string) {
if (!Token.isUnresolved(cidrIp)) {
const cidrMatch = cidrIp.match(/^(\d{1,3}\.){3}\d{1,3}(\/\d+)?$/);
const cidrMatch = cidrIp.match(CIDR_VALIDATION_REGEXES.ipv4);

if (!cidrMatch) {
throw new Error(`Invalid IPv4 CIDR: "${cidrIp}"`);
Expand Down Expand Up @@ -126,7 +126,7 @@ class CidrIPv6 implements IPeer {

constructor(private readonly cidrIpv6: string) {
if (!Token.isUnresolved(cidrIpv6)) {
const cidrMatch = cidrIpv6.match(/^([\da-f]{0,4}:){2,7}([\da-f]{0,4})?(\/\d+)?$/);
const cidrMatch = cidrIpv6.match(CIDR_VALIDATION_REGEXES.ipv6);

if (!cidrMatch) {
throw new Error(`Invalid IPv6 CIDR: "${cidrIpv6}"`);
Expand Down Expand Up @@ -188,4 +188,9 @@ class PrefixList implements IPeer {
public toEgressRuleConfig(): any {
return { destinationPrefixListId: this.prefixListId };
}
}
}

export const CIDR_VALIDATION_REGEXES = {
ipv4: /^(\d{1,3}\.){3}\d{1,3}(\/\d+)?$/,
ipv6: /^([\da-f]{0,4}:){2,7}([\da-f]{0,4})?(\/\d+)?$/,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import cloudwatch = require('@aws-cdk/aws-cloudwatch');
import {Aws, Construct} from '@aws-cdk/core';
import {AdvancedHealthCheckOptions, HealthCheck} from "./health-check";

/**
* Alarm health check properties
* @experimental
*/
export interface AlarmHealthCheckProps extends AdvancedHealthCheckOptions {
/**
* The CloudWatch alarm to be monitored
*
* Supported alarms:
* * Standard-resolution metrics (High-resolution metrics aren't supported)
* * Statistics: Average, Minimum, Maximum, Sum, and SampleCount
*
* Route 53 does not support alarms that use metric math to query multiple CloudWatch metrics.
*/
readonly alarm: cloudwatch.Alarm;
/**
* Status of the health check when CloudWatch has insufficient data to determine
* the state of the alarm that you chose for CloudWatch alarm
*
* @default InsufficientDataHealthStatus.LAST_KNOWN_STATUS
*/
readonly insufficientDataHealthStatus?: InsufficientDataHealthStatusType;
}

/**
* Alarm health check construct
*
* @resource AWS::Route53::HealthCheck
* @see https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/health-checks-creating-values.html#health-checks-creating-values-cloudwatch
* @experimental
*/
export class AlarmHealthCheck extends HealthCheck {
public constructor(scope: Construct, id: string, props: AlarmHealthCheckProps) {
const {alarm, ...baseProps} = props;
super(scope, id, {
type: AlarmHealthCheckType.CALCULATED,
...baseProps,
alarmIdentifier: {
name: props.alarm.alarmName,
// FIXME not always true?
region: Aws.REGION,
},
});
}
}

/**
* The type of Route 53 health check
*/
enum AlarmHealthCheckType {
/**
* For health checks that monitor the status of other health checks,
* Route 53 adds up the number of health checks that Route 53 health checkers consider to be healthy and
* compares that number with the value of HealthThreshold.
*/
CALCULATED = 'CALCULATED',
}

/**
* Type of InsufficientDataHealthStatus
*/
export enum InsufficientDataHealthStatusType {
/**
* Route 53 considers the health check to be healthy.
*/
HEALTHY = 'Healthy',
/**
* Route 53 considers the health check to be unhealthy.
*/
UNHEALTHY = 'Unhealthy',
/**
* Route 53 uses the status of the health check from the last time that CloudWatch had sufficient data to determine the alarm state.
* For new health checks that have no last known status, the default status for the health check is healthy.
*/
LAST_KNOWN_STATUS = 'LastKnownStatus',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {Construct} from '@aws-cdk/core';
import {AdvancedHealthCheckOptions, HealthCheck, IHealthCheck} from "./health-check";

/**
* Calculated health check properties
* @experimental
*/
export interface CalculatedHealthCheckProps extends AdvancedHealthCheckOptions {
/**
* List of health checks to be monitored
*/
readonly childHealthChecks: IHealthCheck[];
/**
* Minimum count of healthy {@link CalculatedHealthCheckProps.childHealthChecks}
* required for the parent health check to be considered healthy
*
* * If you specify a number greater than the number of child health checks,
* Route 53 always considers this health check to be unhealthy.
* * If you specify 0, Route 53 always considers this health check to be healthy.
*/
readonly healthThreshold: number;
}

/**
* Calculated health check construct
*
* @resource AWS::Route53::HealthCheck
* @see https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/health-checks-creating-values.html#health-checks-creating-values-calculated
* @experimental
*/
export class CalculatedHealthCheck extends HealthCheck {
public constructor(
scope: Construct,
id: string,
props: CalculatedHealthCheckProps,
) {
const {childHealthChecks, healthThreshold, inverted} = props;

super(scope, id, {
type: CalculatedHealthCheckType.CALCULATED,
childHealthChecks: childHealthChecks.map(({healthCheckId}) => healthCheckId),
healthThreshold,
inverted,
});
}
}

/**
* The type of Route 53 health check
*/
enum CalculatedHealthCheckType {
/**
* For health checks that monitor the status of other health checks,
* Route 53 adds up the number of health checks that Route 53 health checkers consider to be healthy and
* compares that number with the value of HealthThreshold.
*/
CALCULATED = 'CALCULATED',
}
Loading