如何解决在 CloudFormation 中的资源提供商资源上使用 Fn::GetAtt 函数时收到的 “Attribute 'Key' does not exist”(属性 “Key” 不存在)错误?
上次更新日期:2022 年 9 月 19 日
当我在 AWS CloudFormation 中将 Fn::GetAtt 函数用于我的资源提供商时,我收到以下错误:
“Attribute 'Key' does not exist”(属性 “Key” 不存在)
简短描述
CloudFormation 返回 “Attribute 'Key' does not exist”(属性“Key”不存在)错误,因为它没有收到所需的属性。您的资源的 ReadHandler 必须返回一个从 organization-service-resource.json 资源提供商 schema 文件的 readOnlyProperties 列表中指定的属性。
有关与使用资源提供商相关的其他错误,请参阅以下文章:
- 如何解决在 AWS CloudFormation 中使用 CloudFormation CLI 运行 cfn generate 命令时收到的 "Resource specification is invalid"(资源规范无效)错误?
- 如何解决 CloudFormation 中的“Model validation failed (#: extraneous key [Key] is not permitted)”(模型验证失败 [#:不允许外键 [Key]])错误?
- 如何解决在 CloudFormation 中使用资源提供商类型创建资源时收到的 “Resource timed out waiting for creation of physical resource”(等待创建物理资源时资源超时)错误?
- 如何解决 CloudFormation 中的 “java.lang.ClassNotFoundException: com.example.package.resource.HandlerWrapper” 错误?
解决方法
1. 在您的 organization-service-resource.json 文件中,确认 readOnlyProperties 定义使用以下格式,其中,Output 是在属性部分定义的属性。例如:
"readOnlyProperties": [
"/properties/Output"
],
注意:organization-service-resource.json 格式位于项目的根目录中。
2. 在您的 ReadHandler 中,在模型对象中设置属性。例如:
final ResourceModel model = request.getDesiredResourceState();
model.setOutput("abcdxyz");
return ProgressEvent.<ResourceModel, CallbackContext>builder()
.resourceModel(model)
.status(OperationStatus.SUCCESS)
.build();
相关信息
AWS CloudFormation CLI(来自 GitHub 网站)