Elastic Load Balancing for Envoy(internal)を VPC 内のリバースプロキシとして使ってみた

Elastic Load Balancing for Envoy(internal)を VPC 内のリバースプロキシとして使ってみた

`"ipv4Addressability": "internal"` で作成した ELB for Envoy に、VPC 内のクライアント EC2 からリクエストを送ると、Envoy の設定に書いたパスに応じて 2 つの内部 ALB へ振り分けられました。
2026.11.26

はじめに

2026年11月25日、Elastic Load Balancing for Envoy(ELB for Envoy)の一般提供が発表されました。

https://aws.amazon.com/about-aws/whats-new/2026/11/elastic-load-balancing-for-envoy-generally-available/

ELB for Envoy の基本的な機能については先行記事で紹介しています。

https://dev.classmethod.jp/articles/aws-elb-for-envoy-ga-create-proxy/

今回は、Envoy を VPC 内のリバースプロキシとして利用する想定で、internal で作成したプロキシから、サービスに見立てた 2 つの内部 ALB へ、パスに応じてリクエストを振り分けた結果を紹介します。

検証環境

  • リージョン:東京(ap-northeast-1)
  • aws-cli:2.42.4
  • Envoy のバージョン(proxyVersion):1.40
  • サブネット:デフォルト VPC の ap-northeast-1a と ap-northeast-1c
  • クライアント EC2:t4g.nano(Amazon Linux 2023)
  • 動作確認のコマンドの実行:AWS Systems Manager の Run Command
  • クライアント EC2 の IAM ロール:AmazonSSMManagedInstanceCore ポリシーを付与

前提リソース

プロキシの作成には、同じ VPC で異なる AZ にある 2 つ以上のサブネット、1 つ以上のセキュリティグループ(SG)、プロキシ用の IAM ロールが必要です。ロールの作成手順は公式ドキュメントにあります。

https://docs.aws.amazon.com/elasticloadbalancing/latest/elbproxy/setting-up.html

セキュリティグループ

SG は、クライアント用、プロキシ用、ALB 用の 3 つを作成しました。

SG 付与先 インバウンド
クライアント用 クライアント EC2 なし
プロキシ用 ELB for Envoy のプロキシ TCP 80 をクライアント用 SG から許可
ALB 用 2 つの内部 ALB TCP 80 をプロキシ用 SG から許可

SG の作成後、次の 2 つのコマンドで、SG 同士を参照する許可ルールを設定しました。

aws ec2 authorize-security-group-ingress --group-id <proxy-sg-id> --protocol tcp --port 80 --source-group <client-sg-id> --output json
aws ec2 authorize-security-group-ingress --group-id <alb-sg-id> --protocol tcp --port 80 --source-group <proxy-sg-id> --output json

内部 ALB

サービスに見立てた内部 ALB を 2 つ(service-a、service-b)作成しました。どちらも Scheme は internal で、ap-northeast-1a と ap-northeast-1c の 2 サブネットに配置しました。HTTP 80 のリスナーの既定アクションには、固定応答(ステータス 200、本文はそれぞれ service-a、service-b)を設定しました。

SG、ALB、リスナーの作成コマンドは次のとおりです。

SG・ALB・リスナーの作成コマンド

SG(クライアント用、プロキシ用、ALB 用)

aws ec2 create-security-group --group-name elbproxy-vpc-client --description "ELB for Envoy VPC routing client" --vpc-id <vpc-id> --query GroupId --output text
aws ec2 create-security-group --group-name elbproxy-vpc-proxy --description "ELB for Envoy VPC routing proxy" --vpc-id <vpc-id> --query GroupId --output text
aws ec2 create-security-group --group-name elbproxy-vpc-alb --description "ELB for Envoy VPC routing alb" --vpc-id <vpc-id> --query GroupId --output text

内部 ALB(service-a、service-b)

aws elbv2 create-load-balancer --name elbproxy-vpc-service-a --scheme internal --type application --ip-address-type ipv4 --subnets <subnet-a-id> <subnet-c-id> --security-groups <alb-sg-id> --output json
aws elbv2 create-load-balancer --name elbproxy-vpc-service-b --scheme internal --type application --ip-address-type ipv4 --subnets <subnet-a-id> <subnet-c-id> --security-groups <alb-sg-id> --output json

リスナー(HTTP 80、固定応答)

aws elbv2 create-listener --load-balancer-arn <alb-a-arn> --protocol HTTP --port 80 --default-actions "Type=fixed-response,FixedResponseConfig={StatusCode=200,ContentType=text/plain,MessageBody=service-a}" --output json
aws elbv2 create-listener --load-balancer-arn <alb-b-arn> --protocol HTTP --port 80 --default-actions "Type=fixed-response,FixedResponseConfig={StatusCode=200,ContentType=text/plain,MessageBody=service-b}" --output json

