為什麼我無法刪除連接至 Amazon VPC 的安全群組?

2 分的閱讀內容
0

我在嘗試刪除 Amazon Virtual Private Cloud (Amazon VPC) 的安全群組時,收到錯誤。

解決方法

**注意:**如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本

當您嘗試刪除安全群組時,您可能會因以下原因收到錯誤。

此安全群組是預設安全群組

所有 Amazon VPC 都具有預設安全群組。如果未指定安全群組,則預設安全群組將自動與新啟動的 Amazon Elastic Compute Cloud (Amazon EC2) 執行個體關聯。

當您嘗試刪除預設安全群組時,會收到以下錯誤:

"error: Client.CannotDelete"

您無法刪除預設安全群組。但是,可以變更預設安全群組的規則。如需詳細資訊,請參閱適用於 VPC 的預設安全群組

安全群組規則會參考其自己的安全群組,或其他安全群組的規則參考它

您可能會收到錯誤,因為安全群組自己的規則會參考安全群組。若要解決此問題,請在刪除安全群組之前移除規則。

若要移除參考安全群組的規則,請完成以下步驟:

  1. 開啟 Amazon VPC 主控台
  2. 在導覽窗格中,選擇安全群組
  3. 選取您想要更新的安全群組。
  4. 選擇動作編輯輸入規則動作編輯輸出規則
  5. 為您想要刪除的規則選擇刪除
  6. 選擇儲存規則

如需有關更新安全群組規則的詳細資訊,請參閱安全群組規則

當您嘗試刪除其他安全群組規則參考的安全群組時,您會收到以下錯誤:

"An error occurred (DependencyViolation) when calling the DeleteSecurityGroup operation: resource sg-xyz has a dependent object"

如果其他安全群組的規則參考您要刪除的安全群組,請先移除該規則,然後再刪除安全群組。

位於已建立對等互連的其他 Amazon VPC 中的安全群組可能參考您想要刪除的安全群組。在刪除此安全群組之前,移除規則或刪除 Amazon VPC 對等互連

**注意:**使用 DescribeSecurityGroupReferences API 說明參考安全群組的 Amazon VPC 對等互連的另一端。

安全群組與 AWS 資源關聯

您無法刪除與 AWS 資源關聯的安全群組,例如 Amazon EC2 執行個體或 Amazon API Gateway VPC 連結。

如果您收到下列錯誤:

"Some security groups can't be deleted.The following security groups can't be deleted.These security groups are the default security groups, referenced by other security groups, or are associated with instances or network interfaces."

若要判斷哪些資源使用安全群組,請參閱如何找到與 Amazon EC2 安全群組關聯的資源?

重要:建立 VPC 連結後,無法變更其安全群組或子網路。

若要變更指派給執行個體的安全群組,請參閱使用安全群組

安全群組與網路介面關聯

您無法刪除與請求者-管理的網路介面關聯的安全群組。系統會自動為管理資源 (例如 Application Load Balancer 節點) 建立請求者管理的網路介面。某些 AWS 服務和資源具有始終連接至彈性網路介面的安全群組。這些範例包括 AWS Lambda、Amazon FSx、Amazon ElastiCache for Redis 和 ElastiCache for Memcached。

若要刪除或分開網路介面,請參閱刪除網路介面

您無法刪除與 Amazon VPC 端點上使用的網路介面關聯的安全群組。

當您嘗試刪除安全群組時,會收到以下錯誤:

"An error occurred (DependencyViolation) when calling the DeleteSecurityGroup operation: resource sg-xyz has a dependent object"

若要從介面端點移除或取代安全群組,請完成以下步驟:

  1. 開啟 Amazon VPC 主控台
  2. 在導覽窗格中,選擇端點
  3. 選取介面端點,然後選擇動作管理安全群組
  4. 選取或清除安全群組,然後選擇儲存

執行 describe-network-interfaces AWS CLI 命令,尋找與安全群組關聯的網路介面。將 <group-id> 取代為您的安全群組 ID,並將 <region> 取代為您的 AWS 區域:

aws ec2 describe-network-interfaces --filters Name=group-id,Values=<group-id> --region <region> --output json

檢閱命令輸出。如果輸出為空,則沒有資源與安全群組關聯。

範例命令輸出:

{
    "NetworkInterfaces": []
}

您未獲授權,無法執行 DeleteSecurityGroup 作業

您必須設定適當的 AWS Identity and Access Management (IAM) 許可,才能使用 DeleteSecurityGroup API。

**重要:**當您想要刪除的安全群組與執行個體關聯或被其他安全群組參考時,DeleteSecurityGroup API 會失敗。在這些情況下,操作會失敗,並出現 DependencyViolation 錯誤。

當您嘗試刪除安全群組,但沒有正確的許可時,會收到以下錯誤:

"Failed to delete security groups.An unknown error happened.You are not authorized to perform "DeleteSecurityGroup" operation"

若要對 DeleteSecurityGroup 操作錯誤進行疑難排解,請完成以下步驟:

  1. 開啟 AWS CloudTrail 主控台
  2. 在導覽窗格中,選取事件歷史記錄
  3. 查詢屬性下拉清單中,選擇事件名稱
  4. 在搜尋方塊中,輸入 DeleteSecurityGroup 以查看操作的 API 呼叫。
  5. 事件歷史記錄清單中的此錯誤訊息指出該錯誤與 IAM 許可有關:
    "You are not authorized to perform this operation."
  6. 確認已將 DeleteSecurityGroup 動作新增至刪除該動作的使用者或角色所需的 AWS IAM 政策中。
    如需詳細資訊,請參閱新增和移除 IAM 身分許可
  7. 在 AWS Organizations 中,變更組織的服務控制政策 (SCP)。然後,變更 IAM 使用者或角色的許可。
    **注意:**如果您不是主要帳戶擁有者,請要求主要帳戶擁有者變更 SCP。

如需有關 SCP 的詳細資訊,請參閱 SCP 對許可的影響

使用者無法刪除 VPC 擁有者建立的安全群組

當您嘗試刪除不擁有的共用 Amazon VPC 中的安全群組時,會收到以下錯誤:

"You are not authorized to perform DeleteSecurityGroup operation.A subnet in this vpc is shared but the provided object is not owned by you."

若要對 DeleteSecurityGroup 操作錯誤進行疑難排解,請完成以下步驟:

  1. 開啟 AWS CloudTrail 主控台
  2. 在導覽窗格中,選取事件歷史記錄
  3. 查詢屬性下拉清單中,選擇事件名稱
  4. 在搜尋方塊中,輸入 DeleteSecurityGroup 以查看操作的 API 呼叫。
  5. 確認您的帳戶不擁有安全群組。如果組織中的另一個帳戶擁有安全群組,請要求主要擁有者刪除安全群組。

相關資訊

如何刪除與其他 AWS 帳戶共用的 VPC?

AWS 官方
AWS 官方已更新 7 個月前