Skip to content

create_firewall_rule

create_firewall_rule(
    action: FirewallRuleAction,
    name: ResourceName,
    dns_view_id: ResourceId,
    *,
    config_overrides: Optional[Route53GlobalResolverClientConfig] = None,
    block_override_dns_type: Optional[BlockOverrideDnsQueryType] = None,
    block_override_domain: Optional[Domain] = None,
    block_override_ttl: Optional[BlockOverrideTtl] = None,
    block_response: Optional[FirewallBlockResponse] = None,
    client_token: Optional[ClientToken] = None,
    confidence_threshold: Optional[ConfidenceThreshold] = None,
    description: Optional[ResourceDescription] = None,
    dns_advanced_protection: Optional[DnsAdvancedProtection] = None,
    firewall_domain_list_id: Optional[ResourceId] = None,
    priority: Optional[FirewallRulePriority] = None,
    q_type: Optional[DnsQueryType] = None,
) -> CreateFirewallRuleOutput

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.

Route 53 Global Resolver is a global service that supports resolvers in multiple Amazon Web Services Regions but you must specify the US East (Ohio) Region to create, update, or otherwise work with Route 53 Global Resolver resources. That is, for example, specify --region us-east-2 on Amazon Web Services CLI commands.

Parameters:

  • action (FirewallRuleAction) –

    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.

  • block_override_dns_type (Optional[BlockOverrideDnsQueryType], default: None ) –

    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.

  • block_override_domain (Optional[Domain], default: None ) –

    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.

  • block_override_ttl (Optional[BlockOverrideTtl], default: None ) –

    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.

  • block_response (Optional[FirewallBlockResponse], default: None ) –

    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).

  • client_token (Optional[ClientToken], default: None ) –

    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.

  • confidence_threshold (Optional[ConfidenceThreshold], default: None ) –

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

  • description (Optional[ResourceDescription], default: None ) –

    An optional description for the firewall rule.

  • dns_advanced_protection (Optional[DnsAdvancedProtection], default: None ) –

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

  • firewall_domain_list_id (Optional[ResourceId], default: None ) –

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

  • name (ResourceName) –

    A descriptive name for the firewall rule.

  • priority (Optional[FirewallRulePriority], default: None ) –

    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.

  • dns_view_id (ResourceId) –

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

  • q_type (Optional[DnsQueryType], default: None ) –

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

Raises:

  • AccessDeniedException –

    You don't have permission to perform this operation. Check your IAM permissions and try again.

  • ConflictException –

    The request conflicts with the current state of the resource. This can occur when trying to modify a resource that is not in a valid state for the requested operation.

  • InternalServerException –

    An internal server error occurred. Try again later.

  • ResourceNotFoundException –

    The specified resource was not found. Verify the resource ID and try again.

  • ServiceQuotaExceededException –

    The request would exceed one or more service quotas. Check your current usage and quotas, then try again.

  • ThrottlingException –

    The request was throttled due to too many requests. Wait a moment and try again.

  • ValidationException –

    The input parameters are invalid. Check the parameter values and try again.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_route53globalresolver/_services/route53_global_resolver.py
