本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
下列程式碼範例示範如何搭配 AWS 軟體開發套件 (SDK) 使用 EBS 直接 APIs。
StartSnapshot
搭配 AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 StartSnapshot
。
- SDK for Rust
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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 詳細資訊,請參閱《適用於 AWS Rust 的 SDK API 參考》中的 StartSnapshot
。
-
PutSnapshotBlock
搭配 AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 PutSnapshotBlock
。
- SDK for Rust
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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 詳細資訊,請參閱《適用於 AWS Rust 的 SDK API 參考》中的 PutSnapshotBlock
。
-
CompleteSnapshot
搭配 AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 CompleteSnapshot
。
- SDK for Rust
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 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 詳細資訊,請參閱《適用於 AWS Rust 的 SDK API 參考》中的 CompleteSnapshot
。
-