-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws-route53-targets): Support for Elastic Beanstalk environment …
…URLs (#16305) ## Summary This PR adds a new Route53 target `ElasticBeanstalkEnvironmentTarget` for creating RecordSets that target Elastic Beanstalk environment URLs. E.g. ```ts const ebsEnvironmentUrl = 'mysampleenvironment.xyz.us-east-1.elasticbeanstalk.com'; new route53.ARecord(this, 'AliasRecord', { zone, target: route53.RecordTarget.fromAlias(new alias.ElasticBeanstalkEnvironmentTarget(ebsEnvironmentUrl)), }); ``` [How to find your Elastic Beanstalk environment URL](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-beanstalk-environment.html#routing-to-beanstalk-environment-get-domain-name) Fixes: #3206 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
8 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/@aws-cdk/aws-route53-targets/lib/elastic-beanstalk-environment-target.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as route53 from '@aws-cdk/aws-route53'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import { RegionInfo } from '@aws-cdk/region-info'; | ||
|
||
/** | ||
* Use an Elastic Beanstalk environment URL as an alias record target. | ||
* E.g. mysampleenvironment.xyz.us-east-1.elasticbeanstalk.com | ||
* | ||
* Only supports Elastic Beanstalk environments created after 2016 that have a regional endpoint. | ||
*/ | ||
export class ElasticBeanstalkEnvironmentEndpointTarget implements route53.IAliasRecordTarget { | ||
constructor(private readonly environmentEndpoint: string) { | ||
} | ||
|
||
public bind(_record: route53.IRecordSet, _zone?: route53.IHostedZone): route53.AliasRecordTargetConfig { | ||
if (cdk.Token.isUnresolved(this.environmentEndpoint)) { | ||
throw new Error('Cannot use an EBS alias as `environmentEndpoint`. You must find your EBS environment endpoint via the AWS console. See the Elastic Beanstalk developer guide: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customdomains.html'); | ||
} | ||
|
||
const dnsName = this.environmentEndpoint; | ||
const region = cdk.Fn.select(2, cdk.Fn.split('.', dnsName)); | ||
const { ebsEnvEndpointHostedZoneId: hostedZoneId } = RegionInfo.get(region); | ||
|
||
if (!hostedZoneId || !dnsName) { | ||
throw new Error(`Elastic Beanstalk environment target is not supported for the "${region}" region.`); | ||
} | ||
|
||
return { | ||
hostedZoneId, | ||
dnsName, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/@aws-cdk/aws-route53-targets/test/elastic-beanstalk-environment-target.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import '@aws-cdk/assert-internal/jest'; | ||
import * as route53 from '@aws-cdk/aws-route53'; | ||
import { Stack } from '@aws-cdk/core'; | ||
import * as targets from '../lib'; | ||
|
||
test('use EBS environment as record target', () => { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const zone = new route53.PublicHostedZone(stack, 'HostedZone', { zoneName: 'test.public' }); | ||
|
||
// WHEN | ||
new route53.ARecord(stack, 'Alias', { | ||
zone, | ||
recordName: '_foo', | ||
target: route53.RecordTarget.fromAlias(new targets.ElasticBeanstalkEnvironmentEndpointTarget('mysampleenvironment.xyz.us-east-1.elasticbeanstalk.com')), | ||
}); | ||
|
||
// THEN | ||
expect(stack).toHaveResource('AWS::Route53::RecordSet', { | ||
AliasTarget: { | ||
DNSName: 'mysampleenvironment.xyz.us-east-1.elasticbeanstalk.com', | ||
HostedZoneId: 'Z117KPS5GTRQ2G', | ||
}, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters