Skip to content

Commit e558452

Browse files
add NS record and cleanup template naming
1 parent b8ee5af commit e558452

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

cicd/3-app/aiproxy/template.yml

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
AWSTemplateFormatVersion: 2010-09-09
22
Transform: AWS::Serverless-2016-10-31
3-
Description: Provision an instance of the Javabuilder service. Empty the ContentBucket before deleting this Stack.
3+
Description: Provision an instance of the AI Proxy service.
44
Parameters:
55
BaseDomainName:
66
Type: String
77
Description: Base domain name (e.g. 'code.org' in 'aiproxy.code.org').
8-
# BaseDomainNameHostedZonedID:
9-
# Type: String
10-
# Description: AWS Route53 Hosted Zone ID for base domain name.
118
SubdomainName:
129
Type: String
13-
Description: Subdomain name for javabuilder service (e.g. 'javabuilder' in 'javabuilder.code.org').
10+
Description: Subdomain name for aiproxy service (e.g. 'aiproxy' in 'aiproxy.code.org').
1411
AppImageUri:
1512
Type: String
1613
Description: URI of the Docker image in ECR.
@@ -20,11 +17,27 @@ Parameters:
2017

2118
Resources:
2219

20+
# ------------------
21+
# DNS
22+
# ------------------
23+
24+
# Create a dedicated Hosted Zone for this environment
2325
HostedZone:
2426
Type: AWS::Route53::HostedZone
2527
Properties:
2628
Name: !Sub "${SubdomainName}.${BaseDomainName}."
2729

30+
# Make the Hosted Zone the authoritative DNS server for this subdomain
31+
NSRecordSet:
32+
Type: AWS::Route53::RecordSet
33+
Properties:
34+
HostedZone: code.org
35+
Name: !Sub "${SubdomainName}.${BaseDomainName}."
36+
Type: NS
37+
TTL: 300
38+
ResourceRecords:
39+
- !GetAtt HostedZone.NameServers
40+
2841
Domain:
2942
Type: AWS::Route53::RecordSet
3043
Properties:
@@ -35,6 +48,10 @@ Resources:
3548
DNSName: !GetAtt LoadBalancer.DNSName
3649
HostedZoneId: !GetAtt LoadBalancer.CanonicalHostedZoneID
3750

51+
# ------------------
52+
# Load Balancer
53+
# ------------------
54+
3855
LoadBalancer:
3956
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
4057
Properties:
@@ -47,20 +64,19 @@ Resources:
4764
- !ImportValue VPC-PublicSubnetD
4865
- !ImportValue VPC-PublicSubnetE
4966

50-
LoadBalancerListener:
67+
Listener:
5168
Type: AWS::ElasticLoadBalancingV2::Listener
5269
Properties:
5370
DefaultActions:
5471
- Type: forward
55-
TargetGroupArn: !Ref ECSTargetGroup
72+
TargetGroupArn: !Ref TargetGroup
5673
LoadBalancerArn: !Ref LoadBalancer
5774
Port: 80
5875
Protocol: HTTP
5976

60-
ECSTargetGroup:
77+
TargetGroup:
6178
Type: AWS::ElasticLoadBalancingV2::TargetGroup
6279
Properties:
63-
# TODO: This copies geocoder, but we should probably have a separate VPC for this service.
6480
VpcId: !ImportValue VPC
6581
Port: 80
6682
TargetType: ip
@@ -72,12 +88,16 @@ Resources:
7288
HealthyThresholdCount: 2
7389
UnhealthyThresholdCount: 2
7490

91+
# ------------------
92+
# ECS Service
93+
# ------------------
94+
7595
ECSCluster:
7696
Type: "AWS::ECS::Cluster"
7797

7898
ECSService:
7999
Type: "AWS::ECS::Service"
80-
DependsOn: LoadBalancerListener
100+
DependsOn: Listener
81101
Properties:
82102
Cluster: !Ref ECSCluster
83103
DesiredCount: 1
@@ -95,7 +115,7 @@ Resources:
95115
LoadBalancers:
96116
- ContainerName: aiproxy
97117
ContainerPort: 80
98-
TargetGroupArn: !Ref ECSTargetGroup
118+
TargetGroupArn: !Ref TargetGroup
99119

100120
ECSSecurityGroup:
101121
Type: AWS::EC2::SecurityGroup
@@ -134,12 +154,17 @@ Resources:
134154
awslogs-region: !Ref AWS::Region
135155
awslogs-stream-prefix: ecs
136156

157+
# ------------------
158+
# Logging & Alerts
159+
# ------------------
160+
137161
LogGroup:
138162
Type: AWS::Logs::LogGroup
139163
Properties:
140164
LogGroupName: !Sub "${AWS::StackName}"
141165

142166
Outputs:
143-
AiProxyURL:
144-
Value:
145-
!Ref Domain
167+
URL:
168+
Value: !Ref Domain
169+
Export:
170+
Name: !Sub "${AWS::StackName}-URL"

0 commit comments

Comments
 (0)