更新
在对模板内的自定义资源属性进行任何更改时,发送 RequestType
设置为 Update
的自定义资源提供商请求。因此,自定义资源代码不必检测更改,因为它知道其属性在调用 Update 后已更改。
请求
更新请求包含以下字段:
- RequestType
-
Update
. - RequestId
-
请求的唯一 ID。
- ResponseURL
-
响应 URL 标识一个预签名 S3 桶,该桶接收从自定义资源提供商到 Amazon CloudFormation 的响应。
- ResourceType
-
Amazon CloudFormation 模板中模板开发人员选择的自定义资源的资源类型。自定义资源类型名称的长度最多为 60 个字符,并且可包含字母数字字符和以下字符:
_@-
。更新期间不能更改类型。 - LogicalResourceId
-
Amazon CloudFormation 模板中模板开发人员选择的自定义资源的名称(逻辑 ID)。
- StackId
-
标识包含自定义资源的堆栈的 Amazon 资源名称(ARN)。
- PhysicalResourceId
-
custom resource provider 定义的必需物理 ID,该 ID 对于该提供程序是唯一的。
为
PhysicalResourceId
返回的值可以更改自定义资源更新操作。如果返回的值相同,则将其视为正常更新。如返回的值不同,则 Amazon CloudFormation 将该更新视为替换,并向旧资源发送删除请求。有关更多信息,请参阅AWS::CloudFormation::CustomResource
。 - ResourceProperties
-
模板开发人员在更新后的 Amazon CloudFormation 模板中声明的新资源属性值。
- OldResourceProperties
-
模板开发人员以前在 Amazon CloudFormation 模板中声明的资源属性值。
示例
{ "RequestType" : "Update", "RequestId" : "unique id for this update request", "ResponseURL" : "pre-signed-url-for-update-response", "ResourceType" : "Custom::MyCustomResourceType", "LogicalResourceId" : "name of resource in template", "StackId" : "arn:aws:cloudformation:us-east-2:namespace:stack/stack-name/guid", "PhysicalResourceId" : "custom resource provider-defined physical id", "ResourceProperties" : { "key1" : "new-string", "key2" : [ "new-list" ], "key3" : { "key4" : "new-map" } }, "OldResourceProperties" : { "key1" : "string", "key2" : [ "list" ], "key3" : { "key4" : "map" } } }
响应
成功
如果自定义资源提供商可以成功更新资源,Amazon CloudFormation 预计响应中的状态将设置为 SUCCESS
。
- Status
-
必须是
SUCCESS
。 - RequestId
-
请求的唯一 ID。应从该请求逐字复制此响应值。
- LogicalResourceId
-
Amazon CloudFormation 模板中模板开发人员选择的自定义资源的名称(逻辑 ID)。应从该请求逐字复制此响应值。
- StackId
-
标识包含自定义资源的堆栈的 Amazon 资源名称(ARN)。应从该请求逐字复制此响应值。
- PhysicalResourceId
-
该值应该为自定义资源供应商的唯一标识符,并且最大为 1KB。该值必须为非空字符串,并且对于同一资源的所有响应都必须相同。
为
PhysicalResourceId
返回的值可以更改自定义资源更新操作。如果返回的值相同,则将其视为正常更新。如返回的值不同,则 Amazon CloudFormation 将该更新视为替换,并向旧资源发送删除请求。有关更多信息,请参阅AWS::CloudFormation::CustomResource
。 - NoEcho
-
可选。指示在使用
Fn::GetAtt
函数检索时是否遮蔽自定义资源的输出。如果设置为true
,则除模板Metadata
部分中存储的值外,所有返回值都将用星号(*****)遮蔽。Amazon CloudFormation 不会转换、修改或编辑您在Metadata
部分中包含的任何信息。默认值为false
。有关使用
NoEcho
来遮蔽敏感信息的更多信息,请参阅请勿将凭证嵌入您的模板最佳实践。 - 数据
-
可选。自定义资源提供商定义的名称值对,随响应一起发送。您可以使用
Fn::GetAtt
在模板中按名称访问此处提供的值。重要
如果名称值对包含敏感信息,应使用
NoEcho
字段遮蔽自定义资源的输出。否则,这些值通过显示属性值的 API(例如DescribeStackEvents
)可见。
示例
{ "Status" : "SUCCESS", "RequestId" : "unique id for this update request (copied from request)", "LogicalResourceId" : "name of resource in template (copied from request)", "StackId" : "arn:aws:cloudformation:us-east-2:namespace:stack/stack-name/guid (copied from request)", "PhysicalResourceId" : "custom resource provider-defined physical id", "Data" : { "keyThatCanBeUsedInGetAtt1" : "data for key 1", "keyThatCanBeUsedInGetAtt2" : "data for key 2" } }
失败
如果无法使用新属性集更新资源,则 Amazon CloudFormation 预计响应中的状态将设置为 FAILED
,并且响应中包含失败原因。
- Status
-
必须是
FAILED
。 - Reason
-
描述失败响应的原因。
- RequestId
-
请求的唯一 ID。应从该请求逐字复制此响应值。
- LogicalResourceId
-
Amazon CloudFormation 模板中模板开发人员选择的自定义资源的名称(逻辑 ID)。应从该请求逐字复制此响应值。
- StackId
-
标识包含自定义资源的堆栈的 Amazon 资源名称(ARN)。应从该请求逐字复制此响应值。
- PhysicalResourceId
-
该值应该为自定义资源供应商的唯一标识符,并且最大为 1KB。该值必须为非空字符串,并且对于同一资源的所有响应都必须相同。
为
PhysicalResourceId
返回的值可以更改自定义资源更新操作。如果返回的值相同,则将其视为正常更新。如返回的值不同,则 Amazon CloudFormation 将该更新视为替换,并向旧资源发送删除请求。有关更多信息,请参阅AWS::CloudFormation::CustomResource
。
示例
{ "Status" : "FAILED", "Reason" : "Required failure reason string", "RequestId" : "unique id for this update request (copied from request)", "LogicalResourceId" : "name of resource in template (copied from request)", "StackId" : "arn:aws:cloudformation:us-east-2:namespace:stack/stack-name/guid (copied from request)", "PhysicalResourceId" : "custom resource provider-defined physical id" }