feat(ec2): support instance and network-interface route targets (#4416)

Support InstanceId and NetworkInterfaceId in CreateRoute, ReplaceRoute,
and DescribeRouteTables, automatically resolving InstanceOwnerId.

- Parse and store InstanceId and NetworkInterfaceId on Route
- Validate instance target existence and set InstanceOwnerId to caller account
- Enforce single-target mutual exclusion across all supported route targets
- Remove InstanceId and NetworkInterfaceId from UNSUPPORTED_ROUTE_TARGETS
- Render instanceId, instanceOwnerId, and networkInterfaceId in DescribeRouteTables
- Add DescribeRouteTables filter support for route.instance-id and route.network-interface-id
- Document route target support in docs/services/ec2.md
- Add integration tests in Ec2RouteTargetIntegrationTest
- Add AWS SDK compatibility tests in Ec2RouteTargetTest
This commit is contained in:
Simone Primarosa authored and GitHub committed 2026-09-27 09:18:29 -04:00
1 parent 228086ddb3
commit 70c1c407bc
6 files changed
+714 -115

No files matched your search

@@ -32,8 +32,8 @@ public class Ec2QueryHandler {
/** ReplaceRoute targets AWS accepts that a stored {@code Route} cannot represent here. */
private static final List<String> UNSUPPORTED_ROUTE_TARGETS = List.of(
"CarrierGatewayId", "CoreNetworkArn", "EgressOnlyInternetGatewayId", "InstanceId",
"LocalGatewayId", "NetworkInterfaceId", "OdbNetworkArn",
"CarrierGatewayId", "CoreNetworkArn", "EgressOnlyInternetGatewayId",
"LocalGatewayId", "OdbNetworkArn",
"TransitGatewayId", "VpcEndpointId");
/** The gateway id a route table's built-in route carries (see Ec2Service#createRouteTable). */
@@ -3644,7 +3644,10 @@ public class Ec2QueryHandler {
// egress route is not silently rewritten into a targetless one.
String eigwId = p.getFirst("EgressOnlyInternetGatewayId");
String pcxId = p.getFirst("VpcPeeringConnectionId");
service.createRoute(region, rtId, dest, destIpv6, destPrefixList, gwId, natGwId, eigwId, pcxId);
String instanceId = p.getFirst("InstanceId");
String networkInterfaceId = p.getFirst("NetworkInterfaceId");
service.createRoute(region, rtId, dest, destIpv6, destPrefixList, gwId, natGwId, eigwId, pcxId,
instanceId, networkInterfaceId);
return booleanResponse("CreateRoute");
}
@@ -3665,16 +3668,19 @@ public class Ec2QueryHandler {
String gwId = p.getFirst("GatewayId");
String natGwId = p.getFirst("NatGatewayId");
String pcxId = p.getFirst("VpcPeeringConnectionId");
String instanceId = p.getFirst("InstanceId");
String networkInterfaceId = p.getFirst("NetworkInterfaceId");
// Resetting a route to the local target is expressible: `local` is the gateway id the
// route table's built-in route already carries, so it needs no new field on Route.
if (Boolean.parseBoolean(p.getFirst("LocalTarget"))) {
if (gwId != null || natGwId != null || pcxId != null) {
if (gwId != null || natGwId != null || pcxId != null || instanceId != null || networkInterfaceId != null) {
throw new AwsException("InvalidParameterCombination",
"ReplaceRoute takes exactly one target.", 400);
}
gwId = LOCAL_GATEWAY_ID;
}
service.replaceRoute(region, rtId, dest, destIpv6, destPrefixList, gwId, natGwId, pcxId,
instanceId, networkInterfaceId,
Boolean.parseBoolean(p.getFirst("DryRun")));
return booleanResponse("ReplaceRoute");
}
@@ -4733,7 +4739,10 @@ public class Ec2QueryHandler {
.elem("destinationIpv6CidrBlock", r.getDestinationIpv6CidrBlock())
.elem("destinationPrefixListId", r.getDestinationPrefixListId())
.elem("gatewayId", r.getGatewayId())
.elem("instanceId", r.getInstanceId())
.elem("instanceOwnerId", r.getInstanceOwnerId())
.elem("natGatewayId", r.getNatGatewayId())
.elem("networkInterfaceId", r.getNetworkInterfaceId())
.elem("egressOnlyInternetGatewayId", r.getEgressOnlyInternetGatewayId())
.elem("vpcPeeringConnectionId", r.getVpcPeeringConnectionId())
.elem("state", r.getState())
@@ -1,5 +1,99 @@
package io.github.hectorvent.floci.services.ec2;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsPartition;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.CidrCanonicalizer;
import io.github.hectorvent.floci.core.common.ContainerTeardown;
import io.github.hectorvent.floci.core.common.RequestContext;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.github.hectorvent.floci.core.resource.ExplorerResource;
import io.github.hectorvent.floci.core.resource.ResourceProvider;
import io.github.hectorvent.floci.core.resource.SupportedResourceType;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ec2.model.Address;
import io.github.hectorvent.floci.services.ec2.model.BlockDeviceMapping;
import io.github.hectorvent.floci.services.ec2.model.CapacityReservation;
import io.github.hectorvent.floci.services.ec2.model.EbsBlockDevice;
import io.github.hectorvent.floci.services.ec2.model.GroupIdentifier;
import io.github.hectorvent.floci.services.ec2.model.IamInstanceProfileAssociation;
import io.github.hectorvent.floci.services.ec2.model.Image;
import io.github.hectorvent.floci.services.ec2.model.Instance;
import io.github.hectorvent.floci.services.ec2.model.InstanceCreditSpecification;
import io.github.hectorvent.floci.services.ec2.model.InstanceCreditSpecificationListResult;
import io.github.hectorvent.floci.services.ec2.model.InstanceNetworkInterface;
import io.github.hectorvent.floci.services.ec2.model.InstanceState;
import io.github.hectorvent.floci.services.ec2.model.InternetGateway;
import io.github.hectorvent.floci.services.ec2.model.InternetGatewayAttachment;
import io.github.hectorvent.floci.services.ec2.model.IpPermission;
import io.github.hectorvent.floci.services.ec2.model.IpRange;
import io.github.hectorvent.floci.services.ec2.model.Ipv6Range;
import io.github.hectorvent.floci.services.ec2.model.KeyPair;
import io.github.hectorvent.floci.services.ec2.model.LaunchSpecification;
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplate;
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplateData;
import io.github.hectorvent.floci.services.ec2.model.ManagedPrefixList;
import io.github.hectorvent.floci.services.ec2.model.NatGateway;
import io.github.hectorvent.floci.services.ec2.model.NatGatewayAddress;
import io.github.hectorvent.floci.services.ec2.model.NetworkAcl;
import io.github.hectorvent.floci.services.ec2.model.NetworkAclAssociation;
import io.github.hectorvent.floci.services.ec2.model.NetworkAclEntry;
import io.github.hectorvent.floci.services.ec2.model.NetworkInterface;
import io.github.hectorvent.floci.services.ec2.model.NetworkInterfaceAssociation;
import io.github.hectorvent.floci.services.ec2.model.NetworkInterfaceAttachment;
import io.github.hectorvent.floci.services.ec2.model.NetworkInterfaceListResult;
import io.github.hectorvent.floci.services.ec2.model.NetworkInterfacePrivateIpAddress;
import io.github.hectorvent.floci.services.ec2.model.Placement;
import io.github.hectorvent.floci.services.ec2.model.PrefixList;
import io.github.hectorvent.floci.services.ec2.model.PrefixListEntry;
import io.github.hectorvent.floci.services.ec2.model.PrefixListId;
import io.github.hectorvent.floci.services.ec2.model.ReferencedSecurityGroup;
import io.github.hectorvent.floci.services.ec2.model.Reservation;
import io.github.hectorvent.floci.services.ec2.model.Route;
import io.github.hectorvent.floci.services.ec2.model.RouteTable;
import io.github.hectorvent.floci.services.ec2.model.RouteTableAssociation;
import io.github.hectorvent.floci.services.ec2.model.SecurityGroup;
import io.github.hectorvent.floci.services.ec2.model.SecurityGroupRule;
import io.github.hectorvent.floci.services.ec2.model.Snapshot;
import io.github.hectorvent.floci.services.ec2.model.SpotInstanceRequest;
import io.github.hectorvent.floci.services.ec2.model.Subnet;
import io.github.hectorvent.floci.services.ec2.model.Tag;
import io.github.hectorvent.floci.services.ec2.model.TransitGateway;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayOptions;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayRoute;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayRouteTable;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayRouteTablePropagation;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayVpcAttachment;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayVpcAttachmentOptions;
import io.github.hectorvent.floci.services.ec2.model.UserIdGroupPair;
import io.github.hectorvent.floci.services.ec2.model.Volume;
import io.github.hectorvent.floci.services.ec2.model.VolumeAttachment;
import io.github.hectorvent.floci.services.ec2.model.VolumeModification;
import io.github.hectorvent.floci.services.ec2.model.Vpc;
import io.github.hectorvent.floci.services.ec2.model.VpcCidrBlockAssociation;
import io.github.hectorvent.floci.services.ec2.model.VpcEndpoint;
import io.github.hectorvent.floci.services.ec2.model.VpcEndpointDnsEntry;
import io.github.hectorvent.floci.services.ec2.model.VpcEndpointSubnetConfiguration;
import io.github.hectorvent.floci.services.ec2.model.VpcIpv6CidrBlockAssociation;
import io.github.hectorvent.floci.services.ec2.model.VpcPeeringConnection;
import io.github.hectorvent.floci.services.ec2.model.VpcPeeringConnectionStateReason;
import io.github.hectorvent.floci.services.ec2.model.VpcPeeringConnectionVpcInfo;
import io.github.hectorvent.floci.services.ec2.net.VpcNetworkManager;
import io.github.hectorvent.floci.services.ec2.portforward.Ec2PortForwardManager;
import io.github.hectorvent.floci.services.iam.IamService;
import io.github.hectorvent.floci.services.iam.model.InstanceProfile;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.ContextNotActiveException;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
@@ -28,101 +122,6 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.jboss.logging.Logger;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.RequestContext;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsPartition;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.CidrCanonicalizer;
import io.github.hectorvent.floci.core.common.ContainerTeardown;
import io.github.hectorvent.floci.core.resource.ExplorerResource;
import io.github.hectorvent.floci.core.resource.ResourceProvider;
import io.github.hectorvent.floci.core.resource.SupportedResourceType;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ec2.model.Address;
import io.github.hectorvent.floci.services.ec2.model.BlockDeviceMapping;
import io.github.hectorvent.floci.services.ec2.model.CapacityReservation;
import io.github.hectorvent.floci.services.ec2.model.EbsBlockDevice;
import io.github.hectorvent.floci.services.ec2.model.GroupIdentifier;
import io.github.hectorvent.floci.services.ec2.model.IamInstanceProfileAssociation;
import io.github.hectorvent.floci.services.ec2.net.VpcNetworkManager;
import io.github.hectorvent.floci.services.ec2.portforward.Ec2PortForwardManager;
import io.github.hectorvent.floci.services.ec2.model.Image;
import io.github.hectorvent.floci.services.ec2.model.Instance;
import io.github.hectorvent.floci.services.ec2.model.InstanceCreditSpecification;
import io.github.hectorvent.floci.services.ec2.model.InstanceCreditSpecificationListResult;
import io.github.hectorvent.floci.services.ec2.model.InstanceNetworkInterface;
import io.github.hectorvent.floci.services.ec2.model.InstanceState;
import io.github.hectorvent.floci.services.ec2.model.NetworkInterface;
import io.github.hectorvent.floci.services.ec2.model.NetworkInterfaceAssociation;
import io.github.hectorvent.floci.services.ec2.model.NetworkInterfaceAttachment;
import io.github.hectorvent.floci.services.ec2.model.NetworkInterfaceListResult;
import io.github.hectorvent.floci.services.ec2.model.NetworkInterfacePrivateIpAddress;
import io.github.hectorvent.floci.services.ec2.model.InternetGateway;
import io.github.hectorvent.floci.services.ec2.model.InternetGatewayAttachment;
import io.github.hectorvent.floci.services.ec2.model.IpPermission;
import io.github.hectorvent.floci.services.ec2.model.IpRange;
import io.github.hectorvent.floci.services.ec2.model.Ipv6Range;
import io.github.hectorvent.floci.services.ec2.model.KeyPair;
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplate;
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplateData;
import io.github.hectorvent.floci.services.ec2.model.ManagedPrefixList;
import io.github.hectorvent.floci.services.ec2.model.NatGateway;
import io.github.hectorvent.floci.services.ec2.model.NatGatewayAddress;
import io.github.hectorvent.floci.services.ec2.model.NetworkAcl;
import io.github.hectorvent.floci.services.ec2.model.NetworkAclAssociation;
import io.github.hectorvent.floci.services.ec2.model.NetworkAclEntry;
import io.github.hectorvent.floci.services.ec2.model.PrefixList;
import io.github.hectorvent.floci.services.ec2.model.PrefixListId;
import io.github.hectorvent.floci.services.ec2.model.PrefixListEntry;
import io.github.hectorvent.floci.services.ec2.model.Placement;
import io.github.hectorvent.floci.services.ec2.model.ReferencedSecurityGroup;
import io.github.hectorvent.floci.services.ec2.model.Reservation;
import io.github.hectorvent.floci.services.ec2.model.Route;
import io.github.hectorvent.floci.services.ec2.model.RouteTable;
import io.github.hectorvent.floci.services.ec2.model.RouteTableAssociation;
import io.github.hectorvent.floci.services.ec2.model.SecurityGroup;
import io.github.hectorvent.floci.services.ec2.model.SecurityGroupRule;
import io.github.hectorvent.floci.services.ec2.model.Snapshot;
import io.github.hectorvent.floci.services.ec2.model.Subnet;
import io.github.hectorvent.floci.services.ec2.model.Tag;
import io.github.hectorvent.floci.services.ec2.model.TransitGateway;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayOptions;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayRoute;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayRouteTable;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayRouteTablePropagation;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayVpcAttachment;
import io.github.hectorvent.floci.services.ec2.model.TransitGatewayVpcAttachmentOptions;
import io.github.hectorvent.floci.services.ec2.model.UserIdGroupPair;
import io.github.hectorvent.floci.services.ec2.model.Volume;
import io.github.hectorvent.floci.services.ec2.model.VolumeAttachment;
import io.github.hectorvent.floci.services.ec2.model.VolumeModification;
import io.github.hectorvent.floci.services.ec2.model.Vpc;
import io.github.hectorvent.floci.services.ec2.model.VpcCidrBlockAssociation;
import io.github.hectorvent.floci.services.ec2.model.VpcIpv6CidrBlockAssociation;
import io.github.hectorvent.floci.services.ec2.model.VpcEndpoint;
import io.github.hectorvent.floci.services.ec2.model.VpcEndpointDnsEntry;
import io.github.hectorvent.floci.services.ec2.model.VpcEndpointSubnetConfiguration;
import io.github.hectorvent.floci.services.ec2.model.VpcPeeringConnection;
import io.github.hectorvent.floci.services.ec2.model.VpcPeeringConnectionStateReason;
import io.github.hectorvent.floci.services.ec2.model.VpcPeeringConnectionVpcInfo;
import io.github.hectorvent.floci.services.iam.IamService;
import io.github.hectorvent.floci.services.iam.model.InstanceProfile;
import jakarta.annotation.PostConstruct;
import io.github.hectorvent.floci.services.ec2.model.LaunchSpecification;
import io.github.hectorvent.floci.services.ec2.model.SpotInstanceRequest;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.ContextNotActiveException;
import jakarta.inject.Inject;
@ApplicationScoped
public class Ec2Service implements ContainerTeardown, ResourceProvider {
@@ -7308,13 +7307,17 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
* to would be a behaviour change beyond this fix.
*/
private static void requireEgressOnlyGatewayIsTheOnlyTarget(String gatewayId, String natGatewayId,
String egressOnlyInternetGatewayId) {
String egressOnlyInternetGatewayId,
String vpcPeeringConnectionId,
String instanceId,
String networkInterfaceId) {
if (!isSet(egressOnlyInternetGatewayId)) {
return;
}
if (isSet(gatewayId) || isSet(natGatewayId)) {
if (isSet(gatewayId) || isSet(natGatewayId) || isSet(vpcPeeringConnectionId)
|| isSet(instanceId) || isSet(networkInterfaceId)) {
throw new AwsException("InvalidParameterCombination",
"EgressOnlyInternetGatewayId cannot be combined with GatewayId or NatGatewayId; "
"EgressOnlyInternetGatewayId cannot be combined with another target; "
+ "a route takes one target.", 400);
}
}
@@ -7327,14 +7330,55 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
*/
private static void requireVpcPeeringConnectionIsTheOnlyTarget(String gatewayId, String natGatewayId,
String egressOnlyInternetGatewayId,
String vpcPeeringConnectionId) {
String vpcPeeringConnectionId,
String instanceId,
String networkInterfaceId) {
if (!isSet(vpcPeeringConnectionId)) {
return;
}
if (isSet(gatewayId) || isSet(natGatewayId) || isSet(egressOnlyInternetGatewayId)) {
if (isSet(gatewayId) || isSet(natGatewayId) || isSet(egressOnlyInternetGatewayId)
|| isSet(instanceId) || isSet(networkInterfaceId)) {
throw new AwsException("InvalidParameterCombination",
"VpcPeeringConnectionId cannot be combined with GatewayId, NatGatewayId or "
+ "EgressOnlyInternetGatewayId; a route takes one target.", 400);
"VpcPeeringConnectionId cannot be combined with GatewayId, NatGatewayId, "
+ "EgressOnlyInternetGatewayId, InstanceId or NetworkInterfaceId; a route takes one target.", 400);
}
}
private String resolveInstanceOwnerId(String region, String instanceId) {
if (!isSet(instanceId)) {
return null;
}
getRequiredInstance(region, instanceId);
return callerAccountId();
}
private static void requireInstanceIsTheOnlyTarget(String gatewayId, String natGatewayId,
String egressOnlyInternetGatewayId,
String vpcPeeringConnectionId,
String networkInterfaceId,
String instanceId) {
if (!isSet(instanceId)) {
return;
}
if (isSet(gatewayId) || isSet(natGatewayId) || isSet(egressOnlyInternetGatewayId)
|| isSet(vpcPeeringConnectionId) || isSet(networkInterfaceId)) {
throw new AwsException("InvalidParameterCombination",
"InstanceId cannot be combined with another target; a route takes one target.", 400);
}
}
private static void requireNetworkInterfaceIsTheOnlyTarget(String gatewayId, String natGatewayId,
String egressOnlyInternetGatewayId,
String vpcPeeringConnectionId,
String instanceId,
String networkInterfaceId) {
if (!isSet(networkInterfaceId)) {
return;
}
if (isSet(gatewayId) || isSet(natGatewayId) || isSet(egressOnlyInternetGatewayId)
|| isSet(vpcPeeringConnectionId) || isSet(instanceId)) {
throw new AwsException("InvalidParameterCombination",
"NetworkInterfaceId cannot be combined with another target; a route takes one target.", 400);
}
}
@@ -7342,11 +7386,26 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
String destinationIpv6CidrBlock, String destinationPrefixListId,
String gatewayId, String natGatewayId,
String egressOnlyInternetGatewayId, String vpcPeeringConnectionId) {
createRoute(region, routeTableId, destinationCidrBlock, destinationIpv6CidrBlock,
destinationPrefixListId, gatewayId, natGatewayId, egressOnlyInternetGatewayId,
vpcPeeringConnectionId, null, null);
}
public void createRoute(String region, String routeTableId, String destinationCidrBlock,
String destinationIpv6CidrBlock, String destinationPrefixListId,
String gatewayId, String natGatewayId,
String egressOnlyInternetGatewayId, String vpcPeeringConnectionId,
String instanceId, String networkInterfaceId) {
requireExactlyOneDestination("CreateRoute", destinationCidrBlock, destinationIpv6CidrBlock,
destinationPrefixListId);
requireEgressOnlyGatewayIsTheOnlyTarget(gatewayId, natGatewayId, egressOnlyInternetGatewayId);
requireEgressOnlyGatewayIsTheOnlyTarget(gatewayId, natGatewayId, egressOnlyInternetGatewayId,
vpcPeeringConnectionId, instanceId, networkInterfaceId);
requireVpcPeeringConnectionIsTheOnlyTarget(gatewayId, natGatewayId, egressOnlyInternetGatewayId,
vpcPeeringConnectionId);
vpcPeeringConnectionId, instanceId, networkInterfaceId);
requireInstanceIsTheOnlyTarget(gatewayId, natGatewayId, egressOnlyInternetGatewayId,
vpcPeeringConnectionId, networkInterfaceId, instanceId);
requireNetworkInterfaceIsTheOnlyTarget(gatewayId, natGatewayId, egressOnlyInternetGatewayId,
vpcPeeringConnectionId, instanceId, networkInterfaceId);
final String canonicalDestinationCidrBlock = canonicalizeIpv4Cidr(destinationCidrBlock);
ensureDefaultResources(region);
synchronized (lockFor(key(region, routeTableId))) {
@@ -7364,12 +7423,16 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
destinationPrefixListId)
+ " already exists", 400);
}
String effectiveInstanceOwnerId = resolveInstanceOwnerId(region, instanceId);
Route route = new Route(canonicalDestinationCidrBlock, gatewayId, "CreateRoute");
route.setDestinationIpv6CidrBlock(destinationIpv6CidrBlock);
route.setDestinationPrefixListId(destinationPrefixListId);
route.setNatGatewayId(natGatewayId);
route.setEgressOnlyInternetGatewayId(egressOnlyInternetGatewayId);
route.setVpcPeeringConnectionId(vpcPeeringConnectionId);
route.setInstanceId(instanceId);
route.setInstanceOwnerId(effectiveInstanceOwnerId);
route.setNetworkInterfaceId(networkInterfaceId);
next.add(route);
current.setRoutes(next);
routeTables.put(key(region, routeTableId), current);
@@ -7380,25 +7443,39 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
String destinationIpv6CidrBlock, String destinationPrefixListId,
String gatewayId, String natGatewayId, String vpcPeeringConnectionId) {
replaceRoute(region, routeTableId, destinationCidrBlock, destinationIpv6CidrBlock,
destinationPrefixListId, gatewayId, natGatewayId, vpcPeeringConnectionId, false);
destinationPrefixListId, gatewayId, natGatewayId, vpcPeeringConnectionId,
null, null, false);
}
public void replaceRoute(String region, String routeTableId, String destinationCidrBlock,
String destinationIpv6CidrBlock, String destinationPrefixListId,
String gatewayId, String natGatewayId, String vpcPeeringConnectionId,
boolean dryRun) {
replaceRoute(region, routeTableId, destinationCidrBlock, destinationIpv6CidrBlock,
destinationPrefixListId, gatewayId, natGatewayId, vpcPeeringConnectionId,
null, null, dryRun);
}
public void replaceRoute(String region, String routeTableId, String destinationCidrBlock,
String destinationIpv6CidrBlock, String destinationPrefixListId,
String gatewayId, String natGatewayId, String vpcPeeringConnectionId,
String instanceId, String networkInterfaceId,
boolean dryRun) {
requireExactlyOneDestination("ReplaceRoute", destinationCidrBlock, destinationIpv6CidrBlock,
destinationPrefixListId);
// AWS takes exactly one target. Rejecting both-or-neither also keeps the targets this
// emulator cannot model (transit gateway, network interface, ...) from silently clearing
// emulator cannot model (transit gateway, ...) from silently clearing
// the route and reporting success.
boolean hasGateway = isSet(gatewayId);
boolean hasNatGateway = isSet(natGatewayId);
boolean hasPeeringConnection = isSet(vpcPeeringConnectionId);
if ((hasGateway ? 1 : 0) + (hasNatGateway ? 1 : 0) + (hasPeeringConnection ? 1 : 0) != 1) {
boolean hasInstance = isSet(instanceId);
boolean hasNetworkInterface = isSet(networkInterfaceId);
if ((hasGateway ? 1 : 0) + (hasNatGateway ? 1 : 0) + (hasPeeringConnection ? 1 : 0)
+ (hasInstance ? 1 : 0) + (hasNetworkInterface ? 1 : 0) != 1) {
throw new AwsException("InvalidParameterCombination",
"ReplaceRoute takes exactly one target, and only GatewayId, NatGatewayId or "
+ "VpcPeeringConnectionId is supported.", 400);
"ReplaceRoute takes exactly one target, and only GatewayId, NatGatewayId, "
+ "VpcPeeringConnectionId, InstanceId or NetworkInterfaceId is supported.", 400);
}
final String canonicalDestinationCidrBlock = canonicalizeIpv4Cidr(destinationCidrBlock);
@@ -7416,6 +7493,10 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
destinationPrefixListId)
+ " does not exist", 400));
String effectiveInstanceOwnerId = hasInstance
? resolveInstanceOwnerId(region, instanceId)
: null;
if (dryRun) {
throw new AwsException("DryRunOperation",
"Request would have succeeded, but DryRun flag is set.", 412);
@@ -7428,6 +7509,9 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
replacement.setDestinationPrefixListId(destinationPrefixListId);
replacement.setNatGatewayId(hasNatGateway ? natGatewayId : null);
replacement.setVpcPeeringConnectionId(hasPeeringConnection ? vpcPeeringConnectionId : null);
replacement.setInstanceId(hasInstance ? instanceId : null);
replacement.setInstanceOwnerId(effectiveInstanceOwnerId);
replacement.setNetworkInterfaceId(hasNetworkInterface ? networkInterfaceId : null);
next.set(next.indexOf(existing), replacement);
current.setRoutes(next);
routeTables.put(key(region, routeTableId), current);
@@ -7604,6 +7688,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
return findAnyVpcEntry(region, vpcId).map(AccountAwareStorageBackend.OwnedEntry::account);
}
public List<VpcPeeringConnection> describeVpcPeeringConnections(String region, List<String> ids,
Map<String, List<String>> filters) {
ensureDefaultResources(region);
@@ -8332,6 +8417,10 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
case "route.destination-prefix-list-id" -> rt.getRoutes().stream()
.anyMatch(r -> r.getDestinationPrefixListId() != null
&& matchesValue(values, r.getDestinationPrefixListId()));
case "route.instance-id" -> rt.getRoutes().stream()
.anyMatch(r -> r.getInstanceId() != null && matchesValue(values, r.getInstanceId()));
case "route.network-interface-id" -> rt.getRoutes().stream()
.anyMatch(r -> r.getNetworkInterfaceId() != null && matchesValue(values, r.getNetworkInterfaceId()));
default -> true;
};
}
@@ -12,7 +12,10 @@ public class Route {
private String destinationIpv6CidrBlock;
private String destinationPrefixListId;
private String gatewayId;
private String instanceId;
private String instanceOwnerId;
private String natGatewayId;
private String networkInterfaceId;
private String egressOnlyInternetGatewayId;
private String vpcPeeringConnectionId;
private String state = "active";
@@ -61,9 +64,18 @@ public class Route {
public String getGatewayId() { return gatewayId; }
public void setGatewayId(String gatewayId) { this.gatewayId = gatewayId; }
public String getInstanceId() { return instanceId; }
public void setInstanceId(String instanceId) { this.instanceId = instanceId; }
public String getInstanceOwnerId() { return instanceOwnerId; }
public void setInstanceOwnerId(String instanceOwnerId) { this.instanceOwnerId = instanceOwnerId; }
public String getNatGatewayId() { return natGatewayId; }
public void setNatGatewayId(String natGatewayId) { this.natGatewayId = natGatewayId; }
public String getNetworkInterfaceId() { return networkInterfaceId; }
public void setNetworkInterfaceId(String networkInterfaceId) { this.networkInterfaceId = networkInterfaceId; }
public String getEgressOnlyInternetGatewayId() { return egressOnlyInternetGatewayId; }
public void setEgressOnlyInternetGatewayId(String egressOnlyInternetGatewayId) { this.egressOnlyInternetGatewayId = egressOnlyInternetGatewayId; }