Skip to content

Route 53完全ガイド

Route 53は、AWSのDNSサービスです。実務で使えるDNS設定とトラフィックルーティングを詳しく解説します。

Route 53は、ドメイン名をIPアドレスに変換するDNSサービスです。また、トラフィックルーティング機能も提供します。

ユーザー
↓(ドメイン名でアクセス)
Route 53(DNS解決)
↓(IPアドレスを返す)
EC2インスタンス、ALBなど

問題のある構成(外部DNSプロバイダー):

Terminal window
# 問題: 外部DNSプロバイダーの使用
# 1. AWSサービスとの統合が弱い
# 2. ヘルスチェック機能がない
# 3. トラフィックルーティングが困難
# 4. コストが高い
# 問題点:
# 1. AWSサービスとの統合不足
# 2. 機能の制限
# 3. コストの問題

解決: Route 53による統合

# 解決: Route 53の使用
Resources:
HostedZone:
Type: AWS::Route53::HostedZone
Properties:
Name: example.com
# メリット:
# 1. AWSサービスとの深い統合
# 2. ヘルスチェック機能
# 3. 高度なトラフィックルーティング
# 4. コスト効率

ホストゾーンは、ドメインのDNSレコードを管理するコンテナです。

Terminal window
# ホストゾーンの作成
aws route53 create-hosted-zone \
--name example.com \
--caller-reference $(date +%s)
# ホストゾーンの一覧表示
aws route53 list-hosted-zones
# ネームサーバーの確認
aws route53 get-hosted-zone --id Z1234567890ABC
Resources:
ARecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 300
ResourceRecords:
- 93.184.216.34
Resources:
AAAARecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: AAAA
TTL: 300
ResourceRecords:
- 2606:2800:220:1:248:1893:25c8:1946
Resources:
CNAMERecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: blog.example.com
Type: CNAME
TTL: 300
ResourceRecords:
- example-blog.com
Resources:
AliasRecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
AliasTarget:
DNSName: !GetAtt ApplicationLoadBalancer.DNSName
HostedZoneId: !GetAtt ApplicationLoadBalancer.CanonicalHostedZoneID
EvaluateTargetHealth: true
Resources:
SimpleRecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 300
ResourceRecords:
- 93.184.216.34
Resources:
WeightedRecord1:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 300
SetIdentifier: "server1"
Weight: 70
ResourceRecords:
- 93.184.216.34
WeightedRecord2:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 300
SetIdentifier: "server2"
Weight: 30
ResourceRecords:
- 203.0.113.1
Resources:
LatencyRecord1:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 300
SetIdentifier: "us-east-1"
Region: us-east-1
ResourceRecords:
- 93.184.216.34
LatencyRecord2:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 300
SetIdentifier: "ap-northeast-1"
Region: ap-northeast-1
ResourceRecords:
- 203.0.113.1

フェイルオーバールーティング

Section titled “フェイルオーバールーティング”
Resources:
PrimaryRecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 300
SetIdentifier: "primary"
Failover: PRIMARY
HealthCheckId: !Ref HealthCheck
ResourceRecords:
- 93.184.216.34
SecondaryRecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 300
SetIdentifier: "secondary"
Failover: SECONDARY
ResourceRecords:
- 203.0.113.1
HealthCheck:
Type: AWS::Route53::HealthCheck
Properties:
HealthCheckConfig:
Type: HTTP
ResourcePath: /health
FullyQualifiedDomainName: www.example.com
RequestInterval: 30
FailureThreshold: 3
Resources:
GeoRecord1:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 300
SetIdentifier: "japan"
GeoLocation:
CountryCode: JP
ResourceRecords:
- 203.0.113.1
GeoRecord2:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 300
SetIdentifier: "us"
GeoLocation:
CountryCode: US
ResourceRecords:
- 93.184.216.34
Resources:
HealthCheck:
Type: AWS::Route53::HealthCheck
Properties:
HealthCheckConfig:
Type: HTTP
ResourcePath: /health
FullyQualifiedDomainName: www.example.com
Port: 80
RequestInterval: 30
FailureThreshold: 3
MeasureLatency: true
Regions:
- us-east-1
- us-west-2
- ap-northeast-1

プライベートホストゾーンのヘルスチェック

Section titled “プライベートホストゾーンのヘルスチェック”
Resources:
PrivateHealthCheck:
Type: AWS::Route53::HealthCheck
Properties:
HealthCheckConfig:
Type: HTTPS
ResourcePath: /health
FullyQualifiedDomainName: internal.example.com
Port: 443
RequestInterval: 30
FailureThreshold: 3
Inverted: false
EnableSNI: true

6. 実務でのベストプラクティス

Section titled “6. 実務でのベストプラクティス”

パターン1: ブルー/グリーンデプロイメント

Section titled “パターン1: ブルー/グリーンデプロイメント”
Resources:
BlueRecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 60
SetIdentifier: "blue"
Weight: 100
ResourceRecords:
- 93.184.216.34
GreenRecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 60
SetIdentifier: "green"
Weight: 0 # 最初は0、段階的に増やす
ResourceRecords:
- 203.0.113.1

パターン2: カナリアデプロイメント

Section titled “パターン2: カナリアデプロイメント”
Resources:
ProductionRecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 60
SetIdentifier: "production"
Weight: 90
ResourceRecords:
- 93.184.216.34
CanaryRecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref HostedZone
Name: www.example.com
Type: A
TTL: 60
SetIdentifier: "canary"
Weight: 10 # 10%のトラフィック
ResourceRecords:
- 203.0.113.1

原因:

  • TTLが長すぎる
  • キャッシュサーバーの問題

解決策:

Terminal window
# TTLを短く設定
aws route53 change-resource-record-sets \
--hosted-zone-id Z1234567890ABC \
--change-batch '{
"Changes": [{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "www.example.com",
"Type": "A",
"TTL": 60,
"ResourceRecords": [{"Value": "93.184.216.34"}]
}
}]
}'

問題2: フェイルオーバーが動作しない

Section titled “問題2: フェイルオーバーが動作しない”

原因:

  • ヘルスチェックが正しく設定されていない
  • ヘルスチェックの閾値が適切でない

解決策:

Terminal window
# ヘルスチェックの状態を確認
aws route53 get-health-check --health-check-id abc123
# ヘルスチェックの統計を確認
aws route53 get-health-check-status --health-check-id abc123

これで、Route 53の基礎知識と実務での使い方を理解できるようになりました。