# ServiceManagedVolume

Represents a service-managed volume and always configured at launch.

Extends: Construct › ServiceManagedVolume
Implements: IConstruct, IDependable

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

## Example

```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);
```

## Initializer

```ts
new ServiceManagedVolume(scope: Construct, id: string, props: ServiceManagedVolumeProps)
```

## Construct Props

- `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.

## Properties

- `config`: [ServiceManagedEBSVolumeConfiguration](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ServiceManagedEBSVolumeConfiguration.html) — Volume configuration.

- `configuredAtLaunch`: boolean — configuredAtLaunch indicates volume at launch time, referenced by taskdefinition volume.

- `name`: string — Name of the volume, referenced by task definition and mount point.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `role`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — An IAM role that allows ECS to make calls to EBS APIs.

  If not provided, a new role with appropriate permissions will be created by default.

## Methods

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `mountIn(container: ContainerDefinition, mountPoint: ContainerMountPoint): void` — Mounts the service managed volume to a specified container at a defined mount point.

  **Parameters**

  - `container` — The container to mount the volume on.
  - `mountPoint` — The mounting point details within the container.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
