

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# AWS EBS Direct 的 SDK 代码示例 APIs
<a name="sdk"></a>

以下代码示例演示如何将 EBS 直接 APIs 与 AWS 软件开发套件 (SDK) 配合使用。

**Topics**
+ [StartSnapshot](#sdk-StartSnapshot)
+ [PutSnapshotBlock](#sdk-PutSnapshotBlock)
+ [CompleteSnapshot](#sdk-CompleteSnapshot)

## `StartSnapshot`与 AWS SDK 或 CLI 配合使用
<a name="sdk-StartSnapshot"></a>

以下代码示例演示了如何使用 `StartSnapshot`。

------
#### [ Rust ]

**适用于 Rust 的 SDK**  
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/rustv1/examples/ebs#code-examples)中查找完整示例，了解如何进行设置和运行。

```
async fn start(client: &Client, description: &str) -> Result<String, Error> {
    let snapshot = client
        .start_snapshot()
        .description(description)
        .encrypted(false)
        .volume_size(1)
        .send()
        .await?;

    Ok(snapshot.snapshot_id.unwrap())
}
```
+  有关 API 的详细信息，请参阅适用[StartSnapshot](https://docs.rs/aws-sdk-ebs/latest/aws_sdk_ebs/client/struct.Client.html#method.start_snapshot)于 *Rust 的AWS SDK API 参考*。

------

## `PutSnapshotBlock`与 AWS SDK 或 CLI 配合使用
<a name="sdk-PutSnapshotBlock"></a>

以下代码示例演示了如何使用 `PutSnapshotBlock`。

------
#### [ Rust ]

**适用于 Rust 的 SDK**  
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/rustv1/examples/ebs#code-examples)中查找完整示例，了解如何进行设置和运行。

```
async fn add_block(
    client: &Client,
    id: &str,
    idx: usize,
    block: Vec<u8>,
    checksum: &str,
) -> Result<(), Error> {
    client
        .put_snapshot_block()
        .snapshot_id(id)
        .block_index(idx as i32)
        .block_data(ByteStream::from(block))
        .checksum(checksum)
        .checksum_algorithm(ChecksumAlgorithm::ChecksumAlgorithmSha256)
        .data_length(EBS_BLOCK_SIZE as i32)
        .send()
        .await?;

    Ok(())
}
```
+  有关 API 的详细信息，请参阅适用[PutSnapshotBlock](https://docs.rs/aws-sdk-ebs/latest/aws_sdk_ebs/client/struct.Client.html#method.put_snapshot_block)于 *Rust 的AWS SDK API 参考*。

------

## `CompleteSnapshot`与 AWS SDK 或 CLI 配合使用
<a name="sdk-CompleteSnapshot"></a>

以下代码示例演示了如何使用 `CompleteSnapshot`。

------
#### [ Rust ]

**适用于 Rust 的 SDK**  
 还有更多相关信息 GitHub。在 [AWS 代码示例存储库](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/rustv1/examples/ebs#code-examples)中查找完整示例，了解如何进行设置和运行。

```
async fn finish(client: &Client, id: &str) -> Result<(), Error> {
    client
        .complete_snapshot()
        .changed_blocks_count(2)
        .snapshot_id(id)
        .send()
        .await?;

    println!("Snapshot ID {}", id);
    println!("The state is 'completed' when all of the modified blocks have been transferred to Amazon S3.");
    println!("Use the get-snapshot-state code example to get the state of the snapshot.");

    Ok(())
}
```
+  有关 API 的详细信息，请参阅适用[CompleteSnapshot](https://docs.rs/aws-sdk-ebs/latest/aws_sdk_ebs/client/struct.Client.html#method.complete_snapshot)于 *Rust 的AWS SDK API 参考*。

------