Skip to content

Commit

Permalink
fix(route53): remove http:// from bucket target (#4070)
Browse files Browse the repository at this point in the history
* fix(route53-targets): remove `http://` from bucket target
* change bucket type to IBucket to allow static import

* chore: tslint fix

* fix: use bucketWebsiteDomainName property

* chore: remove unnecessary quotes
  • Loading branch information
Jimmy Gaussen authored and mergify[bot] committed Sep 18, 2019
1 parent 1f64b87 commit 621441d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {RegionInfo} from '@aws-cdk/region-info';
* Use a S3 as an alias record target
*/
export class BucketWebsiteTarget implements route53.IAliasRecordTarget {
constructor(private readonly bucket: s3.Bucket) {
constructor(private readonly bucket: s3.IBucket) {
}

public bind(_record: route53.IRecordSet): route53.AliasRecordTargetConfig {
Expand All @@ -29,7 +29,7 @@ export class BucketWebsiteTarget implements route53.IAliasRecordTarget {

return {
hostedZoneId,
dnsName: this.bucket.bucketWebsiteUrl,
dnsName: this.bucket.bucketWebsiteDomainName,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,66 @@ test('use S3 bucket website as record target', () => {
// THEN
expect(stack).toHaveResource('AWS::Route53::RecordSet', {
AliasTarget: {
DNSName: { "Fn::GetAtt": [ "Bucket83908E77", "WebsiteURL"] },
DNSName: {
"Fn::Select": [
2,
{
"Fn::Split": [
"/",
{
"Fn::GetAtt": [
"Bucket83908E77",
"WebsiteURL"
]
}
]
}
]
},
HostedZoneId: "Z3AQBSTGFYJSTF"
},
});
});

test('use S3 bucket website as record target (fromBucketName)', () => {
// GIVEN
const app = new App();
const stack = new Stack(app, 'test', {env: {region: 'us-east-1'}});

const bucketWebsite = s3.Bucket.fromBucketName(stack, 'Bucket', 'test');

// WHEN
const zone = new route53.PublicHostedZone(stack, 'HostedZone', { zoneName: 'test.public' });
new route53.ARecord(zone, 'Alias', {
zone,
recordName: '_foo',
target: route53.RecordTarget.fromAlias(new targets.BucketWebsiteTarget(bucketWebsite))
});

// THEN
expect(stack).toHaveResource('AWS::Route53::RecordSet', {
AliasTarget: {
DNSName: {
"Fn::Select": [
2,
{
"Fn::Split": [
"/",
{
"Fn::Join": [
"",
[
"test.s3-website-us-east-1.",
{
Ref: "AWS::URLSuffix"
}
]
]
}
]
}
]
},
HostedZoneId: "Z3AQBSTGFYJSTF"
},
});
Expand Down

0 comments on commit 621441d

Please sign in to comment.