# ServiceManagedVolumeProps

Represents the Volume configuration for an ECS service.

Used as props by: [ServiceManagedVolume](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ServiceManagedVolume.html)

- Source: [`aws-ecs/lib/base/service-managed-volume.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-ecs/lib/base/service-managed-volume.ts#L13)
- Type last changed: v2.122.0 · 18 Jan 2024

## Example

TypeScript:

```ts
declare const cluster: ecs.Cluster;
const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef');

const container = taskDefinition.addContainer('web', {
  image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
  portMappings: [{
    containerPort: 80,
    protocol: ecs.Protocol.TCP,
  }],
});

const volume = new ecs.ServiceManagedVolume(this, 'EBSVolume', {
  name: 'ebs1',
  managedEBSVolume: {
    size: Size.gibibytes(15),
    volumeType: ec2.EbsDeviceVolumeType.GP3,
    fileSystemType: ecs.FileSystemType.XFS,
    tagSpecifications: [{
      tags: {
        purpose: 'production',
      },
      propagateTags: ecs.EbsPropagatedTagSource.SERVICE,
    }],
  },
});

volume.mountIn(container, {
  containerPath: '/var/lib',
  readOnly: false,
});

taskDefinition.addVolume(volume);

const service = new ecs.FargateService(this, 'FargateService', {
  cluster,
  taskDefinition,
  minHealthyPercent: 100,
});

service.addVolume(volume);
```

Python:

```python
# cluster: ecs.Cluster

task_definition = ecs.FargateTaskDefinition(self, "TaskDef")

container = task_definition.add_container("web",
    image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
    port_mappings=[ecs.PortMapping(
        container_port=80,
        protocol=ecs.Protocol.TCP
    )]
)

volume = ecs.ServiceManagedVolume(self, "EBSVolume",
    name="ebs1",
    managed_ebs_volume=ecs.ServiceManagedEBSVolumeConfiguration(
        size=Size.gibibytes(15),
        volume_type=ec2.EbsDeviceVolumeType.GP3,
        file_system_type=ecs.FileSystemType.XFS,
        tag_specifications=[ecs.EBSTagSpecification(
            tags={
                "purpose": "production"
            },
            propagate_tags=ecs.EbsPropagatedTagSource.SERVICE
        )]
    )
)

volume.mount_in(container,
    container_path="/var/lib",
    read_only=False
)

task_definition.add_volume(volume)

service = ecs.FargateService(self, "FargateService",
    cluster=cluster,
    task_definition=task_definition,
    min_healthy_percent=100
)

service.add_volume(volume)
```

Java:

```java
Cluster cluster;

FargateTaskDefinition taskDefinition = new FargateTaskDefinition(this, "TaskDef");

ContainerDefinition container = taskDefinition.addContainer("web", ContainerDefinitionOptions.builder()
        .image(ContainerImage.fromRegistry("amazon/amazon-ecs-sample"))
        .portMappings(List.of(PortMapping.builder()
                .containerPort(80)
                .protocol(Protocol.TCP)
                .build()))
        .build());

ServiceManagedVolume volume = ServiceManagedVolume.Builder.create(this, "EBSVolume")
        .name("ebs1")
        .managedEBSVolume(ServiceManagedEBSVolumeConfiguration.builder()
                .size(Size.gibibytes(15))
                .volumeType(EbsDeviceVolumeType.GP3)
                .fileSystemType(FileSystemType.XFS)
                .tagSpecifications(List.of(EBSTagSpecification.builder()
                        .tags(Map.of(
                                "purpose", "production"))
                        .propagateTags(EbsPropagatedTagSource.SERVICE)
                        .build()))
                .build())
        .build();

volume.mountIn(container, ContainerMountPoint.builder()
        .containerPath("/var/lib")
        .readOnly(false)
        .build());

taskDefinition.addVolume(volume);

FargateService service = FargateService.Builder.create(this, "FargateService")
        .cluster(cluster)
        .taskDefinition(taskDefinition)
        .minHealthyPercent(100)
        .build();

service.addVolume(volume);
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Cluster cluster;

var taskDefinition = new FargateTaskDefinition(this, "TaskDef");

var container = taskDefinition.AddContainer("web", new ContainerDefinitionOptions {
    Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample"),
    PortMappings = new [] { new PortMapping {
        ContainerPort = 80,
        Protocol = Protocol.TCP
    } }
});

var volume = new ServiceManagedVolume(this, "EBSVolume", new ServiceManagedVolumeProps {
    Name = "ebs1",
    ManagedEBSVolume = new ServiceManagedEBSVolumeConfiguration {
        Size = Size.Gibibytes(15),
        VolumeType = EbsDeviceVolumeType.GP3,
        FileSystemType = FileSystemType.XFS,
        TagSpecifications = new [] { new EBSTagSpecification {
            Tags = new Dictionary<string, string> {
                { "purpose", "production" }
            },
            PropagateTags = EbsPropagatedTagSource.SERVICE
        } }
    }
});

volume.MountIn(container, new ContainerMountPoint {
    ContainerPath = "/var/lib",
    ReadOnly = false
});

taskDefinition.AddVolume(volume);

var service = new FargateService(this, "FargateService", new FargateServiceProps {
    Cluster = cluster,
    TaskDefinition = taskDefinition,
    MinHealthyPercent = 100
});

service.AddVolume(volume);
```

Golang:

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

taskDefinition := ecs.NewFargateTaskDefinition(this, jsii.String("TaskDef"))

container := taskDefinition.AddContainer(jsii.String("web"), &ContainerDefinitionOptions{
	Image: ecs.ContainerImage_FromRegistry(jsii.String("amazon/amazon-ecs-sample")),
	PortMappings: []PortMapping{
		&PortMapping{
			ContainerPort: jsii.Number(80),
			Protocol: ecs.Protocol_TCP,
		},
	},
})

volume := ecs.NewServiceManagedVolume(this, jsii.String("EBSVolume"), &ServiceManagedVolumeProps{
	Name: jsii.String("ebs1"),
	ManagedEBSVolume: &ServiceManagedEBSVolumeConfiguration{
		Size: awscdk.Size_Gibibytes(jsii.Number(15)),
		VolumeType: ec2.EbsDeviceVolumeType_GP3,
		FileSystemType: ecs.FileSystemType_XFS,
		TagSpecifications: []EBSTagSpecification{
			&EBSTagSpecification{
				Tags: map[string]*string{
					"purpose": jsii.String("production"),
				},
				PropagateTags: ecs.EbsPropagatedTagSource_SERVICE,
			},
		},
	},
})

volume.MountIn(container, &ContainerMountPoint{
	ContainerPath: jsii.String("/var/lib"),
	ReadOnly: jsii.Boolean(false),
})

taskDefinition.AddVolume(volume)

service := ecs.NewFargateService(this, jsii.String("FargateService"), &FargateServiceProps{
	Cluster: Cluster,
	TaskDefinition: TaskDefinition,
	MinHealthyPercent: jsii.Number(100),
})

service.AddVolume(volume)
```

## Properties

- `managedEBSVolume`: [ServiceManagedEBSVolumeConfiguration](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ServiceManagedEBSVolumeConfiguration.html) = undefined — Configuration for an Amazon Elastic Block Store (EBS) volume managed by ECS.

- `name`: string (required) — The name of the volume.

  This corresponds to the name provided in the ECS TaskDefinition.
