# CloudMapNamespaceOptions

The options for creating an AWS Cloud Map namespace.

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

- 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#L1253)
- Type last changed: v2.263.0 · 31 Jul 2026

## Example

TypeScript:

```ts
declare const cluster: ecs.Cluster;
declare const taskDefinition: ecs.TaskDefinition;
declare const containerOptions: ecs.ContainerDefinitionOptions;

const container = taskDefinition.addContainer('MyContainer', containerOptions);

container.addPortMappings({
  name: 'api',
  containerPort: 8080,
});

cluster.addDefaultCloudMapNamespace({
  name: 'local',
});

const service = new ecs.FargateService(this, 'Service', {
  cluster,
  taskDefinition,
  minHealthyPercent: 100,
  serviceConnectConfiguration: {
    services: [
      {
        portMappingName: 'api',
        dnsName: 'http-api',
        port: 80,
      },
    ],
  },
});
```

Python:

```python
# cluster: ecs.Cluster
# task_definition: ecs.TaskDefinition
# container_options: ecs.ContainerDefinitionOptions

container = task_definition.add_container("MyContainer", container_options)

container.add_port_mappings(
    name="api",
    container_port=8080
)

cluster.add_default_cloud_map_namespace(
    name="local"
)

service = ecs.FargateService(self, "Service",
    cluster=cluster,
    task_definition=task_definition,
    min_healthy_percent=100,
    service_connect_configuration=ecs.ServiceConnectProps(
        services=[ecs.ServiceConnectService(
            port_mapping_name="api",
            dns_name="http-api",
            port=80
        )
        ]
    )
)
```

Java:

```java
Cluster cluster;
TaskDefinition taskDefinition;
ContainerDefinitionOptions containerOptions;

ContainerDefinition container = taskDefinition.addContainer("MyContainer", containerOptions);

container.addPortMappings(PortMapping.builder()
        .name("api")
        .containerPort(8080)
        .build());

cluster.addDefaultCloudMapNamespace(CloudMapNamespaceOptions.builder()
        .name("local")
        .build());

FargateService service = FargateService.Builder.create(this, "Service")
        .cluster(cluster)
        .taskDefinition(taskDefinition)
        .minHealthyPercent(100)
        .serviceConnectConfiguration(ServiceConnectProps.builder()
                .services(List.of(ServiceConnectService.builder()
                        .portMappingName("api")
                        .dnsName("http-api")
                        .port(80)
                        .build()))
                .build())
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Cluster cluster;
TaskDefinition taskDefinition;
ContainerDefinitionOptions containerOptions;

var container = taskDefinition.AddContainer("MyContainer", containerOptions);

container.AddPortMappings(new PortMapping {
    Name = "api",
    ContainerPort = 8080
});

cluster.AddDefaultCloudMapNamespace(new CloudMapNamespaceOptions {
    Name = "local"
});

var service = new FargateService(this, "Service", new FargateServiceProps {
    Cluster = cluster,
    TaskDefinition = taskDefinition,
    MinHealthyPercent = 100,
    ServiceConnectConfiguration = new ServiceConnectProps {
        Services = new [] { new ServiceConnectService {
            PortMappingName = "api",
            DnsName = "http-api",
            Port = 80
        } }
    }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var cluster Cluster
var taskDefinition TaskDefinition
var containerOptions ContainerDefinitionOptions

container := taskDefinition.AddContainer(jsii.String("MyContainer"), containerOptions)

container.AddPortMappings(&PortMapping{
	Name: jsii.String("api"),
	ContainerPort: jsii.Number(8080),
})

cluster.AddDefaultCloudMapNamespace(&CloudMapNamespaceOptions{
	Name: jsii.String("local"),
})

service := ecs.NewFargateService(this, jsii.String("Service"), &FargateServiceProps{
	Cluster: Cluster,
	TaskDefinition: TaskDefinition,
	MinHealthyPercent: jsii.Number(100),
	ServiceConnectConfiguration: &ServiceConnectProps{
		Services: []ServiceConnectService{
			&ServiceConnectService{
				PortMappingName: jsii.String("api"),
				DnsName: jsii.String("http-api"),
				Port: jsii.Number(80),
			},
		},
	},
})
```

## Properties

- `name`: string (required) — The name of the namespace, such as example.com.

- `type`: [NamespaceType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_servicediscovery.NamespaceType.html) = PrivateDns — The type of CloudMap Namespace to create.

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

- `vpc`: [IVpc](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) — The VPC to associate the namespace with.

  **Default:** VPC of the cluster for Private DNS Namespace, otherwise none

  This property is required for private DNS namespaces.
