Skip to content

create_volume

create_volume(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    availability_zone: Optional[AvailabilityZoneName] = None,
    availability_zone_id: Optional[AvailabilityZoneId] = None,
    encrypted: Optional[Boolean] = None,
    iops: Optional[Integer] = None,
    kms_key_id: Optional[KmsKeyId] = None,
    outpost_arn: Optional[String] = None,
    size: Optional[Integer] = None,
    snapshot_id: Optional[SnapshotId] = None,
    volume_type: Optional[VolumeType] = None,
    tag_specifications: Optional[TagSpecificationList] = None,
    multi_attach_enabled: Optional[Boolean] = None,
    throughput: Optional[Integer] = None,
    client_token: Optional[String] = None,
    volume_initialization_rate: Optional[Integer] = None,
    operator: Optional[OperatorRequest] = None,
    dry_run: Optional[Boolean] = None,
) -> Volume

Creates an EBS volume that can be attached to an instance in the same Availability Zone.

You can create a new empty volume or restore a volume from an EBS snapshot. Any Amazon Web Services Marketplace product codes from the snapshot are propagated to the volume.

You can create encrypted volumes. Encrypted volumes must be attached to instances that support Amazon EBS encryption. Volumes that are created from encrypted snapshots are also automatically encrypted. For more information, see Amazon EBS encryption in the Amazon EBS User Guide.

You can tag your volumes during creation. For more information, see Tag your Amazon EC2 resources in the Amazon EC2 User Guide.

For more information, see Create an Amazon EBS volume in the Amazon EBS User Guide.

