I Tried Connecting Transit Gateway and Gateway Load Balancer Directly Using a Network Function Attachment

I Tried Connecting Transit Gateway and Gateway Load Balancer Directly Using a Network Function Attachment

With an AWS Transit Gateway network function attachment (Gateway Load Balancer type), I routed traffic through an appliance without creating subnets or route tables for GWLB endpoints. I also checked the context added to GENEVE packets.
2026.11.20

This page has been translated by machine translation. View original

Introduction

On November 17, 2026, the Transit Gateway network function attachment added support for the Gateway Load Balancer type.

https://aws.amazon.com/about-aws/whats-new/2026/11/transit-gateway-gwlb-integration/

With this attachment, you can connect a Transit Gateway (TGW) directly to a Gateway Load Balancer (GWLB) endpoint service. The TGW creates and manages the GWLB endpoint in the AZ you specify. In this article, I create an attachment in the same account, verify communication, and try context sharing.

Test Environment

  • Region: Tokyo (ap-northeast-1)
  • aws-cli: 2.41.1
  • Configuration: the TGW and the endpoint service are in the same account
  • Network Manager API: specify the home region, us-west-2

AZs are indicated by AZ ID. The mapping in this account is as follows.

AZ ID AZ name
apne1-az4 ap-northeast-1a
apne1-az1 ap-northeast-1c

The configuration is as follows.

Component Details
Inspection VPC 10.200.0.0/24. Two subnets for the GWLB (apne1-az4, apne1-az1) and one subnet for the appliance (apne1-az4). No subnet or route table is created for the GWLB endpoint. No VPC attachment to the TGW
spoke VPC A, B 10.201.0.0/24 and 10.202.0.0/24. Each is connected to the TGW with a VPC attachment
GWLB Cross-zone enabled. Target group uses GENEVE 6081, health check is TCP 8080
Endpoint service Acceptance not required
TGW Default route table association and propagation disabled. Encryption Support is disabled

Instead of a firewall product, I ran a Python script on EC2 that simply receives GENEVE packets and returns them.

Appliance specification and script
  • Records the headers (including options) of GENEVE packets received on UDP 6081 as JSON Lines
  • Returns the received packets to the GWLB as they are
  • Responds to health checks on TCP 8080
#!/usr/bin/env python3
import http.server, json, socket, threading, time

LOG = "/var/log/geneve-reflector.jsonl"

def parse(data):
    b0 = data[0]
    optlen = (b0 & 0x3F) * 4
    rec = {
        "ver": b0 >> 6,
        "opt_len_bytes": optlen,
        "flags": data[1],
        "proto": hex(int.from_bytes(data[2:4], "big")),
        "vni": int.from_bytes(data[4:7], "big"),
        "options_hex": data[8:8 + optlen].hex(),
        "tlvs": [],
    }
    opts = data[8:8 + optlen]
    i = 0
    while i + 4 <= len(opts):
        cls = int.from_bytes(opts[i:i + 2], "big")
        typ = opts[i + 2]
        ln = (opts[i + 3] & 0x1F) * 4
        rec["tlvs"].append({"class": hex(cls), "type": typ, "len": ln,
                            "data": opts[i + 4:i + 4 + ln].hex()})
        i += 4 + ln
    inner = data[8 + optlen:]
    if rec["proto"] == "0x800" and len(inner) >= 20:
        rec["inner"] = {"src": socket.inet_ntoa(inner[12:16]),
                        "dst": socket.inet_ntoa(inner[16:20]),
                        "ip_proto": inner[9]}
    return rec

class H(http.server.BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200); self.end_headers(); self.wfile.write(b"ok\n")
    def log_message(self, *a):
        pass

threading.Thread(target=lambda: http.server.HTTPServer(("0.0.0.0", 8080), H).serve_forever(),
                 daemon=True).start()

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("0.0.0.0", 6081))
with open(LOG, "a", buffering=1) as f:
    while True:
        data, addr = s.recvfrom(65535)
        try:
            rec = parse(data)
        except Exception as e:  # 解析できなくても転送は続ける
            rec = {"error": str(e)}
        rec["ts"] = time.strftime("%Y-%m-%dT%H:%M:%S%z")
        rec["from"] = "%s:%d" % addr
        rec["bytes"] = len(data)
        f.write(json.dumps(rec) + "\n")
        s.sendto(data, (addr[0], 6081))  # 宛先ポートは 6081 のまま返す(GWLB の送信元ポートへ返さない)

