# ServiceConnectProps

Interface for Service Connect configuration.

Used as argument in: [BaseService.enableServiceConnect](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.BaseService.html#enableserviceconnect)

- Source: [`aws-ecs/lib/base/base-service.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts#L288)
- Type last changed: v2.251.0 · 24 Apr 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

- `accessLogConfiguration`: [ServiceConnectAccessLogConfiguration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ServiceConnectAccessLogConfiguration.html) — The configuration for Service Connect access logs.

  **Default:** undefined - AWS ECS default is disabled, which means that access logs are not recorded

  Access logs provide detailed telemetry about individual requests processed by the　Service Connect proxy.

- `logDriver`: [LogDriver](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.LogDriver.html) = none — The log driver configuration to use for the Service Connect agent logs.

- `namespace`: string — The cloudmap namespace to register this service into.

  **Default:** the cloudmap namespace specified on the cluster.

- `services`: [ServiceConnectService](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ServiceConnectService.html)[] = none — The list of Services, including a port mapping, terse client alias, and optional intermediate DNS name.

  This property may be left blank if the current ECS service does not need to advertise any ports via Service Connect.
