diff --git a/moto/ec2/models.py b/moto/ec2/models.py index c35fa339..edc216eb 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -2881,24 +2881,25 @@ class VPCBackend(object): vpc = self.get_vpc(vpc_id) return vpc.associate_vpc_cidr_block(cidr_block, amazon_provided_ipv6_cidr_block) - def create_vpc_endpoint(self, - vpc_id, - service_name, - type=None, - policy_document=False, - route_table_ids=None, - subnet_ids=[], - network_interface_ids=[], - dns_entries=None, - client_token=None, - security_group=None, - tag_specifications=None, - private_dns_enabled=None - ): + def create_vpc_endpoint( + self, + vpc_id, + service_name, + type=None, + policy_document=False, + route_table_ids=None, + subnet_ids=[], + network_interface_ids=[], + dns_entries=None, + client_token=None, + security_group=None, + tag_specifications=None, + private_dns_enabled=None, + ): vpc_endpoint_id = generate_vpc_end_point_id(vpc_id) - #validates if vpc is present or not. + # validates if vpc is present or not. self.get_vpc(vpc_id) if type and type.lower() == "interface": @@ -2911,15 +2912,12 @@ class VPCBackend(object): dns_entries = create_dns_entries(service_name, vpc_endpoint_id) - else : + else: # considering gateway if type is not mentioned. service_destination_cidr = randor_ipv4_cidr() for route_table_id in route_table_ids: - self.create_route( - route_table_id, - service_destination_cidr - ) + self.create_route(route_table_id, service_destination_cidr) if dns_entries: dns_entries = [dns_entries] @@ -2936,7 +2934,7 @@ class VPCBackend(object): client_token, security_group, tag_specifications, - private_dns_enabled + private_dns_enabled, ) self.vpc_end_points[vpc_endpoint_id] = vpc_end_point @@ -3560,7 +3558,7 @@ class VPCEndPoint(TaggedEC2Resource): type=None, policy_document=False, route_table_ids=None, - subnet_ids =None, + subnet_ids=None, network_interface_ids=None, dns_entries=None, client_token=None, diff --git a/moto/ec2/responses/vpcs.py b/moto/ec2/responses/vpcs.py index 4b0aa76d..59222207 100644 --- a/moto/ec2/responses/vpcs.py +++ b/moto/ec2/responses/vpcs.py @@ -176,22 +176,20 @@ class VPCs(BaseResponse): security_group = self._get_param("SecurityGroup") vpc_end_point = self.ec2_backend.create_vpc_endpoint( - vpc_id=vpc_id, - service_name=service_name, - type=type, - policy_document=policy_document, - route_table_ids=route_table_ids, - subnet_ids=subnet_ids, - client_token=client_token, - security_group=security_group, - tag_specifications=tag_specifications, - private_dns_enabled=private_dns_enabled + vpc_id=vpc_id, + service_name=service_name, + type=type, + policy_document=policy_document, + route_table_ids=route_table_ids, + subnet_ids=subnet_ids, + client_token=client_token, + security_group=security_group, + tag_specifications=tag_specifications, + private_dns_enabled=private_dns_enabled, ) template = self.response_template(CREATE_VPC_END_POINT) - return template.render( - vpc_end_point=vpc_end_point - ) + return template.render(vpc_end_point=vpc_end_point) CREATE_VPC_RESPONSE = """ @@ -450,4 +448,4 @@ CREATE_VPC_END_POINT = """ """ diff --git a/moto/ec2/utils.py b/moto/ec2/utils.py index 408ee9be..c07c470a 100644 --- a/moto/ec2/utils.py +++ b/moto/ec2/utils.py @@ -194,13 +194,14 @@ def generate_route_id(route_table_id, cidr_block): def generate_vpc_end_point_id(vpc_id): - return "%s-%s" % ('vpce', vpc_id[4:]) + return "%s-%s" % ("vpce", vpc_id[4:]) def create_dns_entries(service_name, vpc_endpoint_id): dns_entries = {} - dns_entries["dns_name"] = "{}-{}.{}".format(vpc_endpoint_id, - random_resource_id(8), service_name) + dns_entries["dns_name"] = "{}-{}.{}".format( + vpc_endpoint_id, random_resource_id(8), service_name + ) dns_entries["hosted_zone_id"] = random_resource_id(13).upper() return dns_entries diff --git a/tests/test_ec2/test_route_tables.py b/tests/test_ec2/test_route_tables.py index f8be8dc8..a64fbae1 100644 --- a/tests/test_ec2/test_route_tables.py +++ b/tests/test_ec2/test_route_tables.py @@ -625,8 +625,7 @@ def test_create_vpc_end_point(): ec2 = boto3.client("ec2", region_name="us-west-1") vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16") - subnet = ec2.create_subnet(VpcId=vpc["Vpc"]["VpcId"], - CidrBlock="10.0.0.0/24") + subnet = ec2.create_subnet(VpcId=vpc["Vpc"]["VpcId"], CidrBlock="10.0.0.0/24") route_table = ec2.create_route_table(VpcId=vpc["Vpc"]["VpcId"]) @@ -634,13 +633,15 @@ def test_create_vpc_end_point(): vpc_end_point = ec2.create_vpc_endpoint( VpcId=vpc["Vpc"]["VpcId"], ServiceName="com.amazonaws.us-east-1.s3", - RouteTableIds=[route_table["RouteTable"]["RouteTableId"]] - ) + RouteTableIds=[route_table["RouteTable"]["RouteTableId"]], + ) - vpc_end_point["VpcEndpoint"]["ServiceName"].\ - should.equal("com.amazonaws.us-east-1.s3") - vpc_end_point["VpcEndpoint"]["RouteTableIds"][0].\ - should.equal(route_table["RouteTable"]["RouteTableId"]) + vpc_end_point["VpcEndpoint"]["ServiceName"].should.equal( + "com.amazonaws.us-east-1.s3" + ) + vpc_end_point["VpcEndpoint"]["RouteTableIds"][0].should.equal( + route_table["RouteTable"]["RouteTableId"] + ) vpc_end_point["VpcEndpoint"]["VpcId"].should.equal(vpc["Vpc"]["VpcId"]) vpc_end_point["VpcEndpoint"]["DnsEntries"].should.have.length_of(0) @@ -649,13 +650,15 @@ def test_create_vpc_end_point(): VpcId=vpc["Vpc"]["VpcId"], ServiceName="com.amazonaws.us-east-1.s3", RouteTableIds=[route_table["RouteTable"]["RouteTableId"]], - VpcEndpointType="gateway" + VpcEndpointType="gateway", ) - vpc_end_point["VpcEndpoint"]["ServiceName"]. \ - should.equal("com.amazonaws.us-east-1.s3") - vpc_end_point["VpcEndpoint"]["RouteTableIds"][0]. \ - should.equal(route_table["RouteTable"]["RouteTableId"]) + vpc_end_point["VpcEndpoint"]["ServiceName"].should.equal( + "com.amazonaws.us-east-1.s3" + ) + vpc_end_point["VpcEndpoint"]["RouteTableIds"][0].should.equal( + route_table["RouteTable"]["RouteTableId"] + ) vpc_end_point["VpcEndpoint"]["VpcId"].should.equal(vpc["Vpc"]["VpcId"]) vpc_end_point["VpcEndpoint"]["DnsEntries"].should.have.length_of(0) @@ -664,12 +667,14 @@ def test_create_vpc_end_point(): VpcId=vpc["Vpc"]["VpcId"], ServiceName="com.amazonaws.us-east-1.s3", SubnetIds=[subnet["Subnet"]["SubnetId"]], - VpcEndpointType="interface" + VpcEndpointType="interface", ) - vpc_end_point["VpcEndpoint"]["ServiceName"].\ - should.equal("com.amazonaws.us-east-1.s3") - vpc_end_point["VpcEndpoint"]["SubnetIds"][0].\ - should.equal(subnet["Subnet"]["SubnetId"]) + vpc_end_point["VpcEndpoint"]["ServiceName"].should.equal( + "com.amazonaws.us-east-1.s3" + ) + vpc_end_point["VpcEndpoint"]["SubnetIds"][0].should.equal( + subnet["Subnet"]["SubnetId"] + ) vpc_end_point["VpcEndpoint"]["VpcId"].should.equal(vpc["Vpc"]["VpcId"]) - len(vpc_end_point["VpcEndpoint"]["DnsEntries"]).should.be.greater_than(0) \ No newline at end of file + len(vpc_end_point["VpcEndpoint"]["DnsEntries"]).should.be.greater_than(0)