如何解決 CloudFormation 中的「模型驗證失敗 (#:不允許無關的鍵值 [Key])」錯誤?
我在堆疊事件中收到「模型驗證失敗 (#:不允許無關的鍵值 [Key])」錯誤。當我使用自訂資源提供者搭配 AWS CloudFormation 命令列介面 (CLI) 建立資源時,發生此錯誤。
簡短說明
當您嘗試使用資源提供者搭配屬性建立資源時,收到這個錯誤。不過,您尚未在資源提供者結構描述中定義一或多個屬性,或者您正在使用保留的屬性。
如果您遇到與使用資源提供者相關的其他錯誤問題,請參閱下列文章,以了解其他疑難排解步驟:
- 如何解決在 AWS CloudFormation 中使用 CloudFormation CLI 執行 cfn generate 命令時出現的「資源規格無效」錯誤?
- 如何解決在 AWS CloudFormation 中使用資源提供者類型建立資源時出現的「資源等待實體資源建立時發生逾時」錯誤?
- 如何解決當我在 AWS CloudFormation 中,對資源提供者資源使用 Fn::GetAtt 函數時,出現的「屬性 'Key’ 不存在」錯誤?
- 如何解決在 AWS CloudFormation 中的 java.lang.ClassNotFoundException: com.example.package.resource.HandlerWrapper 錯誤?
**注意事項:**如果您在執行 AWS CLI 命令時收到錯誤,請確定您使用最新的 AWS CLI 版本。
解決方案
1. 確認 CloudFormation 範本中定義的屬性也已在 organization-service-resource.json 檔案中定義。
**注意事項:**資源提供者結構描述檔案是 organization-service-resource.json 格式的 JSON 檔案,位於專案的根目錄中。
2. 如果您正確定義了屬性,請依序執行 cfn generate、mvn package 和 cfn submit 命令,確認專案已順利建置。例如:
$ cfn generate Generated files for Organization::Service::Resource $ mvn package [INFO] Scanning for projects... [INFO] [INFO] --< software.organization.service.resource:organization-service-resource-handler >-- [INFO] Building organization-service-resource-handler 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- ... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 21.690 s [INFO] Finished at: 2020-07-14T16:02:47-05:00 [INFO] ------------------------------------------------------------------------ $ cfn submit Successfully submitted type. Waiting for registration with token '12345a-abcde-6789-abc1-a1234b567891' to complete. {'ProgressStatus': 'COMPLETE', 'Description': 'Deployment is currently in DEPLOY_STAGE of status COMPLETED' , 'TypeArn': 'arn:aws:cloudformation:us-east-1:1234567891:type/resource/Organization-Service-Resource', 'TypeVersionArn': 'arn:aws:cloudformation:us-east-1:1234567891:type/resource/Organization-Service-Resource/00000035', 'ResponseMetadata': {'RequestId': '123a1234-b123-4567-abcd-123a123b1c1d', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '123a1234-b123-4567-abcd-123a123b1c1d', 'content-type': 'text/xml', 'content-length': '952', 'date': 'Tue, 14 Jul 2020 21:16:17 GMT'}, 'RetryAttempts': 0}}
3. 若要將專案的目前版本設定為預設使用,請執行下列命令:
aws cloudformation set-type-default-version --type RESOURCE --type-name Organization::Service::Resource --version-id 00000005
注意事項: 將 --type-name 和 --version-id 的值取代為您的資源類型名稱,和 cfn submit 在 TypeVersionArn 鍵值中傳回建置的最新版本。
4. 如果步驟 1-3 無法解決問題,請變更資源提供者結構描述和 CloudFormation 範本中的屬性名稱,以檢查您是否正在使用保留屬性。然後,重建並註冊您的資源類型,並嘗試使用不同的屬性名稱再次使用 CloudFormation 建立資源。
請考慮下列提示:
如果單元測試沒有完成,想跳過測試,請執行 mvn -Dmaven.test.skip=true 套件,而不要執行 mvn 套件。
若要在成功註冊類型版本後將目前類型版本設為預設值,請將 --set-default 選項指定為 cfn submit。例如:
$ cfn submit --set-default
**注意事項:**如需相關資訊,請參閱 submit。
您可以從專案根目錄導覽至目錄 /target/surefire-reports 來對測試進行疑難排解。
相關資訊
相關內容
- AWS 官方已更新 2 年前
- AWS 官方已更新 4 年前