-
Notifications
You must be signed in to change notification settings - Fork 6
/
create_cname.py
58 lines (42 loc) · 2 KB
/
create_cname.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
52
53
54
55
56
57
58
import boto3, subprocess
HOSTED_ZONE_ID = 'ZU1MAY9ZO09'
DOMAIN_NAME = 'elliottlamararnold.com'
REGION = 'us-east-1'
def get_wordpress_alb_fqdn():
cmd = "kubectl get svc | awk '/^wordpress/ {print $4}'"
try:
output, _ = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True).communicate()
return str(output.decode().strip())
except Exception as e:
print(str(e))
def map_alb_to_domain(hosted_zone_id=HOSTED_ZONE_ID, domain_name=DOMAIN_NAME):
r53 = boto3.client('route53',region_name=REGION)
try:
r53.change_resource_record_sets(
HostedZoneId=hosted_zone_id,
ChangeBatch={
"Comment": "Creating Alias resource record sets in Route 53",
"Changes": [
{
"Action": "CREATE",
"ResourceRecordSet": { "Name": f"blog.{domain_name}", "Type": "CNAME", 'TTL': 120,
'ResourceRecords': [{'Value': get_wordpress_alb_fqdn()},
]
}
}
]
}
)
except Exception as e:
print(e)
if __name__ == "__main__":
map_alb_to_domain()
# https://stackoverflow.com/questions/46582196/invalidchangebatch-when-calling-the-changeresourcerecordsets-operation-using
# [Tried to create an alias that targets ae908cd290ff9448ab69f7fbdc517da5.,
# type A in zone Z03316531PQU1MAY9ZO09, but the alias target name does not lie within the target zone,
# Tried to create an alias that targets ae908cd290ff9448ab69f7fbdc517da5.,
# type A in zone Z03316531PQU1MAY9ZO09, but that target was not found]
# Can only create an alias when you purchase domain via AWS.
#With an alias you can associate a domain with pre-existing aws resources
# helm upgrade --install ingress-nginx ingress-nginx --repo https://kubernetes.github.io/ingress-nginx
# helm install cert-manager jetstack/cert-manager --version v1.7.1 --set installCRDs=true