Parameters:

  • availability_zone (Optional[AvailabilityZoneName], default: None ) –

    The ID of the Availability Zone in which to create the volume. For example, us-east-1a.

    Either AvailabilityZone or AvailabilityZoneId must be specified, but not both.

  • availability_zone_id (Optional[AvailabilityZoneId], default: None ) –

    The ID of the Availability Zone in which to create the volume. For example, use1-az1.

    Either AvailabilityZone or AvailabilityZoneId must be specified, but not both.

  • encrypted (Optional[Boolean], default: None ) –

    Indicates whether the volume should be encrypted. The effect of setting the encryption state to true depends on the volume origin (new or from a snapshot), starting encryption state, ownership, and whether encryption by default is enabled. For more information, see Encryption by default in the Amazon EBS User Guide.

    Encrypted Amazon EBS volumes must be attached to instances that support Amazon EBS encryption. For more information, see Supported instance types.

  • iops (Optional[Integer], default: None ) –

    The number of I/O operations per second (IOPS) to provision for the volume. Required for io1 and io2 volumes. Optional for gp3 volumes. Omit for all other volume types.

    Valid ranges:

    • gp3: 3,000 (default) - 80,000 IOPS

    • io1: 100 - 64,000 IOPS

    • io2: 100 - 256,000 IOPS

    Instances built on the Nitro System can support up to 256,000 IOPS. Other instances can support up to 32,000 IOPS.

  • kms_key_id (Optional[KmsKeyId], default: None ) –

    The identifier of the KMS key to use for Amazon EBS encryption. If this parameter is not specified, your KMS key for Amazon EBS is used. If KmsKeyId is specified, the encrypted state must be true.

    You can specify the KMS key using any of the following:

    • Key ID. For example, 1234abcd-12ab-34cd-56ef-1234567890ab.

    • Key alias. For example, alias/ExampleAlias.

    • Key ARN. For example, arn:aws:kms:us-east-1:012345678910:key/1234abcd-12ab-34cd-56ef-1234567890ab.

    • Alias ARN. For example, arn:aws:kms:us-east-1:012345678910:alias/ExampleAlias.

    Amazon Web Services authenticates the KMS key asynchronously. Therefore, if you specify an ID, alias, or ARN that is not valid, the action can appear to complete, but eventually fails.

  • outpost_arn (Optional[String], default: None ) –

    The Amazon Resource Name (ARN) of the Outpost on which to create the volume.

    If you intend to use a volume with an instance running on an outpost, then you must create the volume on the same outpost as the instance. You can't use a volume created in an Amazon Web Services Region with an instance on an Amazon Web Services outpost, or the other way around.

  • size (Optional[Integer], default: None ) –

    The size of the volume, in GiBs. You must specify either a snapshot ID or a volume size. If you specify a snapshot, the default is the snapshot size, and you can specify a volume size that is equal to or larger than the snapshot size.

    Valid sizes:

    • gp2: 1 - 16,384 GiB

    • gp3: 1 - 65,536 GiB

    • io1: 4 - 16,384 GiB

    • io2: 4 - 65,536 GiB

    • st1 and sc1: 125 - 16,384 GiB

    • standard: 1 - 1024 GiB

  • snapshot_id (Optional[SnapshotId], default: None ) –

    The snapshot from which to create the volume. You must specify either a snapshot ID or a volume size.

  • volume_type (Optional[VolumeType], default: None ) –

    The volume type. This parameter can be one of the following values:

    • General Purpose SSD: gp2 | gp3

    • Provisioned IOPS SSD: io1 | io2

    • Throughput Optimized HDD: st1

    • Cold HDD: sc1

    • Magnetic: standard

    Throughput Optimized HDD (st1) and Cold HDD (sc1) volumes can't be used as boot volumes.

    For more information, see Amazon EBS volume types in the Amazon EBS User Guide.

    Default: gp2

  • tag_specifications (Optional[TagSpecificationList], default: None ) –

    The tags to apply to the volume during creation.

  • multi_attach_enabled (Optional[Boolean], default: None ) –

    Indicates whether to enable Amazon EBS Multi-Attach. If you enable Multi-Attach, you can attach the volume to up to 16 Instances built on the Nitro System in the same Availability Zone. This parameter is supported with io1 and io2 volumes only. For more information, see Amazon EBS Multi-Attach in the Amazon EBS User Guide.

  • throughput (Optional[Integer], default: None ) –

    The throughput to provision for the volume, in MiB/s. Supported for gp3 volumes only. Omit for all other volume types.

    Valid Range: 125 - 2000 MiB/s

  • client_token (Optional[String], default: None ) –

    Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. For more information, see Ensure Idempotency.

  • volume_initialization_rate (Optional[Integer], default: None ) –

    Specifies the Amazon EBS Provisioned Rate for Volume Initialization (volume initialization rate), in MiB/s, at which to download the snapshot blocks from Amazon S3 to the volume. This is also known as volume initialization. Specifying a volume initialization rate ensures that the volume is initialized at a predictable and consistent rate after creation.

    This parameter is supported only for volumes created from snapshots. Omit this parameter if:

    • You want to create the volume using fast snapshot restore. You must specify a snapshot that is enabled for fast snapshot restore. In this case, the volume is fully initialized at creation.

      If you specify a snapshot that is enabled for fast snapshot restore and a volume initialization rate, the volume will be initialized at the specified rate instead of fast snapshot restore.

    • You want to create a volume that is initialized at the default rate.

    For more information, see Initialize Amazon EBS volumes in the Amazon EC2 User Guide.

    Valid range: 100 - 300 MiB/s

  • operator (Optional[OperatorRequest], default: None ) –

    Reserved for internal use.

  • dry_run (Optional[Boolean], default: None ) –

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Raises:

Examples:

To create a new Provisioned IOPS (SSD) volume from a snapshot This example creates a new Provisioned IOPS (SSD) volume with 1000 provisioned IOPS from a snapshot in the Availability Zone us-east-1a.

