Skip to content

Commit 19e7380

Browse files
committed
feat: added route 53 entry
1 parent fb79ac2 commit 19e7380

File tree

4 files changed

+56
-19
lines changed

4 files changed

+56
-19
lines changed

API.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ const autoScalerProps: AutoScalerProps = { ... }
810810
| --- | --- | --- |
811811
| <code><a href="#@smallcase/aws-cdk-microservice.AutoScalerProps.property.appName">appName</a></code> | <code>string</code> | *No description.* |
812812
| <code><a href="#@smallcase/aws-cdk-microservice.AutoScalerProps.property.asgName">asgName</a></code> | <code>string</code> | *No description.* |
813+
| <code><a href="#@smallcase/aws-cdk-microservice.AutoScalerProps.property.availabilityZones">availabilityZones</a></code> | <code>string[]</code> | *No description.* |
813814
| <code><a href="#@smallcase/aws-cdk-microservice.AutoScalerProps.property.maxSize">maxSize</a></code> | <code>string</code> | *No description.* |
814815
| <code><a href="#@smallcase/aws-cdk-microservice.AutoScalerProps.property.minSize">minSize</a></code> | <code>string</code> | *No description.* |
815816
| <code><a href="#@smallcase/aws-cdk-microservice.AutoScalerProps.property.networkProps">networkProps</a></code> | <code><a href="#@smallcase/aws-cdk-microservice.NetworkProps">NetworkProps</a>[]</code> | *No description.* |
@@ -840,6 +841,16 @@ public readonly asgName: string;
840841

841842
---
842843

844+
##### `availabilityZones`<sup>Required</sup> <a name="availabilityZones" id="@smallcase/aws-cdk-microservice.AutoScalerProps.property.availabilityZones"></a>
845+
846+
```typescript
847+
public readonly availabilityZones: string[];
848+
```
849+
850+
- *Type:* string[]
851+
852+
---
853+
843854
##### `maxSize`<sup>Required</sup> <a name="maxSize" id="@smallcase/aws-cdk-microservice.AutoScalerProps.property.maxSize"></a>
844855

845856
```typescript
@@ -1571,6 +1582,7 @@ const loadBalancerProps: LoadBalancerProps = { ... }
15711582
| <code><a href="#@smallcase/aws-cdk-microservice.LoadBalancerProps.property.lbArn">lbArn</a></code> | <code>string</code> | *No description.* |
15721583
| <code><a href="#@smallcase/aws-cdk-microservice.LoadBalancerProps.property.sslEnabled">sslEnabled</a></code> | <code>boolean</code> | *No description.* |
15731584
| <code><a href="#@smallcase/aws-cdk-microservice.LoadBalancerProps.property.targetGroupArn">targetGroupArn</a></code> | <code>string</code> | *No description.* |
1585+
| <code><a href="#@smallcase/aws-cdk-microservice.LoadBalancerProps.property.zoneId">zoneId</a></code> | <code>string</code> | *No description.* |
15741586
| <code><a href="#@smallcase/aws-cdk-microservice.LoadBalancerProps.property.zoneName">zoneName</a></code> | <code>string</code> | *No description.* |
15751587

15761588
---
@@ -1625,6 +1637,16 @@ public readonly targetGroupArn: string;
16251637

16261638
---
16271639

1640+
##### `zoneId`<sup>Required</sup> <a name="zoneId" id="@smallcase/aws-cdk-microservice.LoadBalancerProps.property.zoneId"></a>
1641+
1642+
```typescript
1643+
public readonly zoneId: string;
1644+
```
1645+
1646+
- *Type:* string
1647+
1648+
---
1649+
16281650
##### `zoneName`<sup>Required</sup> <a name="zoneName" id="@smallcase/aws-cdk-microservice.LoadBalancerProps.property.zoneName"></a>
16291651

16301652
```typescript
@@ -1651,6 +1673,7 @@ const microServiceProps: MicroServiceProps = { ... }
16511673
| --- | --- | --- |
16521674
| <code><a href="#@smallcase/aws-cdk-microservice.MicroServiceProps.property.ami">ami</a></code> | <code>string</code> | *No description.* |
16531675
| <code><a href="#@smallcase/aws-cdk-microservice.MicroServiceProps.property.appName">appName</a></code> | <code>string</code> | *No description.* |
1676+
| <code><a href="#@smallcase/aws-cdk-microservice.MicroServiceProps.property.availabilityZones">availabilityZones</a></code> | <code>string[]</code> | *No description.* |
16541677
| <code><a href="#@smallcase/aws-cdk-microservice.MicroServiceProps.property.env">env</a></code> | <code>string</code> | *No description.* |
16551678
| <code><a href="#@smallcase/aws-cdk-microservice.MicroServiceProps.property.role">role</a></code> | <code><a href="#@smallcase/aws-cdk-microservice.InternalRole">InternalRole</a></code> | *No description.* |
16561679
| <code><a href="#@smallcase/aws-cdk-microservice.MicroServiceProps.property.sshKey">sshKey</a></code> | <code>string</code> | *No description.* |
@@ -1691,6 +1714,16 @@ public readonly appName: string;
16911714