Creating the attachment

Creation and state transitions

The TGW's Encryption Support must be disabled. Specify the TGW ID, the service name of the endpoint service, and the AZ in which to create the GWLB endpoint.

aws ec2 create-transit-gateway-network-function-attachment \
  --transit-gateway-id <tgw-id> \
  --service-name <service-name> \
  --availability-zone-ids apne1-az4

I polled the state at 5 to 10 second intervals using the following command and recorded the point at which each state was first observed.

aws ec2 describe-transit-gateway-network-function-attachments \
  --transit-gateway-attachment-ids <attachment-id> \
  --query "TransitGatewayNetworkFunctionAttachments[0].State" --output text
Elapsed time since the create API call State
0 seconds initiatingRequest (response of the create API)
About 56 seconds pendingAcceptance
About 3 minutes 15 seconds pending
About 6 minutes 20 seconds available

The endpoint created by the TGW

The GWLB endpoint created by the TGW appears in the endpoint connections on the endpoint service side. Before the attachment was created, the endpoint connections were empty.

aws ec2 describe-vpc-endpoint-connections \
  --filters Name=service-id,Values=<vpce-svc-id>
{
    "VpcEndpointConnections": [
        {
            "ServiceId": "vpce-svc-0123456789abcdef0",
            "VpcEndpointState": "available",
            "CreationTimestamp": "2026-11-19T18:52:42.625000+00:00",
            "GatewayLoadBalancerArns": [
                "arn:aws:elasticloadbalancing:ap-northeast-1:111122223333:loadbalancer/gwy/tgwv-gwlb/1234567890abcdef"
            ],
            "IpAddressType": "ipv4",
            "VpcEndpointConnectionId": "vpce-con-0123456789abcdef0",
            "Tags": [],
            "VpcEndpointRegion": "ap-northeast-1",
            "TransitGatewayAttachmentId": "tgw-attach-0123456789abcdef0",
            "TransitGatewayAttachmentOwner": "111122223333"
        }
    ]
}

Before and after creating the attachment, I checked the number of subnets and route tables in the inspection VPC with the following commands. At both points, there were 3 subnets and 2 route tables.

aws ec2 describe-subnets --filters Name=vpc-id,Values=<inspection-vpc-id> \
  --query 'length(Subnets)'
aws ec2 describe-route-tables --filters Name=vpc-id,Values=<inspection-vpc-id> \
  --query 'length(RouteTables)'

Routing

TGW route tables

I created two TGW route tables: one for spokes (spoke-rt) and one for inspection (inspect-rt).

  • spoke-rt: Associate the attachments of spoke VPC A and B, and add a static route with destination 0.0.0.0/0 pointing to the network function attachment
  • inspect-rt: Associate the network function attachment, and propagate the routes of the spoke VPC A and B attachments
# spoke-rt と inspect-rt を作る
aws ec2 create-transit-gateway-route-table --transit-gateway-id <tgw-id>
aws ec2 create-transit-gateway-route-table --transit-gateway-id <tgw-id>

# 関連付け
aws ec2 associate-transit-gateway-route-table \
  --transit-gateway-route-table-id <spoke-rt-id> \
  --transit-gateway-attachment-id <spoke-a-attachment-id>
aws ec2 associate-transit-gateway-route-table \
  --transit-gateway-route-table-id <spoke-rt-id> \
  --transit-gateway-attachment-id <spoke-b-attachment-id>
aws ec2 associate-transit-gateway-route-table \
  --transit-gateway-route-table-id <inspect-rt-id> \
  --transit-gateway-attachment-id <nf-attachment-id>

# spoke のルートを inspect-rt へ伝播
aws ec2 enable-transit-gateway-route-table-propagation \
  --transit-gateway-route-table-id <inspect-rt-id> \
  --transit-gateway-attachment-id <spoke-a-attachment-id>
aws ec2 enable-transit-gateway-route-table-propagation \
  --transit-gateway-route-table-id <inspect-rt-id> \
  --transit-gateway-attachment-id <spoke-b-attachment-id>

# spoke-rt の 0.0.0.0/0 を network function attachment へ
aws ec2 create-transit-gateway-route \
  --transit-gateway-route-table-id <spoke-rt-id> \
  --destination-cidr-block 0.0.0.0/0 \
  --transit-gateway-attachment-id <nf-attachment-id>

In the response of the API that created the static route, the ResourceType of the network function attachment is network-function.

