Skip to content
cloudemu
Services

DNS

Emulated DNS zones and records, including weighted routing, modelled on Route53, Azure DNS, and Cloud DNS

aws Route53azr DNSgcp Cloud DNS

Emulates managed DNS — the hosted zones and resource records you'd create in Route53 to point a name at an address. You create a zone for a domain, then add records (A, CNAME, MX, TXT, and so on) that resolve names within it.

Reach for it in tests when your code provisions zones, writes records, or depends on weighted routing to split traffic across endpoints — so you can exercise those paths without a live DNS provider. Under the hood a zone is a named container and each record is a name/type/value set with an optional TTL.

ProviderServiceDriver
AWSRoute53aws.Route53
AzureDNSazure.DNS
GCPCloud DNSgcp.CloudDNS

Create a zone#

A zone is the container your records live in — the equivalent of a Route53 hosted zone for a domain. Create one before adding any records:

import (
    dnsdriver "github.com/stackshy/cloudemu/v2/services/dns/driver"
    "github.com/stackshy/cloudemu/v2/services/scope"
)

zone, _ := aws.Route53.CreateZone(ctx, dnsdriver.ZoneConfig{
    Name: "example.com",
})

// scope.Scope{} lists every zone; pass a subscription/resource group or
// project to narrow the results.
zones, _ := aws.Route53.ListZones(ctx, scope.Scope{})

Create and list records#

A record maps a name and type to one or more values, mirroring a Route53 resource record set. ListRecords returns them in a stable order for the zone:

aws.Route53.CreateRecord(ctx, dnsdriver.RecordConfig{
    ZoneID: zone.ID,
    Name:   "api.example.com",
    Type:   "A",
    TTL:    300,
    Values: []string{"10.0.0.1", "10.0.0.2"},
})

records, _ := aws.Route53.ListRecords(ctx, zone.ID)

Weighted routing#

Weighted routing splits traffic across endpoints by giving several records the same name and type but a different Weight and a unique SetID — the Route53 pattern where each record's share of traffic is its weight over the total. Here www.example.com sends roughly 70% of resolutions to one address and 30% to the other:

w70 := 70
w30 := 30

aws.Route53.CreateRecord(ctx, dnsdriver.RecordConfig{
    ZoneID: zone.ID,
    Name:   "www.example.com",
    Type:   "A",
    TTL:    300,
    Values: []string{"1.1.1.1"},
    Weight: &w70,
    SetID:  "primary",
})

aws.Route53.CreateRecord(ctx, dnsdriver.RecordConfig{
    ZoneID: zone.ID,
    Name:   "www.example.com",
    Type:   "A",
    TTL:    300,
    Values: []string{"2.2.2.2"},
    Weight: &w30,
    SetID:  "secondary",
})

Weight is a *int, so leaving it nil marks a record as unweighted; the SetID is what keeps two records at the same name from colliding.

Behavior & fidelity#

  • Records key on name, type, and set ID. An unweighted record is a single entry per name+type; weighted records sharing a name+type each carry a distinct SetID, and a plain GetRecord resolves to a stable one of them rather than a random pick.
  • Deleting a name+type removes its whole set. Removing a record by name and type clears every weighted variant under it, matching how a resource record set is a single unit.
  • SDK-compat status — Portable Go API only. Real aws-sdk-go-v2/service/route53, armdns, and Cloud DNS REST clients can't talk to cloudemu yet — DNS SDK-compat handlers will ship in lockstep across all three providers in a future phase. The full driver semantics above (zones, records, weighted routing) are available today through the Portable Go API.

On this page

On this page