constructor()

in packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts [182:240]


  constructor(scope: Construct, id: string, props: ApplicationLoadBalancerProps) {
    super(scope, id, props, {
      type: 'application',
      securityGroups: Lazy.list({ produce: () => this.connections.securityGroups.map(sg => sg.securityGroupId) }),
      ipAddressType: props.ipAddressType,
    });
    // Enhanced CDK Analytics Telemetry
    addConstructMetadata(this, props);

    const minimumCapacityUnit = props.minimumCapacityUnit;
    if (
      minimumCapacityUnit &&
      !Token.isUnresolved(minimumCapacityUnit) &&
      (!Number.isInteger(minimumCapacityUnit) || minimumCapacityUnit < 100 || minimumCapacityUnit > 1500)
    ) {
      throw new ValidationError(`'minimumCapacityUnit' must be a positive integer between 100 and 1500 for Application Load Balancer, got: ${minimumCapacityUnit}.`, this);
    }

    this.ipAddressType = props.ipAddressType ?? IpAddressType.IPV4;

    if (props.ipAddressType === IpAddressType.DUAL_STACK_WITHOUT_PUBLIC_IPV4 && !props.internetFacing) {
      throw new ValidationError('dual-stack without public IPv4 address can only be used with internet-facing scheme.', this);
    }

    const securityGroups = [props.securityGroup || new ec2.SecurityGroup(this, 'SecurityGroup', {
      vpc: props.vpc,
      description: `Automatically created Security Group for ELB ${Names.uniqueId(this)}`,
      allowAllOutbound: false,
    })];
    this.connections = new ec2.Connections({ securityGroups });
    this.listeners = [];
    this.metrics = new ApplicationLoadBalancerMetrics(this, this.loadBalancerFullName);

    if (props.http2Enabled !== undefined) { this.setAttribute('routing.http2.enabled', props.http2Enabled ? 'true' : 'false'); }
    if (props.idleTimeout !== undefined) { this.setAttribute('idle_timeout.timeout_seconds', props.idleTimeout.toSeconds().toString()); }
    if (props.dropInvalidHeaderFields) { this.setAttribute('routing.http.drop_invalid_header_fields.enabled', 'true'); }
    if (props.desyncMitigationMode !== undefined) { this.setAttribute('routing.http.desync_mitigation_mode', props.desyncMitigationMode); }
    if (props.preserveHostHeader) { this.setAttribute('routing.http.preserve_host_header.enabled', 'true'); }
    if (props.xAmznTlsVersionAndCipherSuiteHeaders) { this.setAttribute('routing.http.x_amzn_tls_version_and_cipher_suite.enabled', 'true'); }
    if (props.preserveXffClientPort) { this.setAttribute('routing.http.xff_client_port.enabled', 'true'); }
    if (props.xffHeaderProcessingMode !== undefined) { this.setAttribute('routing.http.xff_header_processing.mode', props.xffHeaderProcessingMode); }
    if (props.wafFailOpen) { this.setAttribute('waf.fail_open.enabled', 'true'); }
    if (props.clientKeepAlive !== undefined) {
      const clientKeepAliveInMillis = props.clientKeepAlive.toMilliseconds();
      if (clientKeepAliveInMillis < 1000) {
        throw new ValidationError(`\'clientKeepAlive\' must be between 60 and 604800 seconds. Got: ${clientKeepAliveInMillis} milliseconds`, this);
      }

      const clientKeepAliveInSeconds = props.clientKeepAlive.toSeconds();
      if (clientKeepAliveInSeconds < 60 || clientKeepAliveInSeconds > 604800) {
        throw new ValidationError(`\'clientKeepAlive\' must be between 60 and 604800 seconds. Got: ${clientKeepAliveInSeconds} seconds`, this);
      }
      this.setAttribute('client_keep_alive.seconds', clientKeepAliveInSeconds.toString());
    }

    if (props.crossZoneEnabled === false) {
      throw new ValidationError('crossZoneEnabled cannot be false with Application Load Balancers.', this);
    }
  }