{
    "Route": {
        "DestinationCidrBlock": "0.0.0.0/0",
        "TransitGatewayAttachments": [
            {
                "ResourceId": "com.amazonaws.vpce.ap-northeast-1.vpce-svc-0123456789abcdef0",
                "TransitGatewayAttachmentId": "tgw-attach-0123456789abcdef0",
                "ResourceType": "network-function"
            }
        ],
        "Type": "static",
        "State": "active"
    }
}

The CIDRs of spoke VPC A (10.201.0.0/24) and B (10.202.0.0/24) were registered in inspect-rt. These are propagated routes (Type is propagated). In the route tables on the spoke VPC side, I placed routes pointing the other VPC's CIDR to the TGW.

aws ec2 create-route --route-table-id <spoke-a-vpc-rtb-id> \
  --destination-cidr-block 10.202.0.0/24 --transit-gateway-id <tgw-id>
aws ec2 create-route --route-table-id <spoke-b-vpc-rtb-id> \
  --destination-cidr-block 10.201.0.0/24 --transit-gateway-id <tgw-id>

Verifying communication

After the TGW route table associations became associated, I ran ping -c 3 -W 2 <peer IP> from the spoke EC2 instances. Three round trips succeeded in both directions, A to B and B to A.

# spoke A(10.201.0.10)から B へ
--- 10.202.0.9 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms

# spoke B(10.202.0.9)から A へ
--- 10.201.0.10 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms

I confirmed that the traffic passed through the appliance from the appliance's log. During the 3 round-trip ping from A to B, the appliance received 6 GENEVE packets. The breakdown of the inner IP packets was 3 requests from 10.201.0.10 to 10.202.0.9 and 3 replies from 10.202.0.9 to 10.201.0.10. The outer source IP address was 10.200.0.10 (an IP in the GWLB subnet) in every case.

Context sharing

Creating a context store

A context is information representing the VPC, subnet, security group, and attachment of the traffic source. To share context, you create a global network in Network Manager, register the TGW, create a context store, and associate it with the TGW.

aws networkmanager create-global-network --region us-west-2

aws networkmanager register-transit-gateway --region us-west-2 \
  --global-network-id <global-network-id> \
  --transit-gateway-arn <tgw-arn>

aws networkmanager create-context-store --region us-west-2 \
  --global-network-id <global-network-id>

aws networkmanager associate-context-store --region us-west-2 \
  --context-store-id <context-store-id> \
  --transit-gateway-arn <tgw-arn>

The association went from ASSOCIATING to ASSOCIATED in about 5 minutes.

Output of list-contexts

After the association, I retrieved the contexts with list-contexts.

aws networkmanager list-contexts --region us-west-2 \
  --context-store-id <context-store-id>

This time, 22 records were returned. What was registered were the spoke-side VPCs, subnets, security groups, and VPC attachments, plus the network function attachment and its endpoint service name. Among the ContextTypes, SegmentId corresponds to the security group, and ResourceId corresponds to the VPC and the network function service name.

Context attached to GENEVE packets

After the association, I ran ping -c 2 from A to B and from B to A, and read the capture obtained on the appliance with tcpdump -r <pcap> -nn -vv. The following are the lines for the outer part (UDP and GENEVE options) and the inner part (ICMP) of the first request packet.

    10.200.0.10.60462 > 10.200.0.21.6081: [udp sum ok] Geneve, Flags [none], vni 0x0, options [class Unknown (0x108) type 0x16 len 28 data 12345678 9abcdef0 08a10010 a00018a0 0008a000 010008a0, class Unknown (0x108) type 0x1 len 12 data 349e29e1 7e57216f, class Unknown (0x108) type 0x2 len 12 data 00000000 00000000, class Unknown (0x108) type 0x3 len 8 data 7c636988]
    10.201.0.10 > 10.202.0.9: ICMP echo request, id 61081, seq 1, length 64

Before the association, there were four class 0x108 TLVs (type 0x15, 0x1, 0x2, 0x3), and the option length was 44 bytes. After the association, type 0x15 (8 bytes of data) was replaced by type 0x16 (24 bytes of data), and the option length became 60 bytes. tcpdump 4.99.1 does not interpret these options and displays them as class Unknown (0x108).

The following table shows the result of matching the 24 bytes of type 0x16 data against the ContextIds from list-contexts for both directions, A to B and B to A. There is one security group per spoke VPC. I could not find a public specification of the byte layout, so the layout is inferred from measurements.

