如何解決 CloudFormation 中的變更集錯誤?
當我嘗試將資源匯入 AWS CloudFormation 堆疊時,我收到錯誤訊息。
解決方法
根據您的錯誤類型,完成相關章節中的步驟以對該錯誤進行疑難排解。
注意: 如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請參閱對 AWS CLI 錯誤進行疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本。
修改後的輸出錯誤
兩個範本中的 Outputs (輸出) 區段必須相同。如果您透過 CloudFormation 主控台,使用具有資源匯入範本且包含輸出的範本建立新堆疊,則您會收到類似以下的錯誤:
「There was an error creating this change set.As part of the import operation, you cannot modify or add [Outputs]」
當您嘗試將資源匯入堆疊時,也會發生此錯誤。
若要解決此錯誤,請確保最新 AWS CloudFormation 範本的 Outputs (輸出) 區段,與您堆疊目前使用的範本相符。如果值不相同,請更新最新範本,使其符合目前範本中 Outputs (輸出) 區段的值與輸出。
重要: 匯入作業不可包含對 Logical ID (邏輯 ID)、Description (說明)、Value (值)、Export (匯出) 或 Outputs (輸出) 的新增與修改。
在匯入作業完成後,請使用 Outputs (輸出) 組態中的變更來更新堆疊。或者,您可以自動將 AWS 資源匯入 CloudFormation 堆疊。
堆疊屬性的驗證錯誤
如果您使用 AWS CLI 或 AWS SDK 建立包含修改或新增堆疊屬性的 IMPORT (匯入) 類型變更集,則您會收到類似以下內容的錯誤:
「An error occurred (ValidationError) when calling the CreateChangeSet operation: As part of the import operation, you cannot modify or add [Tags]」
當您的 IMPORT (匯入) 類型變更集包含修改後的堆疊屬性時,就會發生此錯誤。
若要解決此錯誤,請確認用於建立變更集作業所包含的堆疊屬性與堆疊目前的屬性值相符。
重要: 請勿更新或新增新的屬性值。
在您匯入資源後,請於個別的更新作業中更新您的屬性。或者,您可以自動將 AWS 資源匯入 CloudFormation 堆疊。
修改後的資源錯誤
在匯入作業期間,您無法建立、更新或刪除資源。如果您在資源匯入作業期間修改現有資源,則您會收到類似以下的錯誤:
「There was an error creating this change set.You have modified resources [ResourceName] in your template that are not being imported.Update, create or delete operations cannot be executed during import operations.」
若要解決此錯誤,請建立 UPDATE (更新) 類型變更集,而非 IMPORT (匯入) 類型變更集。這會顯示資源中變更的來源。然後,對現有資源使用相同的 Resources (資源) 規格,並僅將要匯入的適當資源加入範本。或者,您可以自動將 AWS 資源匯入 CloudFormation 堆疊。
待匯入資源清單錯誤
如果您使用 AWS CLI 或 AWS SDK 建立 IMPORT (匯入) 類型變更集,則您會收到以下其中一個錯誤訊息:
「An error occurred (ValidationError) when calling the CreateChangeSet operation: Resources [<ResourceName>] is missing from ResourceToImport list」
「Error: 「An error occurred (ValidationError) when calling the CreateChangeSet operation: Must Provide at least one resource to import」
若要解決此錯誤,請驗證您是否在 AWS CLI 命令的 --resources-to-import 屬性中傳遞了實體 ID。或者,在 CreateChangeSet API 中,對您要匯入堆疊的資源使用 ResourceToImport 屬性。
為了進行匯入,您必須將實體 ID 傳送至新資源。若要解決此錯誤,請驗證您是否在 AWS CLI 命令中包含 --resources-to-import,或在 API 呼叫中包含 ResourceToImport。另外,請確認您已列出要匯入的資源。
IAM 功能錯誤
如果您的變更集包含您沒有權限的 IAM 資源,則您會收到以下其中一個錯誤訊息:
「Error: Failed to create changeset for the stack: <StackName>, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state: For expression "Status" we matched expected path: "FAILED" Status: FAILED.Reason: Requires capabilities: [CAPABILITY_NAMED_IAM]」
「When calling the CreateChangeSet operation: Requires capabilities : [CAPABILITY_IAM/CAPABILITY_NAMED_IAM]」
「Please acknowledge all checkboxes before proceeding.」
若要解決此錯誤,請完成以下步驟:
- 開啟 CloudFormation console (CloudFormation 主控台)。
- 選擇使用現有資源 Create stack (建立堆疊) 或 Update stack (更新堆疊)。
- 繼續前往 Review (檢閱) 頁面,然後選擇 I acknowledge that AWS CloudFormation might create IAM resources (我確認 AWS CloudFormation 可能會建立 IAM 資源) / I acknowledge that AWS CloudFormation might create IAM resources with custom names (我確認 AWS CloudFormation 可能會使用自訂名稱建立 IAM 資源)。
-或-
使用 create-stack 與 update-stack AWS CLI 命令,為 --capabilities 參數指定 CAPABILITY_IAM 或 CAPABILITY_NAMED_IAM 值。
注意: 如果您的 CloudFormation 範本包含 AWS Identity and Access Management (IAM) 資源,則您必須核准 CAPABILITY_IAM。如果您的範本包含 IAM 資源的自訂名稱,則您必須核准 CAPABILITY_NAMED_IAM。如需更多資訊,請參閱 AWS CloudFormation 部署動作參考的功能區段。
更新堆疊作業期間出現「Submitted information didn't contain changes」錯誤
如果您在更新堆疊作業期間使用相同的堆疊範本,則您會收到以下其中一個錯誤訊息:
「The submitted information didn't contain changes.Submit different information to create a change set」
「An error occurred (ValidationError) when calling the UpdateStack operation: No updates are to be performed.」
若要解決此錯誤,請採取以下行動:
- 確認您已對堆疊進行變更。CloudFormation 不會將對 Parameters (參數) 或 Stack Description (堆疊說明) 的修改視為對堆疊範本的變更。
- 確保資源有實質性的變更。例如,如果您想為堆疊新增說明,請在下次更新堆疊中其他資源時進行變更。
- 進行實質性變更 (例如修改堆疊標籤),以觸發堆疊的變更偵測。例如,如果您僅在範本中新增 Description (說明),則可能會收到錯誤。然而,如果您在建立變更集時同時修改堆疊標籤,則不會收到錯誤。
- 將自訂中繼資料新增至資源,以啟用變更。
範例範本:
注意: 將 MyResourceType 替換為您的資源類型,並將 MyResourceProperties 替換為您的資源屬性。Description: This description is the cause of the error when only updating this field. Resources: myResource: Type: MyResourceType Properties: MyResourceProperties Metadata: ### ADD THIS CUSTOM METADATA test: 1 ### ANY KEY-VALUE PAIR
如果您仍無法更新您的堆疊,請聯絡 AWS Support。
ExecuteChangeSet API 呼叫錯誤
您無法同時在 CreateChangeSet API 中使用 OnStackFailure 參數,並在 ExecuteChangeSet API 中使用 DisableRollback 參數。
「Either DisableRollback or OnStackFailure can be specified, but not both.Validation error as OnStackFailure parameter was specified during CreateChangeSet.」
若要解決此錯誤,請確認您未同時使用這兩個參數。
主控台上變更集的輸入與格式不符錯誤
如果您在 CloudFormation 範本中使用了格式不正確的 AWS Secrets Manager 動態參考,則您會收到以下其中一個錯誤:
「Given input did not match expected format」
「Incorrect format is used in the following SSM reference」
若要解決此錯誤,請確保您遵循 Secrets Manager 動態參考的最佳實務。如需更多資訊,請參閱使用動態參考取得儲存在其他服務中的值。
相關資訊
- 語言
- 中文 (繁體)

相關內容
已提問 2 年前
已提問 3 年前