Envoy の設定に ALB の DNS 名を書くため、ALB を先に作成し、どちらも active になったことを確認してからプロキシを作成しました。

プロキシの作成

Envoy 設定ファイル

次の内容を config-01-path-routing.yaml として保存します。リクエストは、パスが /a/ で始まれば service_a クラスターへ、/b/ で始まれば service_b クラスターへ転送します。パスがどちらにも一致しないリクエストには、ステータス 404 と本文 no route を直接返します。クラスターは STRICT_DNS で、転送先に ALB の DNS 名とポート 80 を指定します。

admin:
  address:
    socket_address:
      address: 127.0.0.1
      port_value: 9901
static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address:
        address: 0.0.0.0
        port_value: 80
    filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          stat_prefix: ingress_http
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: ["*"]
              routes:
              - match:
                  prefix: "/a/"
                route:
                  cluster: service_a
                  auto_host_rewrite: true
              - match:
                  prefix: "/b/"
                route:
                  cluster: service_b
                  auto_host_rewrite: true
              - match:
                  prefix: "/"
                direct_response:
                  status: 404
                  body:
                    inline_string: "no route\n"
          http_filters:
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  clusters:
  - name: service_a
    type: STRICT_DNS
    dns_lookup_family: V4_ONLY
    connect_timeout: 5s
    load_assignment:
      cluster_name: service_a
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: <alb-a-dns-name>
                port_value: 80
  - name: service_b
    type: STRICT_DNS
    dns_lookup_family: V4_ONLY
    connect_timeout: 5s
    load_assignment:
      cluster_name: service_b
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: <alb-b-dns-name>
                port_value: 80

プロキシの作成コマンド

create-proxy に渡す入力は、次の内容で create-proxy-input.json に保存します。

{
  "name": "vpc-routing-proxy",
  "type": "envoy",
  "proxyVersion": "1.40",
  "roleArn": "arn:aws:iam::123456789012:role/aws-elb-proxy-role",
  "networkConfiguration": {
    "ipConfiguration": {
      "ipAddressingConfiguration": {
        "ipv4Addressability": "internal",
        "ipv6Addressability": "off"
      }
    },
    "vpcConfiguration": {
      "subnets": [ { "subnetId": "<subnet-a-id>" }, { "subnetId": "<subnet-c-id>" } ],
      "securityGroups": [ { "securityGroupId": "<proxy-sg-id>" } ]
    }
  }
}

2 つのファイルを同じディレクトリに置き、そのディレクトリで次のコマンドを実行します。

aws elb-proxy create-proxy --cli-input-json file://create-proxy-input.json --cli-binary-format raw-in-base64-out --configuration 'configurationFile={configurationBytes@=file://config-01-path-routing.yaml}' --output json

作成したプロキシの dnsName は internal-vpc-routing-proxy-<ID>.elb-proxy.ap-northeast-1.on.aws です。status は約 2 分で create-in-progress から active になりました。

動作確認

クライアント EC2 でプロキシの DNS 名を引くと、2 つのプライベート IP に解決されました。

$ getent ahostsv4 <proxy-dns-name> | awk '{print $1}' | sort -u
172.31.x.x
172.31.x.x

続いて、3 つのパスへ curl でリクエストを送りました。

$ curl -sS -m 10 -w '\nHTTP %{http_code}\n' http://<proxy-dns-name>/a/hello
service-a
HTTP 200
$ curl -sS -m 10 -w '\nHTTP %{http_code}\n' http://<proxy-dns-name>/b/hello
service-b
HTTP 200
$ curl -sS -m 10 -w '\nHTTP %{http_code}\n' http://<proxy-dns-name>/c/hello
no route

HTTP 404

service-a と service-b は各 ALB が返した固定応答の本文、no route は Envoy が direct_response で返した本文です。

まとめ

internal で作成した ELB for Envoy を、VPC 内のリバースプロキシとして利用できることを確認しました。

従来も、内部 ALB の IP ターゲットで VPC 内のリソースを利用できましたが、ターゲットには固定の IP アドレスが必要でした。ALB のように IP アドレスが変わる仕組みを利用するには、NLB などで固定の IP アドレスを確保する必要がありました。ELB for Envoy では転送先を DNS 名で指定できるので、より柔軟に利用できる可能性があります。

また、ECS のタスクや EKS の Pod で Envoy や Nginx を動かしてサービスのエンドポイントを提供していた場合、実行環境のメンテナンスに伴う入れ替えが難しくなることがありました。このエンドポイントを ELB for Envoy にオフロードできれば、システムの可搬性や柔軟性を高められる可能性があります。

サービス公開のハブとして Envoy を利用している場合は、マネージドサービスとして利用できるようになった ELB for Envoy をお試しください。

この記事をシェアする

AWSのお困り事はクラスメソッドへ

関連記事