Skip to content

Cloud Provider IP Blocking

FastAPI Guard can automatically detect and block requests from major cloud providers.

Supported Providers

Currently supported cloud providers: - Amazon Web Services (AWS) - Google Cloud Platform (GCP) - Microsoft Azure

Basic Configuration

Enable cloud provider IP blocking:

config = SecurityConfig(
    block_cloud_providers={"AWS", "GCP", "Azure"}
)

Selective Blocking

Block specific providers:

config = SecurityConfig(
    block_cloud_providers={"AWS"}  # Only block AWS IPs
)

IP Range Updates

Cloud IP ranges are automatically updated daily. You can manually refresh them:

from guard.handlers.cloud_handler import cloud_handler

# Refresh IP ranges
cloud_handler.refresh()

Custom IP Checking

Check if an IP belongs to a cloud provider:

from guard.handlers.cloud_handler import cloud_handler

@app.get("/check-cloud/{ip}")
async def check_cloud_ip(ip: str):
    is_cloud = cloud_handler.is_cloud_ip(
        ip,
        providers={"AWS", "GCP", "Azure"}
    )
    return {"ip": ip, "is_cloud": is_cloud}