

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# `DeleteSnapshot` 搭配 AWS SDK 或 CLI 使用
<a name="example_ec2_DeleteSnapshot_section"></a>

下列程式碼範例示範如何使用 `DeleteSnapshot`。

------
#### [ CLI ]

**AWS CLI**  
**刪除快照**  
此範例命令會刪除快照 ID 為 `snap-1234567890abcdef0` 的快照。如果命令成功，則不會傳回任何輸出。  
命令：  

```
aws ec2 delete-snapshot --snapshot-id snap-1234567890abcdef0
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteSnapshot](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/delete-snapshot.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例會刪除指定的快照。除非也指定 Force 參數，否則在繼續操作之前，系統會提示您確認。**  

```
Remove-EC2Snapshot -SnapshotId snap-12345678
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-EC2Snapshot (DeleteSnapshot)" on target "snap-12345678".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [DeleteSnapshot](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例會刪除指定的快照。除非也指定 Force 參數，否則在繼續操作之前，系統會提示您確認。**  

```
Remove-EC2Snapshot -SnapshotId snap-12345678
```
**輸出：**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-EC2Snapshot (DeleteSnapshot)" on target "snap-12345678".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DeleteSnapshot](https://docs.aws.amazon.com/powershell/v5/reference)。

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

**適用於 Rust 的 SDK**  
 GitHub 上提供更多範例。尋找完整範例，並了解如何在 [AWS 程式碼範例儲存庫](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/rustv1/examples/ebs#code-examples)中設定和執行。

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

    println!("Deleted");

    Ok(())
}
```
+  如需 API 詳細資訊，請參閱《適用於 Rust 的 AWS  SDK API 參考》**中的 [DeleteSnapshot](https://docs.rs/aws-sdk-ec2/latest/aws_sdk_ec2/client/struct.Client.html#method.delete_snapshot)。

------

如需 AWS SDK 開發人員指南和程式碼範例的完整清單，請參閱 [使用 SDK 建立 Amazon EC2 資源 AWS](sdk-general-information-section.md)。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。