createListener method

Future<CreateListenerResponse> createListener({
  1. required String acceleratorArn,
  2. required List<PortRange> portRanges,
  3. required Protocol protocol,
  4. ClientAffinity? clientAffinity,
  5. String? idempotencyToken,
})

Create a listener to process inbound connections from clients to an accelerator. Connections arrive to assigned static IP addresses on a port, port range, or list of port ranges that you specify.

May throw InvalidArgumentException. May throw AcceleratorNotFoundException. May throw InvalidPortRangeException. May throw InternalServiceErrorException. May throw LimitExceededException.

Parameter acceleratorArn : The Amazon Resource Name (ARN) of your accelerator.

Parameter portRanges : The list of port ranges to support for connections from clients to your accelerator.

Parameter protocol : The protocol for connections from clients to your accelerator.

Parameter clientAffinity : Client affinity lets you direct all requests from a user to the same endpoint, if you have stateful applications, regardless of the port and protocol of the client request. Client affinity gives you control over whether to always route each client to the same specific endpoint.

AWS Global Accelerator uses a consistent-flow hashing algorithm to choose the optimal endpoint for a connection. If client affinity is NONE, Global Accelerator uses the "five-tuple" (5-tuple) properties—source IP address, source port, destination IP address, destination port, and protocol—to select the hash value, and then chooses the best endpoint. However, with this setting, if someone uses different ports to connect to Global Accelerator, their connections might not be always routed to the same endpoint because the hash value changes.

If you want a given client to always be routed to the same endpoint, set client affinity to SOURCE_IP instead. When you use the SOURCE_IP setting, Global Accelerator uses the "two-tuple" (2-tuple) properties— source (client) IP address and destination IP address—to select the hash value.

The default value is NONE.

Parameter idempotencyToken : A unique, case-sensitive identifier that you provide to ensure the idempotency—that is, the uniqueness—of the request.

Implementation

Future<CreateListenerResponse> createListener({
  required String acceleratorArn,
  required List<PortRange> portRanges,
  required Protocol protocol,
  ClientAffinity? clientAffinity,
  String? idempotencyToken,
}) async {
  ArgumentError.checkNotNull(acceleratorArn, 'acceleratorArn');
  _s.validateStringLength(
    'acceleratorArn',
    acceleratorArn,
    0,
    255,
    isRequired: true,
  );
  ArgumentError.checkNotNull(portRanges, 'portRanges');
  ArgumentError.checkNotNull(protocol, 'protocol');
  _s.validateStringLength(
    'idempotencyToken',
    idempotencyToken,
    0,
    255,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'GlobalAccelerator_V20180706.CreateListener'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'AcceleratorArn': acceleratorArn,
      'PortRanges': portRanges,
      'Protocol': protocol.toValue(),
      if (clientAffinity != null) 'ClientAffinity': clientAffinity.toValue(),
      'IdempotencyToken': idempotencyToken ?? _s.generateIdempotencyToken(),
    },
  );

  return CreateListenerResponse.fromJson(jsonResponse.body);
}