當我使用我的資源提供者類型在 AWS CloudFormation 中建立資源時,我收到下列錯誤: 「資源等待實體資源建立時發生逾時。」
解決方法
當資源未在 60 秒內傳回其 primaryIdentifier 或實體 ID 時,您會收到「資源等待實體資源建立時發生逾時」錯誤。之所以發生這個錯誤,是因為資源的 CreateHandler 未傳回在資源類型結構描述檔案中指定為 primaryIdentifier 的屬性。
**注意:**該檔案使用組織 organization-service-resource.json 命名格式。例如,article-ec2-subnet.json 是名為 Article::EC2::Subnet 的 Amazon Elastic Cloud Compute (Amazon EC2) 資源的檔案名稱。
若要解決此問題,請完成下列步驟:
- 在資源類型結構描述檔案中,確認 primaryIdentifier 定義使用下列格式:
"primaryIdentifier": [
"/properties/Id"
]
注意: 將 Id 替換為屬性 ID。您可以在專案的根目錄中找到資源結構描述類型檔案。
- 在您的 CreateHandler 中,在 model (模型) 物件中設定 primaryIdentifier 屬性。
範例:
final ResourceModel model = request.getDesiredResourceState();
model.setId("abcdxyz");
return ProgressEvent.<ResourceModel, CallbackContext>builder()
.resourceModel(model)
.status(OperationStatus.SUCCESS)
.build();
注意: 將 Id 替換為資源的主要識別碼,並將 **abcdxyz **替換為您屬性的唯一識別碼值。
如果您在使用資源提供者時收到其他錯誤,請參閱以下 AWS 知識中心文章進行疑難排解:
相關資訊
GitHub 網站上的 CloudFormation CLI。