Skip to content

put_snapshot_block async

put_snapshot_block(
    snapshot_id: SnapshotId,
    block_index: BlockIndex,
    block_data: Body[AsyncIterator[bytes]] | AsyncIterator[bytes] | bytes,
    data_length: DataLength,
    checksum: Checksum,
    checksum_algorithm: ChecksumAlgorithm,
    *,
    config_overrides: Optional[AsyncEBSClientConfig] = None,
    progress: Optional[Progress] = None,
) -> PutSnapshotBlockResponse

Writes a block of data to a snapshot. If the specified block contains data, the existing data is overwritten. The target snapshot must be in the pending state.

Data written to a snapshot must be aligned with 512-KiB sectors.

You should always retry requests that receive server (5xx) error responses, and ThrottlingException and RequestThrottledException client error responses. For more information see Error retries in the Amazon Elastic Compute Cloud User Guide.

Parameters:

  • snapshot_id (SnapshotId) –

    The ID of the snapshot.

    If the specified snapshot is encrypted, you must have permission to use the KMS key that was used to encrypt the snapshot. For more information, see Using encryption in the Amazon Elastic Compute Cloud User Guide..

  • block_index (BlockIndex) –

    The block index of the block in which to write the data. A block index is a logical index in units of 512 KiB blocks. To identify the block index, divide the logical offset of the data in the logical volume by the block size (logical offset of data/524288). The logical offset of the data must be 512 KiB aligned.

  • block_data (Body[AsyncIterator[bytes]] | AsyncIterator[bytes] | bytes) –

    The data to write to the block.

    The block data is not signed as part of the Signature Version 4 signing process. As a result, you must generate and provide a Base64-encoded SHA256 checksum for the block data using the x-amz-Checksum header. Also, you must specify the checksum algorithm using the x-amz-Checksum-Algorithm header. The checksum that you provide is part of the Signature Version 4 signing process. It is validated against a checksum generated by Amazon EBS to ensure the validity and authenticity of the data. If the checksums do not correspond, the request fails. For more information, see Using checksums with the EBS direct APIs in the Amazon Elastic Compute Cloud User Guide.

  • data_length (DataLength) –

    The size of the data to write to the block, in bytes. Currently, the only supported size is 524288 bytes.

    Valid values: 524288

  • progress (Optional[Progress], default: None ) –

    The progress of the write process, as a percentage.

  • checksum (Checksum) –

    A Base64-encoded SHA256 checksum of the data. Only SHA256 checksums are supported.

  • checksum_algorithm (ChecksumAlgorithm) –

    The algorithm used to generate the checksum. Currently, the only supported algorithm is SHA256.

Raises:

