Skip to content

Commit

Permalink
chore(route53): make examples compile (#17226)
Browse files Browse the repository at this point in the history
in this PR:
- chore(route53): make examples compile
- chore(route53-targets): make examples compile
- chore(route53-patterns): make examples compile

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
kaizencc authored Oct 29, 2021
1 parent 0d7452e commit 4c6cee5
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 70 deletions.
20 changes: 10 additions & 10 deletions packages/@aws-cdk/aws-route53-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ must be in US East (N. Virginia).
The following example creates an HTTPS redirect from `foo.example.com` to `bar.example.com`
As an existing certificate is not provided, one will be created in `us-east-1` by the CDK.

```ts
new HttpsRedirect(stack, 'Redirect', {
recordNames: ['foo.example.com'],
targetDomain: 'bar.example.com',
zone: HostedZone.fromHostedZoneAttributes(stack, 'HostedZone', {
hostedZoneId: 'ID',
zoneName: 'example.com',
})
});
```
```ts
new patterns.HttpsRedirect(this, 'Redirect', {
recordNames: ['foo.example.com'],
targetDomain: 'bar.example.com',
zone: route53.HostedZone.fromHostedZoneAttributes(this, 'HostedZone', {
hostedZoneId: 'ID',
zoneName: 'example.com',
}),
});
```
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-route53-patterns/rosetta/default.ts-fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Fixture with packages imported, but nothing else
import { Construct } from 'constructs';
import { Stack } from '@aws-cdk/core';
import * as route53 from '@aws-cdk/aws-route53';
import * as patterns from '@aws-cdk/aws-route53-patterns';

class Fixture extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);
/// here
}
}
71 changes: 57 additions & 14 deletions packages/@aws-cdk/aws-route53-targets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,72 @@ This library contains Route53 Alias Record targets for:
* API Gateway custom domains

```ts
import * as apigw from '@aws-cdk/aws-apigateway';

declare const zone: route53.HostedZone;
declare const restApi: apigw.LambdaRestApi;

new route53.ARecord(this, 'AliasRecord', {
zone,
target: route53.RecordTarget.fromAlias(new alias.ApiGateway(restApi)),
target: route53.RecordTarget.fromAlias(new targets.ApiGateway(restApi)),
// or - route53.RecordTarget.fromAlias(new alias.ApiGatewayDomain(domainName)),
});
```

* API Gateway V2 custom domains

```ts
import * as apigwv2 from '@aws-cdk/aws-apigatewayv2';

declare const zone: route53.HostedZone;
declare const domainName: apigwv2.DomainName;

new route53.ARecord(this, 'AliasRecord', {
zone,
target: route53.RecordTarget.fromAlias(new alias.ApiGatewayv2DomainProperties(domainName.regionalDomainName, domainName.regionalHostedZoneId)),
target: route53.RecordTarget.fromAlias(new targets.ApiGatewayv2DomainProperties(domainName.regionalDomainName, domainName.regionalHostedZoneId)),
});
```

* CloudFront distributions

```ts
import * as cloudfront from '@aws-cdk/aws-cloudfront';

declare const zone: route53.HostedZone;
declare const distribution: cloudfront.CloudFrontWebDistribution;

new route53.ARecord(this, 'AliasRecord', {
zone,
target: route53.RecordTarget.fromAlias(new alias.CloudFrontTarget(distribution)),
target: route53.RecordTarget.fromAlias(new targets.CloudFrontTarget(distribution)),
});
```

* ELBv2 load balancers

```ts
import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2';

declare const zone: route53.HostedZone;
declare const lb: elbv2.ApplicationLoadBalancer;

new route53.ARecord(this, 'AliasRecord', {
zone,
target: route53.RecordTarget.fromAlias(new alias.LoadBalancerTarget(elbv2)),
// or - route53.RecordTarget.fromAlias(new alias.ApiGatewayDomain(domainName)),
target: route53.RecordTarget.fromAlias(new targets.LoadBalancerTarget(lb)),
// or - route53.RecordTarget.fromAlias(new targets.ApiGatewayDomain(domainName)),
});
```

* Classic load balancers

