Skip to content

create_replace_root_volume_task

create_replace_root_volume_task(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    instance_id: Optional[InstanceId] = None,
    snapshot_id: Optional[SnapshotId] = None,
    client_token: Optional[String] = None,
    dry_run: Optional[Boolean] = None,
    tag_specifications: Optional[TagSpecificationList] = None,
    image_id: Optional[ImageId] = None,
    delete_replaced_root_volume: Optional[Boolean] = None,
    volume_initialization_rate: Optional[Long] = None,
    volume_id: Optional[VolumeId] = None,
) -> CreateReplaceRootVolumeTaskResult

Replaces the EBS-backed root volume for a running instance with a new volume that is restored to the original root volume's launch state, that is restored to a specific snapshot taken from the original root volume, that is restored from an AMI that has the same key characteristics as that of the instance, or that is replaced by a specified volume.

For more information, see Replace a root volume in the Amazon EC2 User Guide.

Parameters:

  • instance_id (Optional[InstanceId], default: None ) –

    The ID of the instance for which to replace the root volume.

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

    The ID of the snapshot from which to restore the replacement root volume. The specified snapshot must be a snapshot that you previously created from the original root volume.

    If you want to restore the replacement root volume to the initial launch state, if you want to restore the replacement root volume from an AMI, or if you want to replace the root volume with a specified volume, omit this parameter.

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

    Unique, case-sensitive identifier you provide to ensure the idempotency of the request. If you do not specify a client token, a randomly generated token is used for the request to ensure idempotency. For more information, see Ensuring idempotency.

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

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

    The tags to apply to the root volume replacement task.

  • image_id (Optional[ImageId], default: None ) –

    The ID of the AMI to use to restore the root volume. The specified AMI must have the same product code, billing information, architecture type, and virtualization type as that of the instance.

    If you want to restore the replacement volume from a specific snapshot, if you want to restore it to its launch state, or if you want to replace the root volume with a specified volume, omit this parameter.

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

    Indicates whether to automatically delete the original root volume after the root volume replacement task completes. To delete the original root volume, specify true. If you choose to keep the original root volume after the replacement task completes, you must manually delete it when you no longer need it.

  • volume_initialization_rate (Optional[Long], 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 replacement root 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.

    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

  • volume_id (Optional[VolumeId], default: None ) –

    The ID of the volume to use as the replacement root volume. The specified volume must be in the same Availability Zone as the instance, must be in the available state, and must not be attached to an instance. If the original root volume is encrypted, the specified volume must also be encrypted.

    If you want to restore the replacement root volume from a specific snapshot, an AMI, or to its launch state, omit this parameter.

Raises:

Source code in docs_src/capo_ec2/_services/ec2.py
def create_replace_root_volume_task(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    instance_id: Optional["capo_ec2.types.instance_id.InstanceId"] = None,
    snapshot_id: Optional["capo_ec2.types.snapshot_id.SnapshotId"] = None,
    client_token: Optional["capo_ec2.types.string.String"] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    tag_specifications: Optional[
        "capo_ec2.types.tag_specification_list.TagSpecificationList"
    ] = None,
    image_id: Optional["capo_ec2.types.image_id.ImageId"] = None,
    delete_replaced_root_volume: Optional["capo_ec2.types.boolean.Boolean"] = None,
    volume_initialization_rate: Optional["capo_ec2.types.long.Long"] = None,
    volume_id: Optional["capo_ec2.types.volume_id.VolumeId"] = None,
) -> "capo_ec2.types.create_replace_root_volume_task_result.CreateReplaceRootVolumeTaskResult":
    """<p>Replaces the EBS-backed root volume for a <code>running</code> instance with a new volume that is restored to the original root volume's launch state, that is restored to a specific snapshot taken from the original root volume, that is restored from an AMI that has the same key characteristics as that of the instance, or that is replaced by a specified volume.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/replace-root.html">Replace a root volume</a> in the <i>Amazon EC2 User Guide</i>.</p>

    Args:
        instance_id: <p>The ID of the instance for which to replace the root volume.</p>
        snapshot_id: <p>The ID of the snapshot from which to restore the replacement root volume. The specified snapshot must be a snapshot that you previously created from the original root volume.</p> <p>If you want to restore the replacement root volume to the initial launch state, if you want to restore the replacement root volume from an AMI, or if you want to replace the root volume with a specified volume, omit this parameter.</p>
        client_token: <p>Unique, case-sensitive identifier you provide to ensure the idempotency of the request. If you do not specify a client token, a randomly generated token is used for the request to ensure idempotency. For more information, see <a href="https://docs.aws.amazon.com/ec2/latest/devguide/ec2-api-idempotency.html">Ensuring idempotency</a>.</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>
        tag_specifications: <p>The tags to apply to the root volume replacement task.</p>
        image_id: <p>The ID of the AMI to use to restore the root volume. The specified AMI must have the same product code, billing information, architecture type, and virtualization type as that of the instance.</p> <p>If you want to restore the replacement volume from a specific snapshot, if you want to restore it to its launch state, or if you want to replace the root volume with a specified volume, omit this parameter.</p>
        delete_replaced_root_volume: <p>Indicates whether to automatically delete the original root volume after the root volume replacement task completes. To delete the original root volume, specify <code>true</code>. If you choose to keep the original root volume after the replacement task completes, you must manually delete it when you no longer need it.</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 replacement root 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>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>
        volume_id: <p>The ID of the volume to use as the replacement root volume. The specified volume must be in the same Availability Zone as the instance, must be in the <code>available</code> state, and must not be attached to an instance. If the original root volume is encrypted, the specified volume must also be encrypted.</p> <p>If you want to restore the replacement root volume from a specific snapshot, an AMI, or to its launch state, omit this parameter.</p>

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

    def _handler(
        req: "OperationRequest[capo_ec2.types.create_replace_root_volume_task_request.CreateReplaceRootVolumeTaskRequest]",
    ) -> OperationResponse[
        "capo_ec2.types.create_replace_root_volume_task_result.CreateReplaceRootVolumeTaskResult"
    ]:
        import capo_ec2._operations.amazon_ec2.create_replace_root_volume_task

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateReplaceRootVolumeTask")
    )
    input_: capo_ec2.types.create_replace_root_volume_task_request.CreateReplaceRootVolumeTaskRequest = {}
    if instance_id is not None:
        input_["instance_id"] = instance_id
    if snapshot_id is not None:
        input_["snapshot_id"] = snapshot_id
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if tag_specifications is not None:
        input_["tag_specifications"] = tag_specifications
    if image_id is not None:
        input_["image_id"] = image_id
    if delete_replaced_root_volume is not None:
        input_["delete_replaced_root_volume"] = delete_replaced_root_volume
    if volume_initialization_rate is not None:
        input_["volume_initialization_rate"] = volume_initialization_rate
    if volume_id is not None:
        input_["volume_id"] = volume_id

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