Route 53完全ガイド
Route 53完全ガイド
Section titled “Route 53完全ガイド”Route 53は、AWSのDNSサービスです。実務で使えるDNS設定とトラフィックルーティングを詳しく解説します。
1. Route 53とは
Section titled “1. Route 53とは”Route 53の役割
Section titled “Route 53の役割”Route 53は、ドメイン名をIPアドレスに変換するDNSサービスです。また、トラフィックルーティング機能も提供します。
ユーザー ↓(ドメイン名でアクセス)Route 53(DNS解決) ↓(IPアドレスを返す)EC2インスタンス、ALBなどなぜRoute 53が必要か
Section titled “なぜRoute 53が必要か”問題のある構成(外部DNSプロバイダー):
# 問題: 外部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. コスト効率2. ホストゾーン
Section titled “2. ホストゾーン”ホストゾーンとは
Section titled “ホストゾーンとは”ホストゾーンは、ドメインのDNSレコードを管理するコンテナです。
# ホストゾーンの作成aws route53 create-hosted-zone \ --name example.com \ --caller-reference $(date +%s)
# ホストゾーンの一覧表示aws route53 list-hosted-zones
# ネームサーバーの確認aws route53 get-hosted-zone --id Z1234567890ABC3. DNSレコードタイプ
Section titled “3. DNSレコードタイプ”Resources: ARecord: Type: AWS::Route53::RecordSet Properties: HostedZoneId: !Ref HostedZone Name: www.example.com Type: A TTL: 300 ResourceRecords: - 93.184.216.34AAAAレコード(IPv6)
Section titled “AAAAレコード(IPv6)”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:1946CNAMEレコード
Section titled “CNAMEレコード”Resources: CNAMERecord: Type: AWS::Route53::RecordSet Properties: HostedZoneId: !Ref HostedZone Name: blog.example.com Type: CNAME TTL: 300 ResourceRecords: - example-blog.comALIASレコード
Section titled “ALIASレコード”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: true4. トラフィックルーティング
Section titled “4. トラフィックルーティング”シンプルルーティング
Section titled “シンプルルーティング”Resources: SimpleRecord: Type: AWS::Route53::RecordSet Properties: HostedZoneId: !Ref HostedZone Name: www.example.com Type: A TTL: 300 ResourceRecords: - 93.184.216.34加重ルーティング
Section titled “加重ルーティング”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レイテンシールーティング
Section titled “レイテンシールーティング”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地理的位置ルーティング
Section titled “地理的位置ルーティング”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.345. ヘルスチェック
Section titled “5. ヘルスチェック”ヘルスチェックの設定
Section titled “ヘルスチェックの設定”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: true6. 実務でのベストプラクティス
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.17. よくある問題と解決策
Section titled “7. よくある問題と解決策”問題1: DNS解決が遅い
Section titled “問題1: DNS解決が遅い”原因:
- TTLが長すぎる
- キャッシュサーバーの問題
解決策:
# 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: フェイルオーバーが動作しない”原因:
- ヘルスチェックが正しく設定されていない
- ヘルスチェックの閾値が適切でない
解決策:
# ヘルスチェックの状態を確認aws route53 get-health-check --health-check-id abc123
# ヘルスチェックの統計を確認aws route53 get-health-check-status --health-check-id abc123これで、Route 53の基礎知識と実務での使い方を理解できるようになりました。