# ExistingCloudMapNamespaceOptions

The options for using an existing AWS Cloud Map namespace as the default namespace of a cluster.

Extends: [CloudMapNamespaceOptionsBase](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.CloudMapNamespaceOptionsBase.html)
Used as argument in: [Cluster.addExistingDefaultCloudMapNamespace](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.Cluster.html#addexistingdefaultcloudmapnamespace)

- Source: [`aws-ecs/lib/cluster.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ecs/lib/cluster.ts#L1277)
- Type last changed: v2.263.0 · 31 Jul 2026

## Example

TypeScript:

```ts
declare const vpc: ec2.Vpc;

// Create or reference an existing namespace
const existingNamespace = new cloudmap.PrivateDnsNamespace(this, 'Namespace', {
  name: 'example.local',
  vpc,
});

const cluster = new ecs.Cluster(this, 'Cluster', { vpc });

// Use the existing namespace as the default
cluster.addExistingDefaultCloudMapNamespace({
  namespace: existingNamespace,
  useForServiceConnect: true,
});
```

Python:

```python
# vpc: ec2.Vpc

# Create or reference an existing namespace
existing_namespace = cloudmap.PrivateDnsNamespace(self, "Namespace",
    name="example.local",
    vpc=vpc
)

cluster = ecs.Cluster(self, "Cluster", vpc=vpc)

# Use the existing namespace as the default
cluster.add_existing_default_cloud_map_namespace(
    namespace=existing_namespace,
    use_for_service_connect=True
)
```

Java:

```java
Vpc vpc;

// Create or reference an existing namespace
PrivateDnsNamespace existingNamespace = PrivateDnsNamespace.Builder.create(this, "Namespace")
        .name("example.local")
        .vpc(vpc)
        .build();

Cluster cluster = Cluster.Builder.create(this, "Cluster").vpc(vpc).build();

// Use the existing namespace as the default
cluster.addExistingDefaultCloudMapNamespace(ExistingCloudMapNamespaceOptions.builder()
        .namespace(existingNamespace)
        .useForServiceConnect(true)
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Vpc vpc;

// Create or reference an existing namespace
var existingNamespace = new PrivateDnsNamespace(this, "Namespace", new PrivateDnsNamespaceProps {
    Name = "example.local",
    Vpc = vpc
});

var cluster = new Cluster(this, "Cluster", new ClusterProps { Vpc = vpc });

// Use the existing namespace as the default
cluster.AddExistingDefaultCloudMapNamespace(new ExistingCloudMapNamespaceOptions {
    Namespace = existingNamespace,
    UseForServiceConnect = true
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc

// Create or reference an existing namespace
existingNamespace := cloudmap.NewPrivateDnsNamespace(this, jsii.String("Namespace"), &PrivateDnsNamespaceProps{
	Name: jsii.String("example.local"),
	Vpc: Vpc,
})

cluster := ecs.NewCluster(this, jsii.String("Cluster"), &ClusterProps{
	Vpc: Vpc,
})

// Use the existing namespace as the default
cluster.AddExistingDefaultCloudMapNamespace(&ExistingCloudMapNamespaceOptions{
	Namespace: existingNamespace,
	UseForServiceConnect: jsii.Boolean(true),
})
```

## Properties

- `namespace`: [INamespace](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_servicediscovery.INamespace.html) (required) — The existing Cloud Map namespace to use as the cluster's default namespace.

  The full `INamespace` is required (rather than a ref) because the cluster needs the
  namespace name, ARN and type to wire up Service Discovery and Service Connect.

  [disable-awslint:prefer-ref-interface]

- `useForServiceConnect`: boolean = false — This property specifies whether to set the provided namespace as the service connect default in the cluster properties.
