# ConstructSelector

Selects constructs from a construct tree based on various criteria.

- Source: [`core/lib/mixins/selectors.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/core/lib/mixins/selectors.ts#L17)
- Type last changed: v2.241.0 · 2 Mar 2026

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
const constructSelector = new cdk.ConstructSelector();
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk

construct_selector = cdk.ConstructSelector()
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;

ConstructSelector constructSelector = new ConstructSelector();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK;

var constructSelector = new ConstructSelector();
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import cdk "github.com/aws/aws-cdk-go/awscdk"

constructSelector := cdk.NewConstructSelector()
```

## Initializer

TypeScript:

```ts
new ConstructSelector()
```

Python:

```python
ConstructSelector()
```

Java:

```java
new ConstructSelector()
```

C# / .NET:

```csharp
new ConstructSelector()
```

Golang:

```go
NewConstructSelector()
```

## Methods

- `all(): IConstructSelector` (static) — Selects all constructs in the tree.

- `byId(pattern: string): IConstructSelector` (static) — Selects constructs whose construct IDs match a pattern.

  Uses glob like matching.

- `byPath(pattern: string): IConstructSelector` (static) — Selects constructs whose construct paths match a pattern.

  Uses glob like matching.

- `cfnResource(): IConstructSelector` (static) — Selects CfnResource constructs or the default CfnResource child.

- `onlyItself(): IConstructSelector` (static) — Selects only the provided construct.

- `resourcesOfType(...types: string[]): IConstructSelector` (static) — Selects constructs of a specific type.
