aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.72k stars 3.94k forks source link

Imported VPC errors when there are more than 1 public subnets in a route table #3505

Closed MichaelHindley closed 4 years ago

MichaelHindley commented 5 years ago
 publicSubnetIds: [cdk.Fn.importValue('PubSubId1'), cdk.Fn.importValue('PubSubId2')],
 publicSubnetRouteTableIds: ['RouteTableForBothPublicSubnetsId']

Results in Number of publicSubnetRouteTableIds (x) must be equal to the amount of publicSubnetIds (y)

rix0rrr commented 5 years ago

Not all VPC layouts are importable at the moment, only VPC layouts that mirror a VPC the CDK would create itself.

rix0rrr commented 4 years ago

Has been addressed

mohammadaliqayyum commented 2 years ago

@rix0rrr i do not understand why this issues is closed? I have one RouteTable and three PrivateSubnets and i am not able to import the RouteTable:

Error: Number of privateSubnetRouteTableIds (1) must be equal to the amount of privateSubnetIds (3).

@MichaelHindley have you solved this issue in someway?

mohammadaliqayyum commented 2 years ago

I needed this to be able to create a GatewayVpcEndpointAwsService for S3 and with the imported vpc with fromVpcAttributes i could not import the route tables. I have done the following work around:

// import VPC with other method by id
// create an SSM parameters which store the current VPC ID
new ssm.StringParameter(this, 'VPCID', {
    parameterName: `/VpcProvider/VPCID`,
    stringValue: String(vpcId)
});

// get vpc id so it can be used in vpc lookup
const vpcIdfromssm = ssm.StringParameter.valueFromLookup(this, '/VpcProvider/VPCID');

// use vpc id get from ssm to import vpc
const importVpc = ec2.Vpc.fromLookup(this, 'import-vpc', {
  vpcId: vpcIdfromssm,
});

// create S3 endpoint in imported vpc so that routetables can be edited
const s3Endpoint = importVpc.addGatewayEndpoint('s3Endpoint', {
  service: ec2.GatewayVpcEndpointAwsService.S3,
  subnets: [importVpc.selectSubnets({subnetType: ec2.SubnetType.PRIVATE})],
});
gaspar09 commented 11 months ago
    /**
     * List of IDs of route tables for the public subnets.
     *
     * Must be undefined or have a name for every public subnet group.
     *
     * @default - Retrieving the route table ID of any public subnet will fail
     */
    readonly publicSubnetRouteTableIds?: string[];

I added the route table Id twice. Seemed to work.

 publicSubnetIds: [cdk.Fn.importValue('PubSubId1'), cdk.Fn.importValue('PubSubId2')],
 publicSubnetRouteTableIds: ['RouteTableForBothPublicSubnetsId', 'RouteTableForBothPublicSubnetsId']