createTrafficPolicyInstance method

Future<CreateTrafficPolicyInstanceResponse> createTrafficPolicyInstance({
  1. required String hostedZoneId,
  2. required String name,
  3. required int ttl,
  4. required String trafficPolicyId,
  5. required int trafficPolicyVersion,
})

Creates resource record sets in a specified hosted zone based on the settings in a specified traffic policy version. In addition, CreateTrafficPolicyInstance associates the resource record sets with a specified domain name (such as example.com) or subdomain name (such as www.example.com). Amazon Route 53 responds to DNS queries for the domain or subdomain name by using the resource record sets that CreateTrafficPolicyInstance created.

May throw NoSuchHostedZone. May throw InvalidInput. May throw TooManyTrafficPolicyInstances. May throw NoSuchTrafficPolicy. May throw TrafficPolicyInstanceAlreadyExists.

Parameter hostedZoneId : The ID of the hosted zone that you want Amazon Route 53 to create resource record sets in by using the configuration in a traffic policy.

Parameter name : The domain name (such as example.com) or subdomain name (such as www.example.com) for which Amazon Route 53 responds to DNS queries by using the resource record sets that Route 53 creates for this traffic policy instance.

Parameter ttl : (Optional) The TTL that you want Amazon Route 53 to assign to all of the resource record sets that it creates in the specified hosted zone.

Parameter trafficPolicyId : The ID of the traffic policy that you want to use to create resource record sets in the specified hosted zone.

Parameter trafficPolicyVersion : The version of the traffic policy that you want to use to create resource record sets in the specified hosted zone.

Implementation

Future<CreateTrafficPolicyInstanceResponse> createTrafficPolicyInstance({
  required String hostedZoneId,
  required String name,
  required int ttl,
  required String trafficPolicyId,
  required int trafficPolicyVersion,
}) async {
  ArgumentError.checkNotNull(hostedZoneId, 'hostedZoneId');
  _s.validateStringLength(
    'hostedZoneId',
    hostedZoneId,
    0,
    32,
    isRequired: true,
  );
  ArgumentError.checkNotNull(name, 'name');
  _s.validateStringLength(
    'name',
    name,
    0,
    1024,
    isRequired: true,
  );
  ArgumentError.checkNotNull(ttl, 'ttl');
  _s.validateNumRange(
    'ttl',
    ttl,
    0,
    2147483647,
    isRequired: true,
  );
  ArgumentError.checkNotNull(trafficPolicyId, 'trafficPolicyId');
  _s.validateStringLength(
    'trafficPolicyId',
    trafficPolicyId,
    1,
    36,
    isRequired: true,
  );
  ArgumentError.checkNotNull(trafficPolicyVersion, 'trafficPolicyVersion');
  _s.validateNumRange(
    'trafficPolicyVersion',
    trafficPolicyVersion,
    1,
    1000,
    isRequired: true,
  );
  final $result = await _protocol.sendRaw(
    method: 'POST',
    requestUri: '/2013-04-01/trafficpolicyinstance',
    payload: CreateTrafficPolicyInstanceRequest(
            hostedZoneId: hostedZoneId,
            name: name,
            ttl: ttl,
            trafficPolicyId: trafficPolicyId,
            trafficPolicyVersion: trafficPolicyVersion)
        .toXml(
      'CreateTrafficPolicyInstanceRequest',
      attributes: [
        _s.XmlAttribute(_s.XmlName('xmlns'),
            'https://route53.amazonaws.com/doc/2013-04-01/'),
      ],
    ),
    exceptionFnMap: _exceptionFns,
  );
  final $elem = await _s.xmlFromResponse($result);
  return CreateTrafficPolicyInstanceResponse(
    trafficPolicyInstance: TrafficPolicyInstance.fromXml(
        _s.extractXmlChild($elem, 'TrafficPolicyInstance')!),
    location: _s.extractHeaderStringValue($result.headers, 'Location')!,
  );
}