-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-domain.template.yaml
61 lines (56 loc) · 1.85 KB
/
api-domain.template.yaml
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
59
60
61
AWSTemplateFormatVersion: '2010-09-09'
Description: >-
Creates a custom domain for API Gateway.
Parameters:
ApiDomain:
Type: String
Description: Full domain for the API Gateway custom domain that you want to create.
CertificateArn:
Type: String
Description: Certificate Manager ARN for the ApiDomain certificate. Required to use a custom domain.
HostedZoneId:
Type: String
Description: If provided, creates a record set group connecting the custom domain to a Route53 zone.
Default: ''
HostedZoneName:
Type: String
Description: Can provide this as an alternative to HostedZoneId
Default: ''
Conditions:
HasHostedZoneId: !Not [!Equals [!Ref HostedZoneId, '']]
HasHostedZoneName: !Not [!Equals [!Ref HostedZoneName, '']]
CreateRecordSetGroup: !Or
- !Condition HasHostedZoneId
- !Condition HasHostedZoneName
Resources:
CustomDomain:
Type: AWS::ApiGatewayV2::DomainName
Properties:
DomainName: !Ref ApiDomain
DomainNameConfigurations:
- CertificateArn: !Ref CertificateArn
SecurityPolicy: TLS_1_2
RecordSetGroup:
Type: AWS::Route53::RecordSetGroup
Condition: CreateRecordSetGroup
Properties: !If
- HasHostedZoneId
- HostedZoneId: !Ref HostedZoneId
RecordSets:
- Name: !Ref CustomDomain
Type: A
AliasTarget:
HostedZoneId: !GetAtt CustomDomain.RegionalHostedZoneId
DNSName: !GetAtt CustomDomain.RegionalDomainName
- HostedZoneName: !Ref HostedZoneName
RecordSets:
- Name: !Ref CustomDomain
Type: A
AliasTarget:
HostedZoneId: !GetAtt CustomDomain.RegionalHostedZoneId
DNSName: !GetAtt CustomDomain.RegionalDomainName
Outputs:
CustomDomain:
Value: !Ref CustomDomain
CertificateArn:
Value: !Ref CertificateArn