From ac03044c9620f1d3fcfcd02ef35028c147a29541 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Mon, 9 May 2022 13:06:01 +0000 Subject: [PATCH] EC2:describe_vpc_endpoints() - filter by vpc-endpoint-type (#5110) --- moto/ec2/models/vpcs.py | 6 ++++++ tests/test_ec2/test_vpcs.py | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/moto/ec2/models/vpcs.py b/moto/ec2/models/vpcs.py index 71339e4f9..671da08c9 100644 --- a/moto/ec2/models/vpcs.py +++ b/moto/ec2/models/vpcs.py @@ -76,6 +76,12 @@ class VPCEndPoint(TaggedEC2Resource, CloudFormationModel): self.created_at = utc_date_and_time() + def get_filter_value(self, filter_name): + if filter_name in ("vpc-endpoint-type", "vpc_endpoint_type"): + return self.endpoint_type + else: + return super().get_filter_value(filter_name, "DescribeVpcs") + @property def owner_id(self): return get_account_id() diff --git a/tests/test_ec2/test_vpcs.py b/tests/test_ec2/test_vpcs.py index 0e92479cc..9d0df039b 100644 --- a/tests/test_ec2/test_vpcs.py +++ b/tests/test_ec2/test_vpcs.py @@ -947,7 +947,7 @@ def test_describe_vpc_gateway_end_points(): VpcId=vpc["VpcId"], ServiceName="com.amazonaws.us-east-1.s3", RouteTableIds=[route_table["RouteTableId"]], - VpcEndpointType="gateway", + VpcEndpointType="Gateway", )["VpcEndpoint"] our_id = vpc_end_point["VpcEndpointId"] @@ -960,7 +960,7 @@ def test_describe_vpc_gateway_end_points(): our_endpoint["VpcId"].should.equal(vpc["VpcId"]) our_endpoint["RouteTableIds"].should.equal([route_table["RouteTableId"]]) - our_endpoint.should.have.key("VpcEndpointType").equal("gateway") + our_endpoint.should.have.key("VpcEndpointType").equal("Gateway") our_endpoint.should.have.key("ServiceName").equal("com.amazonaws.us-east-1.s3") our_endpoint.should.have.key("State").equal("available") @@ -970,10 +970,15 @@ def test_describe_vpc_gateway_end_points(): endpoint_by_id["VpcEndpointId"].should.equal(our_id) endpoint_by_id["VpcId"].should.equal(vpc["VpcId"]) endpoint_by_id["RouteTableIds"].should.equal([route_table["RouteTableId"]]) - endpoint_by_id["VpcEndpointType"].should.equal("gateway") + endpoint_by_id["VpcEndpointType"].should.equal("Gateway") endpoint_by_id["ServiceName"].should.equal("com.amazonaws.us-east-1.s3") endpoint_by_id["State"].should.equal("available") + gateway_endpoints = ec2.describe_vpc_endpoints( + Filters=[{"Name": "vpc-endpoint-type", "Values": ["Gateway"]}] + )["VpcEndpoints"] + [e["VpcEndpointId"] for e in gateway_endpoints].should.contain(our_id) + with pytest.raises(ClientError) as ex: ec2.describe_vpc_endpoints(VpcEndpointIds=[route_table["RouteTableId"]]) err = ex.value.response["Error"]