>>> client.create_volume(availability_zone='us-east-1a', iops=1000, volume_type='io1', snapshot_id='snap-066877671789bd71b')
To create a new volume
This example creates an 80 GiB General Purpose (SSD) volume in the Availability Zone ``us-east-1a``.
>>> client.create_volume(availability_zone='us-east-1a', size=80, volume_type='gp2')
Source code in docs_src/capo_ec2/_services/ec2.py
def create_volume(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    availability_zone: Optional[
        "capo_ec2.types.availability_zone_name.AvailabilityZoneName"
    ] = None,
    availability_zone_id: Optional[
        "capo_ec2.types.availability_zone_id.AvailabilityZoneId"
    ] = None,
    encrypted: Optional["capo_ec2.types.boolean.Boolean"] = None,
    iops: Optional["capo_ec2.types.integer.Integer"] = None,
    kms_key_id: Optional["capo_ec2.types.kms_key_id.KmsKeyId"] = None,
    outpost_arn: Optional["capo_ec2.types.string.String"] = None,
    size: Optional["capo_ec2.types.integer.Integer"] = None,
    snapshot_id: Optional["capo_ec2.types.snapshot_id.SnapshotId"] = None,
    volume_type: Optional["capo_ec2.types.volume_type.VolumeType"] = None,
    tag_specifications: Optional[
        "capo_ec2.types.tag_specification_list.TagSpecificationList"
    ] = None,
    multi_attach_enabled: Optional["capo_ec2.types.boolean.Boolean"] = None,
    throughput: Optional["capo_ec2.types.integer.Integer"] = None,
    client_token: Optional["capo_ec2.types.string.String"] = None,
    volume_initialization_rate: Optional["capo_ec2.types.integer.Integer"] = None,
    operator: Optional["capo_ec2.types.operator_request.OperatorRequest"] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> "capo_ec2.types.volume.Volume":
    """<p>Creates an EBS volume that can be attached to an instance in the same Availability Zone.</p> <p>You can create a new empty volume or restore a volume from an EBS snapshot. Any Amazon Web Services Marketplace product codes from the snapshot are propagated to the volume.</p> <p>You can create encrypted volumes. Encrypted volumes must be attached to instances that support Amazon EBS encryption. Volumes that are created from encrypted snapshots are also automatically encrypted. For more information, see <a href="https://docs.aws.amazon.com/ebs/latest/userguide/ebs-encryption.html">Amazon EBS encryption</a> in the <i>Amazon EBS User Guide</i>.</p> <p>You can tag your volumes during creation. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html">Tag your Amazon EC2 resources</a> in the <i>Amazon EC2 User Guide</i>.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/ebs/latest/userguide/ebs-creating-volume.html">Create an Amazon EBS volume</a> in the <i>Amazon EBS User Guide</i>.</p>

    Args:
        availability_zone: <p>The ID of the Availability Zone in which to create the volume. For example, <code>us-east-1a</code>.</p> <p>Either <code>AvailabilityZone</code> or <code>AvailabilityZoneId</code> must be specified, but not both.</p>
        availability_zone_id: <p>The ID of the Availability Zone in which to create the volume. For example, <code>use1-az1</code>.</p> <p>Either <code>AvailabilityZone</code> or <code>AvailabilityZoneId</code> must be specified, but not both.</p>
        encrypted: <p>Indicates whether the volume should be encrypted. The effect of setting the encryption state to <code>true</code> depends on the volume origin (new or from a snapshot), starting encryption state, ownership, and whether encryption by default is enabled. For more information, see <a href="https://docs.aws.amazon.com/ebs/latest/userguide/work-with-ebs-encr.html#encryption-by-default">Encryption by default</a> in the <i>Amazon EBS User Guide</i>.</p> <p>Encrypted Amazon EBS volumes must be attached to instances that support Amazon EBS encryption. For more information, see <a href="https://docs.aws.amazon.com/ebs/latest/userguide/ebs-encryption-requirements.html#ebs-encryption_supported_instances">Supported instance types</a>.</p>
        iops: <p>The number of I/O operations per second (IOPS) to provision for the volume. Required for <code>io1</code> and <code>io2</code> volumes. Optional for <code>gp3</code> volumes. Omit for all other volume types. </p> <p>Valid ranges:</p> <ul> <li> <p>gp3: <code>3,000 </code>(<i>default</i>)<code> - 80,000</code> IOPS</p> </li> <li> <p>io1: <code>100 - 64,000</code> IOPS</p> </li> <li> <p>io2: <code>100 - 256,000</code> IOPS</p> </li> </ul> <note> <p> <a href="https://docs.aws.amazon.com/ec2/latest/instancetypes/ec2-nitro-instances.html"> Instances built on the Nitro System</a> can support up to 256,000 IOPS. Other instances can support up to 32,000 IOPS.</p> </note>
        kms_key_id: <p>The identifier of the KMS key to use for Amazon EBS encryption. If this parameter is not specified, your KMS key for Amazon EBS is used. If <code>KmsKeyId</code> is specified, the encrypted state must be <code>true</code>.</p> <p>You can specify the KMS key using any of the following:</p> <ul> <li> <p>Key ID. For example, 1234abcd-12ab-34cd-56ef-1234567890ab.</p> </li> <li> <p>Key alias. For example, alias/ExampleAlias.</p> </li> <li> <p>Key ARN. For example, arn:aws:kms:us-east-1:012345678910:key/1234abcd-12ab-34cd-56ef-1234567890ab.</p> </li> <li> <p>Alias ARN. For example, arn:aws:kms:us-east-1:012345678910:alias/ExampleAlias.</p> </li> </ul> <p>Amazon Web Services authenticates the KMS key asynchronously. Therefore, if you specify an ID, alias, or ARN that is not valid, the action can appear to complete, but eventually fails.</p>
        outpost_arn: <p>The Amazon Resource Name (ARN) of the Outpost on which to create the volume.</p> <p>If you intend to use a volume with an instance running on an outpost, then you must create the volume on the same outpost as the instance. You can't use a volume created in an Amazon Web Services Region with an instance on an Amazon Web Services outpost, or the other way around.</p>
        size: <p>The size of the volume, in GiBs. You must specify either a snapshot ID or a volume size. If you specify a snapshot, the default is the snapshot size, and you can specify a volume size that is equal to or larger than the snapshot size.</p> <p>Valid sizes:</p> <ul> <li> <p>gp2: <code>1 - 16,384</code> GiB</p> </li> <li> <p>gp3: <code>1 - 65,536</code> GiB</p> </li> <li> <p>io1: <code>4 - 16,384</code> GiB</p> </li> <li> <p>io2: <code>4 - 65,536</code> GiB</p> </li> <li> <p>st1 and sc1: <code>125 - 16,384</code> GiB</p> </li> <li> <p>standard: <code>1 - 1024</code> GiB</p> </li> </ul>
        snapshot_id: <p>The snapshot from which to create the volume. You must specify either a snapshot ID or a volume size.</p>
        volume_type: <p>The volume type. This parameter can be one of the following values:</p> <ul> <li> <p>General Purpose SSD: <code>gp2</code> | <code>gp3</code> </p> </li> <li> <p>Provisioned IOPS SSD: <code>io1</code> | <code>io2</code> </p> </li> <li> <p>Throughput Optimized HDD: <code>st1</code> </p> </li> <li> <p>Cold HDD: <code>sc1</code> </p> </li> <li> <p>Magnetic: <code>standard</code> </p> </li> </ul> <important> <p>Throughput Optimized HDD (<code>st1</code>) and Cold HDD (<code>sc1</code>) volumes can't be used as boot volumes.</p> </important> <p>For more information, see <a href="https://docs.aws.amazon.com/ebs/latest/userguide/ebs-volume-types.html">Amazon EBS volume types</a> in the <i>Amazon EBS User Guide</i>.</p> <p>Default: <code>gp2</code> </p>
        tag_specifications: <p>The tags to apply to the volume during creation.</p>
        multi_attach_enabled: <p>Indicates whether to enable Amazon EBS Multi-Attach. If you enable Multi-Attach, you can attach the volume to up to 16 <a href="https://docs.aws.amazon.com/ec2/latest/instancetypes/ec2-nitro-instances.html">Instances built on the Nitro System</a> in the same Availability Zone. This parameter is supported with <code>io1</code> and <code>io2</code> volumes only. For more information, see <a href="https://docs.aws.amazon.com/ebs/latest/userguide/ebs-volumes-multi.html"> Amazon EBS Multi-Attach</a> in the <i>Amazon EBS User Guide</i>.</p>
        throughput: <p>The throughput to provision for the volume, in MiB/s. Supported for <code>gp3</code> volumes only. Omit for all other volume types.</p> <p>Valid Range: <code>125 - 2000</code> MiB/s</p>
        client_token: <p>Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. For more information, see <a href="https://docs.aws.amazon.com/ec2/latest/devguide/ec2-api-idempotency.html">Ensure Idempotency</a>.</p>
        volume_initialization_rate: <p>Specifies the Amazon EBS Provisioned Rate for Volume Initialization (volume initialization rate), in MiB/s, at which to download the snapshot blocks from Amazon S3 to the volume. This is also known as <i>volume initialization</i>. Specifying a volume initialization rate ensures that the volume is initialized at a predictable and consistent rate after creation.</p> <p>This parameter is supported only for volumes created from snapshots. Omit this parameter if:</p> <ul> <li> <p>You want to create the volume using fast snapshot restore. You must specify a snapshot that is enabled for fast snapshot restore. In this case, the volume is fully initialized at creation.</p> <note> <p>If you specify a snapshot that is enabled for fast snapshot restore and a volume initialization rate, the volume will be initialized at the specified rate instead of fast snapshot restore.</p> </note> </li> <li> <p>You want to create a volume that is initialized at the default rate.</p> </li> </ul> <p>For more information, see <a href="https://docs.aws.amazon.com/ebs/latest/userguide/initalize-volume.html"> Initialize Amazon EBS volumes</a> in the <i>Amazon EC2 User Guide</i>.</p> <p>Valid range: 100 - 300 MiB/s</p>
        operator: <p>Reserved for internal use.</p>
        dry_run: <p>Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To create a new Provisioned IOPS (SSD) volume from a snapshot
        This example creates a new Provisioned IOPS (SSD) volume with 1000 provisioned IOPS from a snapshot in the Availability Zone ``us-east-1a``.

        >>> client.create_volume(availability_zone='us-east-1a', iops=1000, volume_type='io1', snapshot_id='snap-066877671789bd71b')
        To create a new volume
        This example creates an 80 GiB General Purpose (SSD) volume in the Availability Zone ``us-east-1a``.

        >>> client.create_volume(availability_zone='us-east-1a', size=80, volume_type='gp2')
    """

    def _handler(
        req: "OperationRequest[capo_ec2.types.create_volume_request.CreateVolumeRequest]",
    ) -> OperationResponse["capo_ec2.types.volume.Volume"]:
        import capo_ec2._operations.amazon_ec2.create_volume

        output, http_response = (
            capo_ec2._operations.amazon_ec2.create_volume.create_volume(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateVolume")
    )
    input_: capo_ec2.types.create_volume_request.CreateVolumeRequest = {}
    if availability_zone is not None:
        input_["availability_zone"] = availability_zone
    if availability_zone_id is not None:
        input_["availability_zone_id"] = availability_zone_id
    if encrypted is not None:
        input_["encrypted"] = encrypted
    if iops is not None:
        input_["iops"] = iops
    if kms_key_id is not None:
        input_["kms_key_id"] = kms_key_id
    if outpost_arn is not None:
        input_["outpost_arn"] = outpost_arn
    if size is not None:
        input_["size"] = size
    if snapshot_id is not None:
        input_["snapshot_id"] = snapshot_id
    if volume_type is not None:
        input_["volume_type"] = volume_type
    if tag_specifications is not None:
        input_["tag_specifications"] = tag_specifications
    if multi_attach_enabled is not None:
        input_["multi_attach_enabled"] = multi_attach_enabled
    if throughput is not None:
        input_["throughput"] = throughput
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if volume_initialization_rate is not None:
        input_["volume_initialization_rate"] = volume_initialization_rate
    if operator is not None:
        input_["operator"] = operator
    if dry_run is not None:
        input_["dry_run"] = dry_run

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output