# Point a name at a resource

Answer a name, the zone apex included, with the current address of one of your apps, load balancers, bucket websites or CDN distributions, using an ALIAS record.

An `ALIAS` record has no values of its own: the nameservers answer it with the address of its
target as it is now, so nobody updates the record when the target moves. Unlike a `CNAME`, it works
at the apex. Replace _zone-id_ with the id of your hosted zone.

## What each target answers

| Target           | Answer                                                                                                                                                                         |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| App              | `A`: the address the app is served on (its load balancer's IPv4, or its machine's public address). Nothing while the app is being deleted.                                     |
| Load balancer    | `A` with its IPv4 and `AAAA` with its IPv6.                                                                                                                                    |
| Bucket website   | The addresses the static websites of buckets are served on. The name is added to the bucket's website domains.                                                                 |
| CDN distribution | `A` and `AAAA` of the distribution's healthy edge nodes, with a TTL of at most 30 seconds. List the name among the distribution's custom names too, or it gets no certificate. |

A target that has no address yet leaves the name existing but without an answer. When the target is
deleted, the `ALIAS` record is deleted with it.

## Records the platform writes for you

- Adding a custom domain to an app, when the domain is inside one of your hosted zones, writes an
  `ALIAS` to the app at that name (TTL 60). The app's domains panel then says "Answered by your
  hosted zone …, nothing to create". A domain added before its zone existed has no record: the panel
  names the `ALIAS` to add, or remove and re-add the domain.
- Adding a custom domain to a bucket website inside one of your zones writes an `ALIAS` to the
  bucket, when the name has no other records.
- Adding a custom name to a CDN distribution inside one of your zones writes an `ALIAS` when the
  name is the apex and has no other address records, or a `CNAME` when the name is below the apex
  and has no other records.

## Prerequisites

- Permission for `dns:ChangeRecords` on the zone. Without it, **Add record** is unavailable.
- In the console, also `dns:ListZones` to open **Hosted zones** (without it the page shows an
  access-denied notice) and `dns:GetZone` to open the zone (without it the zone's page is not
  found), and, to see the targets, `deploy:DescribeApp` (apps), `lb:DescribeLoadBalancers`,
  `s3:ListBuckets` or `cdn:ListDistributions`. Without `deploy:DescribeApp` and no other target, the
  dialog says "An ALIAS points at a deployed app, and listing this organization’s apps needs
  deploy:DescribeApp. Ask an administrator, or choose another record type."
- The target exists in your organization.

## Add the ALIAS record

**Console**
1. Open the zone. On the **Records** tab, choose **Add record**.
2. For **Name**, enter `@` for the apex, or a name such as www.
3. For **Type**, choose **ALIAS**.
4. For **Points at**, choose the app, load balancer, bucket website or CDN distribution.
5. Choose **Add**.

The table shows the record's value as "→" and the target.

**CLI**
```sh
dcloud dns records set zone-id --name @ --type ALIAS --load-balancer-id lb-id
```

Use `--app-id`, `--bucket` (a bucket name) or `--distribution-id` for the other targets.

**API**
```http
POST /dns/api/zones/zone-id/records
{ "name": "@", "type": "ALIAS", "loadBalancerId": "6f1d2c3b-4a5e-4f60-8a7b-9c0d1e2f3a4b" }
```

Send exactly one of `appId`, `loadBalancerId`, `bucket` or `distributionId`, and no `values`.

**Terraform**
```hcl
resource "dcloud_dns_record" "apex" {
  zone_id          = dcloud_dns_zone.main.id
  name             = "@"
  type             = "ALIAS"
  load_balancer_id = dcloud_lb.web.id
}
```

Or `app_id`, `bucket` or `distribution_id`.

To point an existing `ALIAS` at another target, edit it and choose another **Points at**, or send
the new target to `PUT /dns/api/zones/{id}/records/{recordId}`.

## When the record is refused

All with `400`:

- "An ALIAS record points at exactly one of: an app, a load balancer, a bucket website, a CDN
  distribution" when you send none or more than one target.
- "App not found", "Load balancer not found", "Bucket not found" or "Distribution not found".
- "www.example.com is already the domain of another bucket's website".
- "A health check goes on an A, AAAA or CNAME record; an ALIAS follows its target".
- "An ALIAS follows its target and cannot be routed".

## Related

- [Record sets](record-sets.md)
- [Use a custom domain](/docs/s3/guide/use-a-custom-domain) for a bucket website
- [Point a domain at a load balancer](/docs/lb/guide/point-a-domain)
- `dns.records.set` · `dcloud dns records set` · `dcloud_dns_record`
