# BlockDeviceVolume

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

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

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

## Example

TypeScript:

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

new ec2.Instance(this, 'Instance', {
  vpc,
  instanceType,
  machineImage,

  // ...

  blockDevices: [
    {
      deviceName: '/dev/sda1',
      volume: ec2.BlockDeviceVolume.ebs(50),
    },
    {
      deviceName: '/dev/sdm',
      volume: ec2.BlockDeviceVolume.ebs(100),
    },
  ],
});
```

Python:

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

ec2.Instance(self, "Instance",
    vpc=vpc,
    instance_type=instance_type,
    machine_image=machine_image,

    # ...

    block_devices=[ec2.BlockDevice(
        device_name="/dev/sda1",
        volume=ec2.BlockDeviceVolume.ebs(50)
    ), ec2.BlockDevice(
        device_name="/dev/sdm",
        volume=ec2.BlockDeviceVolume.ebs(100)
    )
    ]
)
```

Java:

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

Instance.Builder.create(this, "Instance")
        .vpc(vpc)
        .instanceType(instanceType)
        .machineImage(machineImage)

        // ...

        .blockDevices(List.of(BlockDevice.builder()
                .deviceName("/dev/sda1")
                .volume(BlockDeviceVolume.ebs(50))
                .build(), BlockDevice.builder()
                .deviceName("/dev/sdm")
                .volume(BlockDeviceVolume.ebs(100))
                .build()))
        .build();
```

C# / .NET:

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

new Instance(this, "Instance", new InstanceProps {
    Vpc = vpc,
    InstanceType = instanceType,
    MachineImage = machineImage,

    // ...

    BlockDevices = new [] { new BlockDevice {
        DeviceName = "/dev/sda1",
        Volume = BlockDeviceVolume.Ebs(50)
    }, new BlockDevice {
        DeviceName = "/dev/sdm",
        Volume = BlockDeviceVolume.Ebs(100)
    } }
});
```

Golang:

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

ec2.NewInstance(this, jsii.String("Instance"), &InstanceProps{
	Vpc: Vpc,
	InstanceType: InstanceType,
	MachineImage: MachineImage,

	// ...

	BlockDevices: []BlockDevice{
		&BlockDevice{
			DeviceName: jsii.String("/dev/sda1"),
			Volume: ec2.BlockDeviceVolume_Ebs(jsii.Number(50)),
		},
		&BlockDevice{
			DeviceName: jsii.String("/dev/sdm"),
			Volume: ec2.BlockDeviceVolume_*Ebs(jsii.Number(100)),
		},
	},
})
```

## Properties

- `ebsDevice`: [EbsDeviceProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.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.
