You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inside the methods, implement your custom provisioning logic, and return a `Response`. The `AbstractCustomResourceHandler` takes your `Response`, builds a
44
44
[custom resource responses](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-responses.html) and sends it to CloudFormation automatically.
45
45
46
-
Custom resources notify cloudformation either of `SUCCESS` or `FAILED` status. You have 2 utility methods to represent these responses: `Response.success(physicalResourceId)` and `Response.failed(physicalResourceId)`.
47
-
If a `Response` is not returned by your code, `AbstractCustomResourceHandler` defaults the response to `SUCCESS`.
46
+
Custom resources notify cloudformation either of `SUCCESS` or `FAILED` status. You have 2 utility methods to represent these responses: `Response.success(physicalResourceId)` and `Response.failed(physicalResourceId)`.
47
+
The `physicalResourceId` is an identifier that is used during the lifecycle operations of the Custom Resource.
48
+
You should supply a `physicalResourceId` during the `CREATE` operation, CloudFormation stores the `physicalResourceId` and includes it `UPDATE` and `DELETE` events.
49
+
50
+
Here an example of how to implement a Custom Resource using the powertools-cloudformation library:
if(deleteResult.isSuccessful()){ //check if the delete operations were successful
87
+
returnResponse.success(physicalResourceId);
88
+
}else{
89
+
returnResponse.failed(physicalResourceId);
90
+
}
76
91
}
77
92
}
78
93
```
79
94
80
-
### Signaling Provisioning Failures
95
+
### Missing `Response` and exception handling
96
+
97
+
If a `Response` is not returned by your code, `AbstractCustomResourceHandler` defaults the response to `SUCCESS`.
98
+
If your code raises an exception (which is not handled), the `AbstractCustomResourceHandler` defaults the response to `FAILED`.
99
+
100
+
In both of the scenarios, powertools-java will assign the `physicalResourceId` based on the following logic:
101
+
- if present, use the `physicalResourceId` provided in the `CloudFormationCustomResourceEvent`
102
+
- if it is not present, use the `LogStreamName` from the Lambda context
81
103
82
-
If the provisioning inside your Custom Resource fails, you can notify CloudFormation of the failure by returning a `Repsonse.failure(physicalResourceId)`.
104
+
#### Why does this matter?
83
105
106
+
It is recommended that you always provide a `physicalResourceId` in your response because `physicalResourceId` has a crucial role in the lifecycle of a CloudFormation custom resource.
107
+
If the `physicalResourceId` changes between calls from Cloudformation, for instance in response to an `Update` event, Cloudformation [treats the resource update as a replacement](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html).
84
108
85
-
### Configuring Response Objects
109
+
### Customising a response
86
110
87
-
When provisioning results in data to be shared with other parts of the stack, include this data within the returned
88
-
`Response` instance.
111
+
As well as the `Response.success(physicalResourceId)` and `Response.failed(physicalResourceId)`, you can customise the `Response` by using the `Response.builder()`.
112
+
You customise the responses when you need additional attributes to be shared with other parts of the CloudFormation stack.
89
113
90
-
This Lambda function creates a [Chime AppInstance](https://docs.aws.amazon.com/chime/latest/dg/create-app-instance.html)
114
+
In the example below, the Lambda function creates a [Chime AppInstance](https://docs.aws.amazon.com/chime/latest/dg/create-app-instance.html)
91
115
and maps the returned ARN to a "ChimeAppInstanceArn" attribute.
0 commit comments