AssociateAliasCommand

Associates an alias (also known as a CNAME or an alternate domain name) with a CloudFront distribution.

With this operation you can move an alias that's already in use on a CloudFront distribution to a different distribution in one step. This prevents the downtime that could occur if you first remove the alias from one distribution and then separately add the alias to another distribution.

To use this operation to associate an alias with a distribution, you provide the alias and the ID of the target distribution for the alias. For more information, including how to set up the target distribution, prerequisites that you must complete, and other restrictions, see Moving an alternate domain name to a different distribution  in the Amazon CloudFront Developer Guide.

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { CloudFrontClient, AssociateAliasCommand } from "@aws-sdk/client-cloudfront"; // ES Modules import
// const { CloudFrontClient, AssociateAliasCommand } = require("@aws-sdk/client-cloudfront"); // CommonJS import
const client = new CloudFrontClient(config);
const input = { // AssociateAliasRequest
  TargetDistributionId: "STRING_VALUE", // required
  Alias: "STRING_VALUE", // required
};
const command = new AssociateAliasCommand(input);
const response = await client.send(command);
// {};

AssociateAliasCommand Input

See AssociateAliasCommandInput for more details

Parameter
Type
Description
Alias
Required
string | undefined

The alias (also known as a CNAME) to add to the target distribution.

TargetDistributionId
Required
string | undefined

The ID of the distribution that you're associating the alias with.

AssociateAliasCommand Output

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.

Throws

Name
Fault
Details
AccessDenied
client

Access denied.

IllegalUpdate
client

The update contains modifications that are not allowed.

InvalidArgument
client

An argument is invalid.

NoSuchDistribution
client

The specified distribution does not exist.

TooManyDistributionCNAMEs
client

Your request contains more CNAMEs than are allowed per distribution.

CloudFrontServiceException
Base exception class for all service exceptions from CloudFront service.