Delete request for CloudFormation custom resources
When the template developer deletes the stack or removes the custom resource from the stack,
CloudFormation sends a request to the custom resource provider with RequestType
set
to Delete
. To successfully delete a stack with a custom resource, the custom resource provider
must respond successfully to a delete request.
For an introduction to custom resources and how they work, see Create custom provisioning logic with custom resources.
Request
Delete requests contain the following fields:
RequestType
-
Delete
. RequestId
-
A unique ID for the request.
ResponseURL
-
The response URL identifies a presigned S3 bucket that receives responses from the custom resource provider to AWS CloudFormation.
ResourceType
-
The template developer-chosen resource type of the custom resource in the CloudFormation template. Custom resource type names can be up to 60 characters long and can include alphanumeric and the following characters:
_@-
. LogicalResourceId
-
The template developer-chosen name (logical ID) of the custom resource in the AWS CloudFormation template.
StackId
-
The Amazon Resource Name (ARN) that identifies the stack that contains the custom resource.
PhysicalResourceId
A required custom resource provider-defined physical ID that is unique for that provider.
The value returned for a
PhysicalResourceId
can change custom resource update operations. If the value returned is the same, it is considered a normal update. If the value returned is different, AWS CloudFormation recognizes the update as a replacement and sends a delete request to the old resource. For more information, seeAWS::CloudFormation::CustomResource
.ResourceProperties
-
This field contains the contents of the
Properties
object sent by the template developer. Its contents are defined by the custom resource provider.
Example
{
"RequestType" : "Delete",
"RequestId" : "unique id for this delete request",
"ResponseURL" : "pre-signed-url-for-delete-response",
"ResourceType" : "Custom::MyCustomResourceType",
"LogicalResourceId" : "name of resource in template",
"StackId" : "arn:aws:cloudformation:us-west-2:123456789012:stack/mystack/5b918d10-cd98-11ea-90d5-0a9cd3354c10",
"PhysicalResourceId" : "custom resource provider-defined physical id",
"ResourceProperties" : {
"key1" : "string",
"key2" : [ "list" ],
"key3" : { "key4" : "map" }
}
}
Responses
Success
When the delete request is successful, a response must be sent to the S3 bucket with the following fields:
Status
-
Must be
SUCCESS
. RequestId
-
A unique ID for the request. This response value should be copied verbatim from the request.
LogicalResourceId
-
The template developer-chosen name (logical ID) of the custom resource in the AWS CloudFormation template. This response value should be copied verbatim from the request.
StackId
-
The Amazon Resource Name (ARN) that identifies the stack that contains the custom resource. This response value should be copied verbatim from the request.
PhysicalResourceId
This value should be an identifier unique to the custom resource vendor, and can be up to 1 KB in size. The value must be a non-empty string and must be identical for all responses for the same resource.
The value returned for a
PhysicalResourceId
can change custom resource update operations. If the value returned is the same, it is considered a normal update. If the value returned is different, AWS CloudFormation recognizes the update as a replacement and sends a delete request to the old resource. For more information, seeAWS::CloudFormation::CustomResource
.
Example
{
"Status" : "SUCCESS",
"RequestId" : "unique id for this delete request (copied from request)",
"LogicalResourceId" : "name of resource in template (copied from request)",
"StackId" : "arn:aws:cloudformation:us-west-2:123456789012:stack/mystack/5b918d10-cd98-11ea-90d5-0a9cd3354c10 (copied from request)",
"PhysicalResourceId" : "custom resource provider-defined physical id"
}
Failed
When the delete request fails, a response must be sent to the S3 bucket with the following fields:
Status
-
Must be
FAILED
. Reason
-
The reason for the failure.
RequestId
-
The
RequestId
value copied from the delete request. LogicalResourceId
-
The
LogicalResourceId
value copied from the delete request. StackId
-
The
StackId
value copied from the delete request. PhysicalResourceId
-
A required custom resource provider-defined physical ID that's unique for that provider.
Example
{
"Status" : "FAILED",
"Reason" : "Required failure reason string",
"RequestId" : "unique id for this delete request (copied from request)",
"LogicalResourceId" : "name of resource in template (copied from request)",
"StackId" : "arn:aws:cloudformation:us-west-2:123456789012:stack/mystack/5b918d10-cd98-11ea-90d5-0a9cd3354c10 (copied from request)",
"PhysicalResourceId" : "custom resource provider-defined physical id"
}