16921715
---
16931716

1717+
##### `availabilityZones`<sup>Required</sup> <a name="availabilityZones" id="@smallcase/aws-cdk-microservice.MicroServiceProps.property.availabilityZones"></a>
1718+
1719+
```typescript
1720+
public readonly availabilityZones: string[];
1721+
```
1722+
1723+
- *Type:* string[]
1724+
1725+
---
1726+
16941727
##### `env`<sup>Required</sup> <a name="env" id="@smallcase/aws-cdk-microservice.MicroServiceProps.property.env"></a>
16951728

16961729
```typescript
@@ -1881,6 +1914,7 @@ const networkProps: NetworkProps = { ... }
18811914
| <code><a href="#@smallcase/aws-cdk-microservice.NetworkProps.property.port">port</a></code> | <code>number</code> | *No description.* |
18821915
| <code><a href="#@smallcase/aws-cdk-microservice.NetworkProps.property.protocol">protocol</a></code> | <code>string</code> | *No description.* |
18831916
| <code><a href="#@smallcase/aws-cdk-microservice.NetworkProps.property.sslEnabled">sslEnabled</a></code> | <code>boolean</code> | *No description.* |
1917+
| <code><a href="#@smallcase/aws-cdk-microservice.NetworkProps.property.zoneId">zoneId</a></code> | <code>string</code> | *No description.* |
18841918
| <code><a href="#@smallcase/aws-cdk-microservice.NetworkProps.property.zoneName">zoneName</a></code> | <code>string</code> | *No description.* |
18851919

18861920
---
@@ -1945,6 +1979,16 @@ public readonly sslEnabled: boolean;
19451979

19461980
---
19471981

1982+
##### `zoneId`<sup>Required</sup> <a name="zoneId" id="@smallcase/aws-cdk-microservice.NetworkProps.property.zoneId"></a>
1983+
1984+
```typescript
1985+
public readonly zoneId: string;
1986+
```
1987+
1988+
- *Type:* string
1989+
1990+
---
1991+
19481992
##### `zoneName`<sup>Required</sup> <a name="zoneName" id="@smallcase/aws-cdk-microservice.NetworkProps.property.zoneName"></a>
19491993

19501994
```typescript

