Skip to content
v2.278.0

CloudMapNamespaceOptions Struct ​

The options for creating an AWS Cloud Map namespace.

Example ​

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
# 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
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();
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
        } }
    }
});
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 ​

namestringnamestrnameStringNamestringName*string required #
The name of the namespace, such as example.com.
typeoptionalNamespaceTypetypeoptionalNamespaceTypetypeoptionalNamespaceTypeTypeoptionalNamespaceTypeTypeoptionalNamespaceType = PrivateDns #
The type of CloudMap Namespace to create.
useForServiceConnectoptionalbooleanuse_for_service_connectoptionalbooluseForServiceConnectoptionalBooleanUseForServiceConnectoptionalboolUseForServiceConnectoptional*bool = false #
This property specifies whether to set the provided namespace as the service connect default in the cluster properties.
vpcoptionalIVpcvpcoptionalIVpcvpcoptionalIVpcVpcoptionalIVpcVpcoptionalIVpc #
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.