/
dns.py
51 lines (42 loc) · 1.4 KB
/
dns.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from troposphere import (
Ref, Join)
from troposphere import route53
from cumulus.chain import step
class Dns(step.Step):
def __init__(self,
base_domain,
hosted_zone_id,
dns_name,
):
step.Step.__init__(self)
self.base_domain = base_domain
self.hosted_zone_id = hosted_zone_id
self.dns_name = dns_name
def handle(self, chain_context):
template = chain_context.template
name = 'AlbAlias%s' % chain_context.instance_name
template.add_resource(route53.RecordSetGroup(
"Route53Records",
RecordSets=[
route53.RecordSet(
name,
Weight=1,
SetIdentifier="original",
AliasTarget=route53.AliasTarget(
HostedZoneId=self.hosted_zone_id,
DNSName=self.dns_name,
EvaluateTargetHealth=False,
),
Name=Join("", [
Ref("namespace"),
"-",
Ref("env"),
".",
self.base_domain,
"."
]),
Type="A",
)
],
HostedZoneName=Join("", [self.base_domain, "."])
))