CloudFormation custom resource request and response reference
CloudFormation manages custom resources through a request-response protocol that communicates with
your custom resource provider. Each request includes a request type (Create,
Update, or Delete) and follows this high-level workflow:
-
A template developer defines a custom resource with a
ServiceTokenandServiceTimeoutin the template and initiates a stack operation. -
CloudFormation sends a JSON request to the custom resource provider through SNS or Lambda.
-
The custom resource provider processes the request and returns a JSON response to a presigned Amazon S3 bucket URL before the timeout period expires.
-
CloudFormation reads the response and proceeds with the stack operation. If no response is received before the timeout period ends, the request is considered unsuccessful, and the stack operation fails.
For more information, see How custom resources work.
This section describes the structure, parameters, and expected responses for each request type.
Note
The total size of the response body can't exceed 4096 bytes.
Template setup
When defining a custom resource in a template, the template developer uses AWS::CloudFormation::CustomResource with the following properties:
ServiceToken-
An Amazon SNS topic ARN or Lambda function ARN from the same Region as the stack.
Required: Yes
Type: String
ServiceTimeout-
The maximum time, in seconds, before a custom resource operation times out. It must be a value between 1 and 3600. Default: 3600 seconds (1 hour).
Required: No
Type: String
Additional resource properties are supported. Resource properties will be included as
ResourceProperties in the request. The custom resource provider must determine which
properties are valid and their acceptable values.
Request object
Response object
The custom resource provider sends a response to the pre-signed URL for all request types. If the custom resource provider doesn't send a response, CloudFormation waits until the operation times out.
The response must be a JSON object with the following fields:
Status-
Must be either
SUCCESSorFAILED.Required: Yes
Type: String
RequestId-
A unique ID for the request. Copy this value exactly as it appears in the request.
Required: Yes
Type: String
StackId-
The Amazon Resource Name (ARN) that identifies the stack that contains the custom resource. Copy this value exactly as it appears in the request.
Required: Yes
Type: String
LogicalResourceId-
The template developer-chosen name (logical ID) of the custom resource in the CloudFormation template. Copy this value exactly as it appears in the request.
Required: Yes
Type: String
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.
When updating custom resources, the value returned for
PhysicalResourceIddetermines the update behavior. If the value remains the same, CloudFormation considers it a normal update. If the value changes, CloudFormation interprets the update as a replacement and sends a delete request to the old resource. For more information, see AWS::CloudFormation::CustomResource.Required: Yes
Type: String
Reason-
Describes the reason for a failure response.
Required if
StatusisFAILED. It's optional otherwise.Required: Conditional
Type: String
NoEcho-
Indicates whether to mask the output of the custom resource when retrieved by using the
Fn::GetAttfunction. If set totrue, all returned values are masked with asterisks (*****), except for those stored in theMetadatasection of the template. CloudFormation does not transform, modify, or redact any information you include in theMetadatasection. The default value isfalse.For more information about using
NoEchoto mask sensitive information, see the Do not embed credentials in your templates best practice.Available for
CreateandUpdateresponses only. Not supported forDeleteresponses.Required: No
Type: Boolean
Data-
The custom resource provider-defined name-value pairs to send with the response. You can access the values provided here by name in the template with
Fn::GetAtt.Available for
CreateandUpdateresponses only. Not supported forDeleteresponses.Important
If the name-value pairs contain sensitive information, you should use the
NoEchofield to mask the output of the custom resource. Otherwise, the values are visible through APIs that surface property values (such asDescribeStackEvents).Required: No
Type: JSON object
Success Response Examples
Create and
Update Response
{
"Status": "SUCCESS",
"RequestId": "unique-request-id",
"StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/name/id",
"LogicalResourceId": "resource-logical-id",
"PhysicalResourceId": "provider-defined-physical-id",
"NoEcho": true,
"Data": {
"key1": "value1",
"key2": "value2"
}
}
Delete
Response
{
"Status": "SUCCESS",
"RequestId": "unique-request-id",
"StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/name/id",
"LogicalResourceId": "resource-logical-id",
"PhysicalResourceId": "provider-defined-physical-id"
}
Failed Response Example
{
"Status": "FAILED",
"RequestId": "unique-request-id",
"StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/name/id",
"LogicalResourceId": "resource-logical-id",
"PhysicalResourceId": "provider-defined-physical-id",
"Reason": "Required failure reason string"
}