Hybrid networking is unusual among AWS topics: most of what you do through the SDK is read, not write. The physical Direct Connect link is ordered from a provider, and the expensive gateways are usually stood up once by a network team. Your day-to-day SDK work is inventorying and health-checking what already exists.
These examples walk that read path in both Python (boto3) and TypeScript (AWS SDK for JavaScript v3): describe a Direct Connect connection, the virtual interfaces on it, and its gateway association, then the Transit Gateway, its attachments, and its route tables. Every call here is safe to run against a live account.
Combine the calls into a quick health snapshot you can run on a schedule.
# --- Python (boto3) ---conns = dx.describe_connections()["connections"]up = [c for c in conns if c["connectionState"] == "available"]print(f"{len(up)}/{len(conns)} Direct Connect links available")vifs = dx.describe_virtual_interfaces()["virtualInterfaces"]down = [v["virtualInterfaceId"] for v in vifs if v["virtualInterfaceState"] != "available"]print("VIFs not up:", down or "none")
// --- TypeScript (AWS SDK v3) ---import { DescribeConnectionsCommand, DescribeVirtualInterfacesCommand } from "@aws-sdk/client-direct-connect";const conns = (await dx.send(new DescribeConnectionsCommand({}))).connections ?? [];const up = conns.filter((c) => c.connectionState === "available");console.log(`${up.length}/${conns.length} Direct Connect links available`);const vifs = (await dx.send(new DescribeVirtualInterfacesCommand({}))).virtualInterfaces ?? [];const down = vifs.filter((v) => v.virtualInterfaceState !== "available") .map((v) => v.virtualInterfaceId);console.log("VIFs not up:", down.length ? down : "none");
Reading state on a schedule catches a flapping link before users report it.
Pair this with CloudWatch metrics like ConnectionState for alerting rather than polling alone.
Nothing here mutates anything, so it is safe to run from a read-only monitoring role.
Extend it with attachment and association states for a full hybrid picture.