```ts
import * as elb from '@aws-cdk/aws-elasticloadbalancing';

declare const zone: route53.HostedZone;
declare const lb: elb.LoadBalancer;

new route53.ARecord(this, 'AliasRecord', {
zone,
target: route53.RecordTarget.fromAlias(new alias.ClassicLoadBalancerTarget(elb)),
target: route53.RecordTarget.fromAlias(new targets.ClassicLoadBalancerTarget(lb)),
// or - route53.RecordTarget.fromAlias(new alias.ApiGatewayDomain(domainName)),
});
```
Expand All @@ -67,7 +91,12 @@ For example, if the Amazon-provided DNS for the load balancer is `ALB-xxxxxxx.us
* GlobalAccelerator

```ts
new route53.ARecord(stack, 'AliasRecord', {
import * as globalaccelerator from '@aws-cdk/aws-globalaccelerator';

declare const zone: route53.HostedZone;
declare const accelerator: globalaccelerator.Accelerator;

new route53.ARecord(this, 'AliasRecord', {
zone,
target: route53.RecordTarget.fromAlias(new targets.GlobalAcceleratorTarget(accelerator)),
// or - route53.RecordTarget.fromAlias(new targets.GlobalAcceleratorDomainTarget('xyz.awsglobalaccelerator.com')),
Expand All @@ -82,9 +111,14 @@ See [the documentation on DNS addressing](https://docs.aws.amazon.com/global-acc
**Important:** Based on the CFN docs for VPCEndpoints - [see here](attrDnsEntries) - the attributes returned for DnsEntries in CloudFormation is a combination of the hosted zone ID and the DNS name. The entries are ordered as follows: regional public DNS, zonal public DNS, private DNS, and wildcard DNS. This order is not enforced for AWS Marketplace services, and therefore this CDK construct is ONLY guaranteed to work with non-marketplace services.

```ts
new route53.ARecord(stack, "AliasRecord", {
import * as ec2 from '@aws-cdk/aws-ec2';

declare const zone: route53.HostedZone;
declare const interfaceVpcEndpoint: ec2.InterfaceVpcEndpoint;

new route53.ARecord(this, "AliasRecord", {
zone,
target: route53.RecordTarget.fromAlias(new alias.InterfaceVpcEndpointTarget(interfaceVpcEndpoint))
target: route53.RecordTarget.fromAlias(new targets.InterfaceVpcEndpointTarget(interfaceVpcEndpoint)),
});
```

Expand All @@ -94,35 +128,44 @@ See [the documentation on DNS addressing](https://docs.aws.amazon.com/global-acc
See [the Developer Guide](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/getting-started.html) for more info.

```ts
const [recordName, domainName] = ['www', 'example.com'];
import * as s3 from '@aws-cdk/aws-s3';

const recordName = 'www';
const domainName = 'example.com';

const bucketWebsite = new Bucket(this, 'BucketWebsite', {
const bucketWebsite = new s3.Bucket(this, 'BucketWebsite', {
bucketName: [recordName, domainName].join('.'), // www.example.com
publicReadAccess: true,
websiteIndexDocument: 'index.html',
});

const zone = HostedZone.fromLookup(this, 'Zone', {domainName}); // example.com
const zone = route53.HostedZone.fromLookup(this, 'Zone', {domainName}); // example.com

new route53.ARecord(this, 'AliasRecord', {
zone,
recordName, // www
target: route53.RecordTarget.fromAlias(new alias.BucketWebsiteTarget(bucket)),
target: route53.RecordTarget.fromAlias(new targets.BucketWebsiteTarget(bucketWebsite)),
});
```

* User pool domain

```ts
import * as cognito from '@aws-cdk/aws-cognito';

declare const zone: route53.HostedZone;
declare const domain: cognito.UserPoolDomain;
new route53.ARecord(this, 'AliasRecord', {
zone,
target: route53.RecordTarget.fromAlias(new alias.UserPoolDomainTarget(domain)),
target: route53.RecordTarget.fromAlias(new targets.UserPoolDomainTarget(domain)),
});
```

* Route 53 record

```ts
declare const zone: route53.HostedZone;
declare const record: route53.ARecord;
new route53.ARecord(this, 'AliasRecord', {
zone,
target: route53.RecordTarget.fromAlias(new targets.Route53RecordTarget(record)),
Expand Down
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-route53-targets/rosetta/default.ts-fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Fixture with packages imported, but nothing else
import { Construct } from 'constructs';
import { Stack } from '@aws-cdk/core';
import * as route53 from '@aws-cdk/aws-route53';
import * as targets from '@aws-cdk/aws-route53-targets';

class Fixture extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);
/// here
}
}
Loading

0 comments on commit 4c6cee5

Please sign in to comment.