def create_firewall_rule(
    self,
    action: "capo_route53globalresolver.types.firewall_rule_action.FirewallRuleAction",
    name: "capo_route53globalresolver.types.resource_name.ResourceName",
    dns_view_id: "capo_route53globalresolver.types.resource_id.ResourceId",
    *,
    config_overrides: Optional[Route53GlobalResolverClientConfig] = None,
    block_override_dns_type: Optional[
        "capo_route53globalresolver.types.block_override_dns_query_type.BlockOverrideDnsQueryType"
    ] = None,
    block_override_domain: Optional[
        "capo_route53globalresolver.types.domain.Domain"
    ] = None,
    block_override_ttl: Optional[
        "capo_route53globalresolver.types.block_override_ttl.BlockOverrideTtl"
    ] = None,
    block_response: Optional[
        "capo_route53globalresolver.types.firewall_block_response.FirewallBlockResponse"
    ] = None,
    client_token: Optional[
        "capo_route53globalresolver.types.client_token.ClientToken"
    ] = None,
    confidence_threshold: Optional[
        "capo_route53globalresolver.types.confidence_threshold.ConfidenceThreshold"
    ] = None,
    description: Optional[
        "capo_route53globalresolver.types.resource_description.ResourceDescription"
    ] = None,
    dns_advanced_protection: Optional[
        "capo_route53globalresolver.types.dns_advanced_protection.DnsAdvancedProtection"
    ] = None,
    firewall_domain_list_id: Optional[
        "capo_route53globalresolver.types.resource_id.ResourceId"
    ] = None,
    priority: Optional[
        "capo_route53globalresolver.types.firewall_rule_priority.FirewallRulePriority"
    ] = None,
    q_type: Optional[
        "capo_route53globalresolver.types.dns_query_type.DnsQueryType"
    ] = None,
) -> "capo_route53globalresolver.types.create_firewall_rule_output.CreateFirewallRuleOutput":
    """<p>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.</p> <important> <p>Route 53 Global Resolver is a global service that supports resolvers in multiple Amazon Web Services Regions but you must specify the US East (Ohio) Region to create, update, or otherwise work with Route 53 Global Resolver resources. That is, for example, specify <code>--region us-east-2</code> on Amazon Web Services CLI commands.</p> </important>

    Args:
        action: <p>The action that DNS Firewall should take on a DNS query when it matches one of the domains in the rule's domain list:</p> <ul> <li> <p> <code>ALLOW</code> - Permit the request to go through.</p> </li> <li> <p> <code>ALERT</code> - Permit the request and send metrics and logs to CloudWatch.</p> </li> <li> <p> <code>BLOCK</code> - Disallow the request. This option requires additional details in the rule's <code>BlockResponse</code>.</p> </li> </ul>
        block_override_dns_type: <p>The DNS record's type. This determines the format of the record value that you provided in <code>BlockOverrideDomain</code>. Used for the rule action <code>BLOCK</code> with a <code>BlockResponse</code> setting of <code>OVERRIDE</code>.</p> <p>This setting is required if the <code>BlockResponse</code> setting is <code>OVERRIDE</code>.</p>
        block_override_domain: <p>The custom DNS record to send back in response to the query. Used for the rule action <code>BLOCK</code> with a <code>BlockResponse</code> setting of <code>OVERRIDE</code>.</p> <p>This setting is required if the <code>BlockResponse</code> setting is <code>OVERRIDE</code>.</p>
        block_override_ttl: <p>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 <code>BLOCK</code> with a <code>BlockResponse</code> setting of <code>OVERRIDE</code>.</p> <p>This setting is required if the <code>BlockResponse</code> setting is <code>OVERRIDE</code>.</p>
        block_response: <p>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).</p>
        client_token: <p>A unique, case-sensitive identifier to ensure idempotency. This means that making the same request multiple times with the same <code>clientToken</code> has the same result every time.</p>
        confidence_threshold: <p>The confidence threshold for advanced threat detection. Valid values are HIGH, MEDIUM, or LOW, indicating the accuracy level required for threat detection.</p>
        description: <p>An optional description for the firewall rule.</p>
        dns_advanced_protection: <p>Whether to enable advanced DNS threat protection for this rule. Advanced protection can detect and block DNS tunneling and Domain Generation Algorithm (DGA) threats.</p>
        firewall_domain_list_id: <p>The ID of the firewall domain list to use in this rule.</p>
        name: <p>A descriptive name for the firewall rule.</p>
        priority: <p>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.</p>
        dns_view_id: <p>The ID of the DNS view to associate with this firewall rule.</p>
        q_type: <p>The DNS query type to match for this rule. Examples include A (IPv4 address), AAAA (IPv6 address), MX (mail exchange), or TXT (text record).</p>

    Raises:
        capo_route53globalresolver.errors.access_denied_exception.AccessDeniedException: <p>You don't have permission to perform this operation. Check your IAM permissions and try again.</p>
        capo_route53globalresolver.errors.conflict_exception.ConflictException: <p>The request conflicts with the current state of the resource. This can occur when trying to modify a resource that is not in a valid state for the requested operation.</p>
        capo_route53globalresolver.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Try again later.</p>
        capo_route53globalresolver.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource was not found. Verify the resource ID and try again.</p>
        capo_route53globalresolver.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request would exceed one or more service quotas. Check your current usage and quotas, then try again.</p>
        capo_route53globalresolver.errors.throttling_exception.ThrottlingException: <p>The request was throttled due to too many requests. Wait a moment and try again.</p>
        capo_route53globalresolver.errors.validation_exception.ValidationException: <p>The input parameters are invalid. Check the parameter values and try again.</p>
        capo_route53globalresolver.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_route53globalresolver.types.create_firewall_rule_input.CreateFirewallRuleInput]",
    ) -> OperationResponse[
        "capo_route53globalresolver.types.create_firewall_rule_output.CreateFirewallRuleOutput"
    ]:
        import capo_route53globalresolver._operations.ec2_dns_global_resolver_customer_api.create_firewall_rule

        output, http_response = (
            capo_route53globalresolver._operations.ec2_dns_global_resolver_customer_api.create_firewall_rule.create_firewall_rule(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateFirewallRule")
    )
    input_: capo_route53globalresolver.types.create_firewall_rule_input.CreateFirewallRuleInput = {
        "action": action,
        "name": name,
        "dns_view_id": dns_view_id,
    }
    if block_override_dns_type is not None:
        input_["block_override_dns_type"] = block_override_dns_type
    if block_override_domain is not None:
        input_["block_override_domain"] = block_override_domain
    if block_override_ttl is not None:
        input_["block_override_ttl"] = block_override_ttl
    if block_response is not None:
        input_["block_response"] = block_response
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if confidence_threshold is not None:
        input_["confidence_threshold"] = confidence_threshold
    if description is not None:
        input_["description"] = description
    if dns_advanced_protection is not None:
        input_["dns_advanced_protection"] = dns_advanced_protection
    if firewall_domain_list_id is not None:
        input_["firewall_domain_list_id"] = firewall_domain_list_id
    if priority is not None:
        input_["priority"] = priority
    if q_type is not None:
        input_["q_type"] = q_type

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output