# BlockDeviceVolume

Describes a block device mapping for an EC2 instance or Auto Scaling group.

Obtainable from: BlockDeviceVolume.ebs, BlockDeviceVolume.ebsFromSnapshot, BlockDeviceVolume.ephemeral, BlockDeviceVolume.noDevice

- Source: [`aws-autoscaling/lib/volume.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-autoscaling/lib/volume.ts#L139)

## Example

TypeScript:

```ts
declare const vpc: ec2.Vpc;
declare const instanceType: ec2.InstanceType;
declare const machineImage: ec2.IMachineImage;

const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', {
  vpc,
  instanceType,
  machineImage,
  blockDevices: [
    {
        deviceName: 'gp3-volume',
        volume: autoscaling.BlockDeviceVolume.ebs(15, {
          volumeType: autoscaling.EbsDeviceVolumeType.GP3,
          throughput: 125,
        }),
      },
  ],
  // ...
});
```

Python:

```python
# vpc: ec2.Vpc
# instance_type: ec2.InstanceType
# machine_image: ec2.IMachineImage

auto_scaling_group = autoscaling.AutoScalingGroup(self, "ASG",
    vpc=vpc,
    instance_type=instance_type,
    machine_image=machine_image,
    block_devices=[autoscaling.BlockDevice(
        device_name="gp3-volume",
        volume=autoscaling.BlockDeviceVolume.ebs(15,
            volume_type=autoscaling.EbsDeviceVolumeType.GP3,
            throughput=125
        )
    )
    ]
)
```

Java:

```java
Vpc vpc;
InstanceType instanceType;
IMachineImage machineImage;

AutoScalingGroup autoScalingGroup = AutoScalingGroup.Builder.create(this, "ASG")
        .vpc(vpc)
        .instanceType(instanceType)
        .machineImage(machineImage)
        .blockDevices(List.of(BlockDevice.builder()
                .deviceName("gp3-volume")
                .volume(BlockDeviceVolume.ebs(15, EbsDeviceOptions.builder()
                        .volumeType(EbsDeviceVolumeType.GP3)
                        .throughput(125)
                        .build()))
                .build()))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Vpc vpc;
InstanceType instanceType;
IMachineImage machineImage;

var autoScalingGroup = new AutoScalingGroup(this, "ASG", new AutoScalingGroupProps {
    Vpc = vpc,
    InstanceType = instanceType,
    MachineImage = machineImage,
    BlockDevices = new [] { new BlockDevice {
        DeviceName = "gp3-volume",
        Volume = BlockDeviceVolume.Ebs(15, new EbsDeviceOptions {
            VolumeType = EbsDeviceVolumeType.GP3,
            Throughput = 125
        })
    } }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc
var instanceType InstanceType
var machineImage IMachineImage

autoScalingGroup := autoscaling.NewAutoScalingGroup(this, jsii.String("ASG"), &AutoScalingGroupProps{
	Vpc: Vpc,
	InstanceType: InstanceType,
	MachineImage: MachineImage,
	BlockDevices: []BlockDevice{
		&BlockDevice{
			DeviceName: jsii.String("gp3-volume"),
			Volume: autoscaling.BlockDeviceVolume_Ebs(jsii.Number(15), &EbsDeviceOptions{
				VolumeType: autoscaling.EbsDeviceVolumeType_GP3,
				Throughput: jsii.Number(125),
			}),
		},
	},
})
```

## Properties

- `ebsDevice`: [EbsDeviceProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.EbsDeviceProps.html) — EBS device info.

- `virtualName`: string — Virtual device name.

## Methods

- `ebs(volumeSize: number, options?: EbsDeviceOptions): BlockDeviceVolume // chainable` (static) — Creates a new Elastic Block Storage device.

  **Parameters**

  - `volumeSize` — The volume size, in Gibibytes (GiB).
  - `options` — additional device options.

- `ebsFromSnapshot(snapshotId: string, options?: EbsDeviceSnapshotOptions): BlockDeviceVolume // chainable` (static) — Creates a new Elastic Block Storage device from an existing snapshot.

  **Parameters**

  - `snapshotId` — The snapshot ID of the volume to use.
  - `options` — additional device options.

- `ephemeral(volumeIndex: number): BlockDeviceVolume // chainable` (static) — Creates a virtual, ephemeral device.

  The name will be in the form ephemeral{volumeIndex}.

  **Parameters**

  - `volumeIndex` — the volume index.

- `noDevice(): BlockDeviceVolume // chainable` (static) — Suppresses a volume mapping.