Byte position Item Packet from A to B Packet from B to A
0–7 Lower 16 digits of the context store ID context-store-0123456789abcdef0 Same
8–9 Unknown purpose 08a1 08a1
10–12 Attachment 0010a0 → tgw-attach-0a1b2c3d4e5f67890 (spoke A) 0018a0 → tgw-attach-0f9e8d7c6b5a43210 (spoke B)
13–15 VPC 0018a0 → vpc-0aaaa1111bbbb2222 (spoke A) 0010a0 → vpc-0cccc3333dddd4444 (spoke B)
16–18 Subnet 0008a0 → subnet-0111122223333aaaa (spoke A) 0010a0 → subnet-0444455556666bbbb (spoke B)
19–20 AZ 0001 → apne1-az4 0001 → apne1-az4
21–23 Security group 0008a0 → sg-0aaaa0000bbbb1111 (spoke A) 0010a0 → sg-0cccc2222dddd3333 (spoke B)

In both directions, the ContextIds of the attachment, VPC, subnet, AZ, and security group matched the source resources. Only the source context was included. For the AZ, the lower byte of the two bytes is matched as the ContextId of AvailabilityZone.

For the matching, I used the following script. Save it as resolve-context.py and pass the output JSON of list-contexts and the appliance log (geneve-reflector.jsonl) as arguments.

python3 resolve-context.py <list-contexts の JSON> <geneve-reflector.jsonl>
resolve-context.py
#!/usr/bin/env python3
"""アプライアンスが受けた GENEVE オプション(class 0x0108, type 0x16)の ContextId を、
list-contexts の出力と照合して、リソースの名前に解決する。

使い方: resolve-context.py <list-contexts の JSON> <geneve-reflector.jsonl>

バイト配置は公開仕様が見当たらないため、実測から推定したもの:
  type 0x16 の data は 24 バイト
    [0:8]   コンテキストストア ID の下位 16 桁(context-store-0 + 16 桁)
    [8:10]  不明(2 バイト。観測では 08 a1 で固定)
    [10:13] 送信元の attachment の ContextId(3 バイト)
    [13:16] 送信元の VPC の ContextId
    [16:19] 送信元の subnet の ContextId
    [19:21] 送信元の AZ の ContextId(2 バイト)
    [21:24] 送信元のセキュリティグループの ContextId
subnet と SG の ContextId は、この環境では値が同じため、2 つの位置の取り違えは区別できない。
"""
import json
import sys

def load_json(path):
    text = open(path).read()
    start = text.index("{")
    end = text.rindex("}") + 1
    return json.loads(text[start:end])

def load_lines(path):
    out = []
    for line in open(path):
        line = line.strip()
        if line.startswith("{"):
            out.append(json.loads(line))
    return out

ctx = load_json(sys.argv[1])["Contexts"]
by = {}
for c in ctx:
    by.setdefault((c["ContextType"], c["ContextId"]), []).append(c)

def name(ctype, cid):
    hits = by.get((ctype, cid), [])
    return [h["PublicId"] for h in hits] or ["(not found)"]

seen = set()
for rec in load_lines(sys.argv[2]):
    for t in rec["tlvs"]:
        if t["type"] != 22:
            continue
        d = bytes.fromhex(t["data"])
        key = (rec["inner"]["src"], t["data"])
        if key in seen:
            continue
        seen.add(key)
        att, vpc, sub = d[10:13].hex(), d[13:16].hex(), d[16:19].hex()
        az, sg = d[19:21].hex(), d[21:24].hex()
        print("inner src %s -> dst %s" % (rec["inner"]["src"], rec["inner"]["dst"]))
        print("  context store : context-store-0%s" % d[0:8].hex())
        print("  attachment %s: %s" % (att, name("Attachment", att)))
        print("  vpc        %s: %s" % (vpc, name("ResourceId", vpc)))
        print("  subnet     %s: %s" % (sub, name("Subnet", sub)))
        print("  az         %s: %s" % (az, name("AvailabilityZone", az[-2:])))
        print("  sg         %s: %s" % (sg, name("SegmentId", sg)))

Summary

The network function attachment now supports the GWLB type, so the TGW can connect directly to the GWLB endpoint service placed in front of a firewall or similar appliance.

If managing the inspection VPC, especially maintaining the subnets and route tables for GWLB endpoints, is a burden, give this update a try.

Share this article

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