Skip to content

Commit 500c2c3

Browse files
committed
add dns-template
1 parent 476b8ef commit 500c2c3

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,12 @@ $ aws cloudformation create-stack --stack-name <スタック名> --template-url
101101
```bash
102102
$ aws cloudformation update-stack --stack-name <スタック名> --template-url https://s3-ap-northeast-1.amazonaws.com/<バケット名>/<tag名>/cloudformation-template-update-stack.json --capabilities '["CAPABILITY_IAM","CAPABILITY_NAMED_IAM"]'
103103
```
104+
105+
106+
## ドメインの割当
107+
108+
APIをデプロイ後にdns-templateのスタックをデプロイすることでドメインが割り当てられます
109+
110+
```
111+
aws cloudformation deploy --stack-name <スタック名> --template /path/to/dns-template.yml --capabilities '["CAPABILITY_AUTO_EXPAND"]' --parameter-overrides Doamin=<ネイキッドドメイン> SubDomain=<サブドメイン> HostedZoneId=<Route53のゾーンID> RestApiId=<割り当てたいAPIのID> CertificateArn=<ACMで発行した証明書のARN>
112+
```

dns-template.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Description: OAuth API Domain
3+
4+
Parameters:
5+
Doamin:
6+
Type: String
7+
Default: alis.to
8+
SubDomain:
9+
Type: String
10+
Default: oauth2
11+
HostedZoneId:
12+
Type: String
13+
RestApiId:
14+
Type: String
15+
CertificateArn:
16+
Type: String
17+
18+
Resources:
19+
RestApiRecordSet:
20+
Type: AWS::Route53::RecordSet
21+
Properties:
22+
HostedZoneId: !Ref HostedZoneId
23+
Name: !Sub
24+
- ${SubDomain}.${Domain}
25+
- SubDomain: !Ref SubDomain
26+
Domain: !Ref Doamin
27+
TTL: 60
28+
Type: CNAME
29+
ResourceRecords:
30+
- !GetAtt RestApiDomain.RegionalDomainName
31+
RestApiDomain:
32+
Type: AWS::ApiGateway::DomainName
33+
Properties:
34+
DomainName: !Sub
35+
- ${SubDomain}.${Domain}
36+
- SubDomain: !Ref SubDomain
37+
Domain: !Ref Doamin
38+
EndpointConfiguration:
39+
Types:
40+
- REGIONAL
41+
RegionalCertificateArn: !Ref CertificateArn
42+
ApiBasePathMapping:
43+
Type: AWS::ApiGateway::BasePathMapping
44+
Properties:
45+
DomainName: !Sub
46+
- ${SubDomain}.${Domain}
47+
- SubDomain: !Ref SubDomain
48+
Domain: !Ref Doamin
49+
RestApiId: !Ref RestApiId
50+
Stage: production
51+
DependsOn:
52+
- RestApiRecordSet
53+
- RestApiDomain

0 commit comments

Comments
 (0)