EC2 at the edge
EC2 at the edge runs EC2 instances at AWS’s edge locations, close to users, on a network you route yourself. It’s built for traffic-heavy workloads: serving large files, media relays, VPN and SD-WAN gateways, DDoS scrubbing. The instances are m8iden-edge instances on Dedicated Hosts.
EC2 at the edge is a gated preview, in Virginia, San Francisco, Dublin and Singapore. Until AWS grants your account access, EC2 rejects its calls. See Amazon EC2 at the edge.
Each instance is in two networks
Section titled “Each instance is in two networks”An edge instance has an interface in a subnet of your VPC, in a region, and an edge interface in a subnet of a virtual edge network at the edge location. The VPC carries the instance’s management traffic and its calls to AWS services. The virtual edge network carries the traffic the instance serves, out through its edge gateway to the internet, other clouds and AWS.
A virtual edge network is a secondary network of type virtual-edge: a network beside your VPCs, on separate infrastructure. A VPC’s security groups, network ACLs and flow logs don’t apply to it, and edge interfaces track no connections.
Allocate a host
Section titled “Allocate a host”Edge instances run only on Dedicated Hosts. Allocate one in the edge location’s zone:
const edgeZone = yield* Config.String("EDGE_ZONE");
const host = yield* AWS.EC2.DedicatedHost("Host", { availabilityZone: edgeZone, instanceFamily: "m8iden-edge",});Set EDGE_ZONE to the edge location’s zone. A host is billed while it’s allocated, whether or not instances run on it, so destroying it stops the charge.
Create the edge network
Section titled “Create the edge network”Create the virtual edge network in the same zone, then a subnet in it:
const edge = yield* AWS.EC2.SecondaryNetwork("Edge", { networkType: "virtual-edge", ipv4CidrBlock: "10.100.0.0/22", availabilityZone: edgeZone,});
const edgeSubnet = yield* AWS.EC2.SecondarySubnet("EdgeSubnet", { secondaryNetworkId: edge.secondaryNetworkId, ipv4CidrBlock: "10.100.0.0/24", availabilityZone: edgeZone,});A network’s block is between a /28 and a /12, and you can have five secondary networks per region. Only tags change in place: a new type, block or zone replaces the network or subnet.
Launch an instance into both
Section titled “Launch an instance into both”Place the instance on the host, give it a VPC subnet, and give it an edge interface with secondaryInterfaces:
const network = yield* AWS.EC2.Network("AppNetwork", { cidrBlock: "10.42.0.0/16" });
const server = yield* AWS.EC2.Instance("Server", { imageId: AWS.EC2.amazonLinux2023(), instanceType: "m8iden-edge.2xlarge", subnetId: network.publicSubnetIds[0], hostId: host.hostId, secondaryInterfaces: [{ secondarySubnetId: edgeSubnet.secondarySubnetId, networkCardIndex: 1 }],});The VPC interface stays on network card 0, and each edge interface gets a card of its own. An instance gets its edge interfaces at launch and keeps them, so changing secondaryInterfaces or hostId replaces the instance.
Route traffic to the internet
Section titled “Route traffic to the internet”The edge gateway is the network’s way out. A route table on the gateway decides where traffic goes, and associating it with the subnet applies it there:
const gateway = yield* AWS.EC2.VirtualEdgeGateway("EdgeGateway", { secondaryNetworkId: edge.secondaryNetworkId,});
const routes = yield* AWS.EC2.VirtualEdgeRouteTable("EdgeRoutes", { virtualEdgeGatewayId: gateway.virtualEdgeGatewayId, addressType: "ipv4",});
yield* AWS.EC2.VirtualEdgeRoute("DefaultRoute", { virtualEdgeRouteTableId: routes.virtualEdgeRouteTableId, ipv4DestinationCidrBlock: "0.0.0.0/0", targetType: "internet",});
yield* AWS.EC2.VirtualEdgeRouteTableAssociation("EdgeSubnetRoutes", { virtualEdgeRouteTableId: routes.virtualEdgeRouteTableId, secondarySubnetId: edgeSubnet.secondarySubnetId,});A route table holds one address family, so IPv6 gets a table of its own. A route’s other targets are subnet, for instances in a secondary subnet, and blackhole, which drops the traffic.
Announce your own addresses
Section titled “Announce your own addresses”Users reach your instances at addresses the gateway announces. First allow the gateway to announce a block, from an IPAM pool you brought, or one Amazon allocates:
const prefix = yield* AWS.EC2.VirtualEdgeAdvertisement("PublicPrefix", { virtualEdgeGatewayId: gateway.virtualEdgeGatewayId, ipv4NetmaskLength: 28,});Then route it to your instances, and say where to announce it:
yield* AWS.EC2.VirtualEdgeRoute("PublicPrefixRoute", { virtualEdgeRouteTableId: routes.virtualEdgeRouteTableId, ipv4DestinationCidrBlock: prefix.ipv4CidrBlock, targetType: "subnet", targets: [{ secondarySubnetId: edgeSubnet.secondarySubnetId, ipv4Address: "10.100.0.10" }], reachabilityScopes: ["internet"],});Traffic is balanced across the targets. Set a target’s weight to 0 to drain it. An allowed advertisement can’t change in place, and a new Amazon-allocated block is a different block.
Exchange routes over BGP
Section titled “Exchange routes over BGP”Instead of static routes, your instances can announce routes themselves over BGP. Each secondary subnet has two route server endpoints. Peer with both, so routing survives losing one:
for (const routeServerEndpoint of ["endpoint-1", "endpoint-2"] as const) { yield* AWS.EC2.VirtualEdgeRouteServerPeer(`Peer-${routeServerEndpoint}`, { secondarySubnetId: edgeSubnet.secondarySubnetId, routeServerEndpoint, amazonSideAsn: 64512, ipv4PeerAddressRange: "10.100.0.16/28", bgpOptions: { peerAsn: 65000 }, });}Routes your instances announce join the route table associated with their subnet. They’re announced beyond the gateway only when an allowed advertisement covers them. Set peerLivenessDetection: "bfd" in bgpOptions to detect a failed peer in under a second.
See the EC2 reference for every resource’s props.