# VpcLookupOptions

Properties for looking up an existing VPC.

The combination of properties must specify filter down to exactly one
non-default VPC, otherwise an error is raised.

Used as argument in: [Vpc.fromLookup](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Vpc.html#fromlookup)

- Source: [`aws-ec2/lib/vpc-lookup.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ec2/lib/vpc-lookup.ts#L7)
- Type last changed: v2.73.0 · 6 Apr 2023

## Example

TypeScript:

```ts
const vpc = ec2.Vpc.fromLookup(this, 'Vpc', {
  isDefault: true,
});
const cluster = new ecs.Cluster(this, 'ECSCluster', { vpc });

const taskDefinition = new ecs.TaskDefinition(this, 'TD', {
  compatibility: ecs.Compatibility.EC2,
});

taskDefinition.addContainer('TheContainer', {
  image: ecs.ContainerImage.fromRegistry('foo/bar'),
  memoryLimitMiB: 256,
});

const runTask = new tasks.EcsRunTask(this, 'Run', {
  integrationPattern: sfn.IntegrationPattern.RUN_JOB,
  cluster,
  taskDefinition,
  launchTarget: new tasks.EcsEc2LaunchTarget(),
  enableExecuteCommand: true,
});
```

Python:

```python
vpc = ec2.Vpc.from_lookup(self, "Vpc",
    is_default=True
)
cluster = ecs.Cluster(self, "ECSCluster", vpc=vpc)

task_definition = ecs.TaskDefinition(self, "TD",
    compatibility=ecs.Compatibility.EC2
)

task_definition.add_container("TheContainer",
    image=ecs.ContainerImage.from_registry("foo/bar"),
    memory_limit_mi_b=256
)

run_task = tasks.EcsRunTask(self, "Run",
    integration_pattern=sfn.IntegrationPattern.RUN_JOB,
    cluster=cluster,
    task_definition=task_definition,
    launch_target=tasks.EcsEc2LaunchTarget(),
    enable_execute_command=True
)
```

Java:

```java
IVpc vpc = Vpc.fromLookup(this, "Vpc", VpcLookupOptions.builder()
        .isDefault(true)
        .build());
Cluster cluster = Cluster.Builder.create(this, "ECSCluster").vpc(vpc).build();

TaskDefinition taskDefinition = TaskDefinition.Builder.create(this, "TD")
        .compatibility(Compatibility.EC2)
        .build();

taskDefinition.addContainer("TheContainer", ContainerDefinitionOptions.builder()
        .image(ContainerImage.fromRegistry("foo/bar"))
        .memoryLimitMiB(256)
        .build());

EcsRunTask runTask = EcsRunTask.Builder.create(this, "Run")
        .integrationPattern(IntegrationPattern.RUN_JOB)
        .cluster(cluster)
        .taskDefinition(taskDefinition)
        .launchTarget(new EcsEc2LaunchTarget())
        .enableExecuteCommand(true)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var vpc = Vpc.FromLookup(this, "Vpc", new VpcLookupOptions {
    IsDefault = true
});
var cluster = new Cluster(this, "ECSCluster", new ClusterProps { Vpc = vpc });

var taskDefinition = new TaskDefinition(this, "TD", new TaskDefinitionProps {
    Compatibility = Compatibility.EC2
});

taskDefinition.AddContainer("TheContainer", new ContainerDefinitionOptions {
    Image = ContainerImage.FromRegistry("foo/bar"),
    MemoryLimitMiB = 256
});

var runTask = new EcsRunTask(this, "Run", new EcsRunTaskProps {
    IntegrationPattern = IntegrationPattern.RUN_JOB,
    Cluster = cluster,
    TaskDefinition = taskDefinition,
    LaunchTarget = new EcsEc2LaunchTarget(),
    EnableExecuteCommand = true
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
vpc := ec2.Vpc_FromLookup(this, jsii.String("Vpc"), &VpcLookupOptions{
	IsDefault: jsii.Boolean(true),
})
cluster := ecs.NewCluster(this, jsii.String("ECSCluster"), &ClusterProps{
	Vpc: Vpc,
})

taskDefinition := ecs.NewTaskDefinition(this, jsii.String("TD"), &TaskDefinitionProps{
	Compatibility: ecs.Compatibility_EC2,
})

taskDefinition.AddContainer(jsii.String("TheContainer"), &ContainerDefinitionOptions{
	Image: ecs.ContainerImage_FromRegistry(jsii.String("foo/bar")),
	MemoryLimitMiB: jsii.Number(256),
})

runTask := tasks.NewEcsRunTask(this, jsii.String("Run"), &EcsRunTaskProps{
	IntegrationPattern: sfn.IntegrationPattern_RUN_JOB,
	Cluster: Cluster,
	TaskDefinition: TaskDefinition,
	LaunchTarget: tasks.NewEcsEc2LaunchTarget(),
	EnableExecuteCommand: jsii.Boolean(true),
})
```

## Properties

- `isDefault`: boolean — Whether to match the default VPC.

  **Default:** Don't care whether we return the default VPC

- `ownerAccountId`: string — The ID of the AWS account that owns the VPC.

  **Default:** the account id of the parent stack

- `region`: string — Optional to override inferred region.

  **Default:** Current stack's environment region

- `returnVpnGateways`: boolean = true — Whether to look up whether a VPN Gateway is attached to the looked up VPC.

  You can set this to `false` if you know the VPC does not have a VPN Gateway
  attached, in order to avoid an API call.

  If you change this property from `false` to `true` or undefined, you may
  need to clear the corresponding context entry in `cdk.context.json` in
  order to trigger a new lookup.

- `subnetGroupNameTag`: string = aws-cdk:subnet-name — Optional tag for subnet group name.

  If not provided, we'll look at the aws-cdk:subnet-name tag.
  If the subnet does not have the specified tag,
  we'll use its type as the name.

- `tags`: { [key: string]: string } — Tags on the VPC.

  **Default:** Don't filter on tags

  The VPC must have all of these tags

- `vpcId`: string — The ID of the VPC.

  **Default:** Don't filter on vpcId

  If given, will import exactly this VPC.

- `vpcName`: string — The name of the VPC.

  **Default:** Don't filter on vpcName

  If given, will import the VPC with this name.