src/constructs/autoScalingGroup.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Resource } from 'aws-cdk-lib';
22
import { BlockDevice, BlockDeviceVolume, CfnAutoScalingGroup, EbsDeviceVolumeType } from 'aws-cdk-lib/aws-autoscaling';
3-
import { InstanceProps, InstanceType, IVpc, LaunchTemplate, LaunchTemplateAttributes, MachineImage, Port, SecurityGroup, SecurityGroupProps, Subnet, Vpc, VpcProps } from 'aws-cdk-lib/aws-ec2';
3+
import { InstanceProps, InstanceType, IVpc, LaunchTemplate, LaunchTemplateAttributes, MachineImage, Port, SecurityGroup, SecurityGroupProps, Vpc, VpcProps } from 'aws-cdk-lib/aws-ec2';
44
import { CfnTargetGroup, NetworkTargetGroupProps } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
55
import { Effect, PolicyStatement, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
66
import { Construct } from 'constructs';
@@ -19,6 +19,7 @@ export interface NetworkProps {
1919
readonly sslEnabled: boolean;
2020
readonly host: string;
2121
readonly lbArn: string;
22+
readonly zoneId: string;
2223
readonly zoneName: string;
2324
}
2425

@@ -96,6 +97,7 @@ export interface AutoScalerProps {
9697
readonly subnets: string[];
9798
readonly networkProps: NetworkProps[];
9899
readonly appName: string;
100+
readonly availabilityZones: string[];
99101
}
100102

101103
export class AutoScaler extends Resource {
@@ -117,7 +119,7 @@ export class AutoScaler extends Resource {
117119
},
118120
targetGroupArns: this.loadBalancerProperties.map( (lb) => { return lb.targetGroupArn; } ),
119121
tags: props.tags,
120-
availabilityZones: this.getZones(props.subnets),
122+
availabilityZones: props.availabilityZones,
121123
vpcZoneIdentifier: props.subnets,
122124
healthCheckGracePeriod: 300,
123125
});
@@ -280,23 +282,12 @@ export class AutoScaler extends Resource {
280282
lbArn: t.lbArn,
281283
sslEnabled: t.sslEnabled,
282284
targetGroupArn: tg.ref,
285+
zoneId: t.zoneId,
283286
zoneName: t.zoneName,
284287
});
285288

286289
});
287290

288291
return lbProps;
289292
}
290-
291-
private getZones(subnets: string[]) {
292-
var availabilityZones: string[] = [];
293-
subnets.forEach(subnet => {
294-
const net = Subnet.fromSubnetAttributes(this, subnet, {
295-
availabilityZone: 'dummy',
296-
subnetId: subnet,
297-
});
298-
availabilityZones.push(net.availabilityZone);
299-
});
300-
return availabilityZones;
301-
}
302293
}

src/constructs/microservice.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface MicroServiceProps {
1515
readonly instanceLabels?: CfnAutoScalingGroup.TagPropertyProperty[];
1616
readonly vpc: string;
1717
readonly subnets: string[];
18+
readonly availabilityZones: string[];
1819
readonly diskSize?: number;
1920
readonly role: InternalRole;
2021
readonly tcpRules?: IngressRule[];
@@ -89,7 +90,8 @@ export class MicroService extends Construct {
8990
blockDevice: {
9091
size: this.diskSize,
9192
name: '/dev/sda1',
92-
type: this.getDiskType(this.diskType ?? 'GP3'),
93+
// type: this.getDiskType(this.diskType ?? 'GP3'),
94+
type: EbsDeviceVolumeType.GP3,
9395
},
9496
vpc: {
9597
type: 'existing',
@@ -106,6 +108,7 @@ export class MicroService extends Construct {
106108
},
107109
tags: props.instanceLabels,
108110
subnets: this.subnets,
111+
availabilityZones: props.availabilityZones,
109112
});
110113

111114
if (this.createCodedeployApplication) {
@@ -191,7 +194,4 @@ export class MicroService extends Construct {
191194
return role;
192195
}
193196

194-
private getDiskType(type: string) {
195-
return type as EbsDeviceVolumeType;
196-
}
197197
}

src/constructs/network.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface LoadBalancerProps {
1111
readonly lbArn: string;
1212
readonly sslEnabled: boolean;
1313
readonly zoneName: string;
14+
readonly zoneId: string;
1415
}
1516

1617
export class BalancerEntry extends Resource {
@@ -84,7 +85,8 @@ export class BalancerEntry extends Resource {
8485
});
8586
new ARecord(this, 'record-' + props.hostHeader.split('.')[-2], {
8687
target: RecordTarget.fromAlias(new LoadBalancerTarget(lb)),
87-
zone: new HostedZone(this, props.hostHeader + '-zone', {
88+
zone: HostedZone.fromHostedZoneAttributes(this, props.hostHeader + '-zone', {
89+
hostedZoneId: props.zoneId,
8890
zoneName: props.zoneName,
8991
}),
9092
});

0 commit comments

Comments
 (0)