Source code in docs_src/capo_ebs/_services/async_ebs.py
async def put_snapshot_block(
    self,
    snapshot_id: "capo_ebs.types.snapshot_id.SnapshotId",
    block_index: "capo_ebs.types.block_index.BlockIndex",
    block_data: Body[AsyncIterator[bytes]] | AsyncIterator[bytes] | bytes,
    data_length: "capo_ebs.types.data_length.DataLength",
    checksum: "capo_ebs.types.checksum.Checksum",
    checksum_algorithm: "capo_ebs.types.checksum_algorithm.ChecksumAlgorithm",
    *,
    config_overrides: Optional[AsyncEBSClientConfig] = None,
    progress: Optional["capo_ebs.types.progress.Progress"] = None,
) -> "capo_ebs.types.put_snapshot_block_response.PutSnapshotBlockResponse":
    """<p>Writes a block of data to a snapshot. If the specified block contains data, the existing data is overwritten. The target snapshot must be in the <code>pending</code> state.</p> <p>Data written to a snapshot must be aligned with 512-KiB sectors.</p> <note> <p>You should always retry requests that receive server (<code>5xx</code>) error responses, and <code>ThrottlingException</code> and <code>RequestThrottledException</code> client error responses. For more information see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/error-retries.html">Error retries</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>.</p> </note>

    Args:
        snapshot_id: <p>The ID of the snapshot.</p> <important> <p>If the specified snapshot is encrypted, you must have permission to use the KMS key that was used to encrypt the snapshot. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebsapis-using-encryption.html"> Using encryption</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>..</p> </important>
        block_index: <p>The block index of the block in which to write the data. A block index is a logical index in units of <code>512</code> KiB blocks. To identify the block index, divide the logical offset of the data in the logical volume by the block size (logical offset of data/<code>524288</code>). The logical offset of the data must be <code>512</code> KiB aligned.</p>
        block_data: <p>The data to write to the block.</p> <p>The block data is not signed as part of the Signature Version 4 signing process. As a result, you must generate and provide a Base64-encoded SHA256 checksum for the block data using the <b>x-amz-Checksum</b> header. Also, you must specify the checksum algorithm using the <b>x-amz-Checksum-Algorithm</b> header. The checksum that you provide is part of the Signature Version 4 signing process. It is validated against a checksum generated by Amazon EBS to ensure the validity and authenticity of the data. If the checksums do not correspond, the request fails. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-accessing-snapshot.html#ebsapis-using-checksums"> Using checksums with the EBS direct APIs</a> in the <i>Amazon Elastic Compute Cloud User Guide</i>.</p>
        data_length: <p>The size of the data to write to the block, in bytes. Currently, the only supported size is <code>524288</code> bytes.</p> <p>Valid values: <code>524288</code> </p>
        progress: <p>The progress of the write process, as a percentage.</p>
        checksum: <p>A Base64-encoded SHA256 checksum of the data. Only SHA256 checksums are supported.</p>
        checksum_algorithm: <p>The algorithm used to generate the checksum. Currently, the only supported algorithm is <code>SHA256</code>.</p>

    Raises:
        capo_ebs.errors.access_denied_exception.AccessDeniedException: <p>You do not have sufficient access to perform this action.</p>
        capo_ebs.errors.internal_server_exception.InternalServerException: <p>An internal error has occurred. For more information see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/error-retries.html">Error retries</a>.</p>
        capo_ebs.errors.request_throttled_exception.RequestThrottledException: <p>The number of API requests has exceeded the maximum allowed API request throttling limit for the snapshot. For more information see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/error-retries.html">Error retries</a>.</p>
        capo_ebs.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource does not exist.</p>
        capo_ebs.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>Your current service quotas do not allow you to perform this action.</p>
        capo_ebs.errors.validation_exception.ValidationException: <p>The input fails to satisfy the constraints of the EBS direct APIs.</p>
        capo_ebs.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ebs.types.put_snapshot_block_request.PutSnapshotBlockRequest]",
    ) -> AsyncOperationResponse[
        "capo_ebs.types.put_snapshot_block_response.PutSnapshotBlockResponse"
    ]:
        import capo_ebs._operations.ebs.put_snapshot_block

        (
            output,
            http_response,
        ) = await capo_ebs._operations.ebs.put_snapshot_block.async_put_snapshot_block(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_ebs.types.put_snapshot_block_request.PutSnapshotBlockRequest",
    ) -> dict[str, Any]:
        import capo_ebs.types.put_snapshot_block_request

        return capo_ebs.types.put_snapshot_block_request.redact_sensitive(input_)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("PutSnapshotBlock", redact_input=_redact_input),
    )
    input_: capo_ebs.types.put_snapshot_block_request.PutSnapshotBlockRequest = {
        "snapshot_id": snapshot_id,
        "block_index": block_index,
        "block_data": ensure_async_iterator(block_data),
        "data_length": data_length,
        "checksum": checksum,
        "checksum_algorithm": checksum_algorithm,
    }
    if progress is not None:
        input_["progress"] = progress

    async with aclosing_bodies(input_):
        response = await aexecute_pipeline(
            AsyncOperationRequest(input=input_, options=options_),
            handler=_handler,
            interceptors=list(interceptors_),
        )
        await response.response.aclose()
        return response.output