LoginSignup
2
0

More than 3 years have passed since last update.

AWS Global AcceleratorでLoadbalancerのPublicIPを固定する

Posted at

非機能要件概要

  • 外部システムとデータ連携している時、外部システム側がDNS名ではなく、IPを指定した接続のみという非機能要件もあったりします。PublicIPを持つEC2 Instanceでリバースプロキシを作成したり、Network Loadbalancerを使用すればIPを指定した接続という要件は満たせます。しかしながらSSLアクセラレーション機能がなかったり、バックエンドサーバのInboundを0.0.0.0/0にしておく必要があったり、EC2に依存する設定が複数あります。
    また、Direct ConnectとVPC endpointを使用して外部システムと同じ閉域網で構築したりもします。
    ただし、使用するコンポーネントも多く、外部システムとの作業調整やデータ提供の可用性を高めるためのコストが高くなりがちです。
    また、Application LoadbalancerとClassic LoadbalancerにはPublicIPが2つ付きますが、このIPは動的でAWSの任意のタイミングやトラフィック需要によって変動します。そのため、IP変更されたことを検知するためにポーリングして変更を実施する仕組みが必要だったりします。

  • Global Acceleratorを使用すると、LoadBalancerのIPを実質的に固定することが可能になります。複雑になりがちな構成をシンプルにできます。

Global Accelerator?

  • Global Accerelator を使うと、Load Balancerや EC2 Instanceに対して2つの静的IPアドレスを関連付けることが可能になります。Global Accerelator がアプリケーションサーバのフロントエンドインターフェイスとして機能するため、アプリケーションサーバのIPアドレスを更新せずに、Blue Green deploymentが実行できます。

  • インターネットに接続された単一のアクセスポイントとして Global Accerelator を使用することで、AWSで実行しているアプリケーションサーバを分散サービス妨害 (DDoS) 攻撃から保護できます。
    Global Acceleratorは専用のVPCで稼働しています。VPC間のピア接続でShield Advancedが機能することで分散サービス妨害(DDoS)攻撃から保護されます。
    しかも、アプリケーションまでのホップ数が少ないNW経路を使用できるため、理論上はパフォーマンスが向上します。

イメージ

image.png

設定ファイル

下記は terraform での設定例です。

multiple_provider.tf
provider "aws" {
  region  = "ap-northeast-1"
  profile = "terraform-user01"
}

provider "aws" {
  region  = "us-west-2"
  alias   = "oregon"
  profile = "terraform-user02"
}
globalaccelerator_accelerator.tf
resource "aws_globalaccelerator_accelerator" "xxxxxxxxxx_accelerator" {
  provider        = aws.oregon
  name            = "xxxxxxxxxx"
  ip_address_type = "IPV4"
  enabled         = true

  attributes {
    flow_logs_enabled   = true
    flow_logs_s3_bucket = "xxxxxxxxxx"
    flow_logs_s3_prefix = "xxxxxxxxxx/"
  }
}
globalaccelerator_listener.tf
resource "aws_globalaccelerator_listener" "xxxxxxxxxx_listener" {
  provider        = aws.oregon
  accelerator_arn = aws_globalaccelerator_accelerator.xxxxxxxxxx_accelerator.id
  client_affinity = "SOURCE_IP"
  protocol        = "TCP"

  port_range {
    from_port = 80
    to_port   = 80
  }
}
globalaccelerator_endpoint_group.tf
resource "aws_globalaccelerator_endpoint_group" "xxxxxxxxxx_endpoint_group" {
  provider                      = aws.oregon
  endpoint_group_region         = "ap-northeast-1"
  health_check_interval_seconds = 30
  health_check_path             = "/"
  health_check_protocol         = "TCP"
  listener_arn                  = aws_globalaccelerator_listener.xxxxxxxxxx_listener.id
  threshold_count               = 3
  traffic_dial_percentage       = 100

  endpoint_configuration {
    endpoint_id = "arn:aws:elasticloadbalancing:ap-northeast-1:xxxxxxxxxx:loadbalancer/app/xxxxxxxxxx"
    weight      = 128
  }
}

確認

  • Global Accelerator作成前
    image.png

  • ターゲットにALBを指定したGlobal Accelerator作成後、以下の2IPが付与されました
    image.png

  • この2つの静的IPアドレスを任意のFQDNのAレコードとして定義すれば作業完了です。

料金

  • 固定料金: アクセラレーターが削除されるまで、アカウントでアクセラレーターが稼働している 1 時間 (1 時間未満は繰上げ) 毎に 0.025 USD 課金されます。
  • プレミアムデータ転送料金 (DT-Premium): AWS ネットワーク経由で転送されるデータのギガバイトあたりの料金です。

所感

  • クライアントから少ないホップ数でアプリケーションに到達できるというのはIPを固定する運用の副産物としのレイテンシ低減などはインパクトがありますが、月に$130くらいかかるので明細と相談しながら運用する必要があります。
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0