createFirewallRule method

Future<CreateFirewallRuleOutput> createFirewallRule({
  1. required FirewallRuleAction action,
  2. required String dnsViewId,
  3. required String name,
  4. BlockOverrideDnsQueryType? blockOverrideDnsType,
  5. String? blockOverrideDomain,
  6. int? blockOverrideTtl,
  7. FirewallBlockResponse? blockResponse,
  8. String? clientToken,
  9. ConfidenceThreshold? confidenceThreshold,
  10. String? description,
  11. DnsAdvancedProtection? dnsAdvancedProtection,
  12. String? firewallDomainListId,
  13. int? priority,
  14. String? qType,
})

Creates a DNS firewall rule. Firewall rules define actions (ALLOW, BLOCK, or ALERT) to take on DNS queries that match specified domain lists, managed domain lists, or advanced threat protections.

May throw AccessDeniedException. May throw ConflictException. May throw InternalServerException. May throw ResourceNotFoundException. May throw ServiceQuotaExceededException. May throw ThrottlingException. May throw ValidationException.

Parameter action : The action that DNS Firewall should take on a DNS query when it matches one of the domains in the rule's domain list:

  • ALLOW - Permit the request to go through.
  • ALERT - Permit the request and send metrics and logs to CloudWatch.
  • BLOCK - Disallow the request. This option requires additional details in the rule's BlockResponse.

Parameter dnsViewId : The ID of the DNS view to associate with this firewall rule.

Parameter name : A descriptive name for the firewall rule.

Parameter blockOverrideDnsType : The DNS record's type. This determines the format of the record value that you provided in BlockOverrideDomain. Used for the rule action BLOCK with a BlockResponse setting of OVERRIDE.

This setting is required if the BlockResponse setting is OVERRIDE.

Parameter blockOverrideDomain : The custom DNS record to send back in response to the query. Used for the rule action BLOCK with a BlockResponse setting of OVERRIDE.

This setting is required if the BlockResponse setting is OVERRIDE.

Parameter blockOverrideTtl : The recommended amount of time, in seconds, for the DNS resolver or web browser to cache the provided override record. Used for the rule action BLOCK with a BlockResponse setting of OVERRIDE.

This setting is required if the BlockResponse setting is OVERRIDE.

Parameter blockResponse : The response to return when the action is BLOCK. Valid values are NXDOMAIN (domain does not exist), NODATA (domain exists but no records), or OVERRIDE (return custom response).

Parameter clientToken : A unique, case-sensitive identifier to ensure idempotency. This means that making the same request multiple times with the same clientToken has the same result every time.

Parameter confidenceThreshold : The confidence threshold for advanced threat detection. Valid values are HIGH, MEDIUM, or LOW, indicating the accuracy level required for threat detection.

Parameter description : An optional description for the firewall rule.

Parameter dnsAdvancedProtection : Whether to enable advanced DNS threat protection for this rule. Advanced protection can detect and block DNS tunneling and Domain Generation Algorithm (DGA) threats.

Parameter firewallDomainListId : The ID of the firewall domain list to use in this rule.

Parameter priority : The priority of this rule. Rules are evaluated in priority order, with lower numbers having higher priority. When a DNS query matches multiple rules, the rule with the highest priority (lowest number) is applied.

Parameter qType : The DNS query type to match for this rule. Examples include A (IPv4 address), AAAA (IPv6 address), MX (mail exchange), or TXT (text record).

Implementation

Future<CreateFirewallRuleOutput> createFirewallRule({
  required FirewallRuleAction action,
  required String dnsViewId,
  required String name,
  BlockOverrideDnsQueryType? blockOverrideDnsType,
  String? blockOverrideDomain,
  int? blockOverrideTtl,
  FirewallBlockResponse? blockResponse,
  String? clientToken,
  ConfidenceThreshold? confidenceThreshold,
  String? description,
  DnsAdvancedProtection? dnsAdvancedProtection,
  String? firewallDomainListId,
  int? priority,
  String? qType,
}) async {
  _s.validateNumRange(
    'blockOverrideTtl',
    blockOverrideTtl,
    0,
    604800,
  );
  _s.validateNumRange(
    'priority',
    priority,
    1,
    10000,
  );
  final $payload = <String, dynamic>{
    'action': action.value,
    'dnsViewId': dnsViewId,
    'name': name,
    if (blockOverrideDnsType != null)
      'blockOverrideDnsType': blockOverrideDnsType.value,
    if (blockOverrideDomain != null)
      'blockOverrideDomain': blockOverrideDomain,
    if (blockOverrideTtl != null) 'blockOverrideTtl': blockOverrideTtl,
    if (blockResponse != null) 'blockResponse': blockResponse.value,
    'clientToken': clientToken ?? _s.generateIdempotencyToken(),
    if (confidenceThreshold != null)
      'confidenceThreshold': confidenceThreshold.value,
    if (description != null) 'description': description,
    if (dnsAdvancedProtection != null)
      'dnsAdvancedProtection': dnsAdvancedProtection.value,
    if (firewallDomainListId != null)
      'firewallDomainListId': firewallDomainListId,
    if (priority != null) 'priority': priority,
    if (qType != null) 'qType': qType,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/firewall-rules',
    exceptionFnMap: _exceptionFns,
  );
  return CreateFirewallRuleOutput.fromJson(response);
}