Skip to content

Commit

Permalink
Soft-deprecating IDistribution.domainName
Browse files Browse the repository at this point in the history
  • Loading branch information
njlynch committed Jul 15, 2020
1 parent 4466043 commit fbbda72
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-cloudfront/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ URLs and not S3 URLs directly.
### Domain Names and Certificates

When you create a distribution, CloudFront assigns a domain name for the distribution, for example: `d111111abcdef8.cloudfront.net`; this value can
be retrieved from `distribution.domainName`. CloudFront distributions use a default certificate (`*.cloudfront.net`) to support HTTPS by default. If
you want to use your own domain name, such as `www.example.com`, you must associate a certificate with your distribution that contains your domain
name. The certificate must be present in the AWS Certificate Manager (ACM) service in the US East (N. Virginia) region; the certificate may either be
created by ACM, or created elsewhere and imported into ACM.
be retrieved from `distribution.distributionDomainName`. CloudFront distributions use a default certificate (`*.cloudfront.net`) to support HTTPS by
default. If you want to use your own domain name, such as `www.example.com`, you must associate a certificate with your distribution that contains
your domain name. The certificate must be present in the AWS Certificate Manager (ACM) service in the US East (N. Virginia) region; the certificate
may either be created by ACM, or created elsewhere and imported into ACM.

```ts
const myCertificate = new acm.DnsValidatedCertificate(this, 'mySiteCert', {
Expand Down
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-cloudfront/lib/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ export interface IDistribution extends IResource {
* The domain name of the Distribution, such as d111111abcdef8.cloudfront.net.
*
* @attribute
* @deprecated - Use `distributionDomainName` instead.
*/
readonly domainName: string;

/**
* The domain name of the Distribution, such as d111111abcdef8.cloudfront.net.
*
* @attribute
*/
readonly distributionDomainName: string;

/**
* The distribution ID for this distribution.
*
Expand Down Expand Up @@ -100,17 +108,20 @@ export class Distribution extends Resource implements IDistribution {
public static fromDistributionAttributes(scope: Construct, id: string, attrs: DistributionAttributes): IDistribution {
return new class extends Resource implements IDistribution {
public readonly domainName: string;
public readonly distributionDomainName: string;
public readonly distributionId: string;

constructor() {
super(scope, id);
this.domainName = attrs.domainName;
this.distributionDomainName = attrs.domainName;
this.distributionId = attrs.distributionId;
}
}();
}

public readonly domainName: string;
public readonly distributionDomainName: string;
public readonly distributionId: string;

private readonly defaultBehavior: CacheBehavior;
Expand Down Expand Up @@ -152,6 +163,7 @@ export class Distribution extends Resource implements IDistribution {
} });

this.domainName = distribution.attrDomainName;
this.distributionDomainName = distribution.attrDomainName;
this.distributionId = distribution.ref;
}

Expand Down
12 changes: 11 additions & 1 deletion packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,19 @@ export class CloudFrontWebDistribution extends cdk.Resource implements IDistribu
/**
* The domain name created by CloudFront for this distribution.
* If you are using aliases for your distribution, this is the domainName your DNS records should point to.
* (In Route53, you could create an ALIAS record to this value, for example. )
* (In Route53, you could create an ALIAS record to this value, for example.)
*
* @deprecated - Use `distributionDomainName` instead.
*/
public readonly domainName: string;

/**
* The domain name created by CloudFront for this distribution.
* If you are using aliases for your distribution, this is the domainName your DNS records should point to.
* (In Route53, you could create an ALIAS record to this value, for example.)
*/
public readonly distributionDomainName: string;

/**
* The distribution ID for this distribution.
*/
Expand Down Expand Up @@ -897,6 +906,7 @@ export class CloudFrontWebDistribution extends cdk.Resource implements IDistribu
const distribution = new CfnDistribution(this, 'CFDistribution', { distributionConfig });
this.node.defaultChild = distribution;
this.domainName = distribution.attrDomainName;
this.distributionDomainName = distribution.attrDomainName;
this.distributionId = distribution.ref;
}

Expand Down

0 comments on commit fbbda72

Please sign in to comment.