Skip to content

Commit 7cea781

Browse files
committed
more doc changes
1 parent 6c2ae4c commit 7cea781

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

docs/utilities/custom_resources.md

+75
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,78 @@ public class CustomSerializationHandler extends AbstractResourceHandler {
215215
}
216216
}
217217
```
218+
219+
## Advanced
220+
221+
### Understanding the CloudFormation custom resource lifecycle
222+
223+
While the library provides an easy-to-use interface, we recommend that you understand the lifecycle of CloudFormation custom resources before using them in production.
224+
225+
#### Creating a custom resource
226+
When CloudFormation issues a CREATE on a custom resource, there are 2 possible states: `CREATE_COMPLETE` and `CREATE_FAILED`
227+
```mermaid
228+
stateDiagram
229+
direction LR
230+
createState: Create custom resource
231+
[*] --> createState
232+
createState --> CREATE_COMPLETE
233+
createState --> CREATE_FAILED
234+
```
235+
236+
If the resource is created successfully, the `physicalResourceId` is stored by CloudFormation for future operations.
237+
If the resource failed to create, CloudFormation triggers a rollback operation by default (rollback can be disabled, see [stack failure options](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stack-failure-options.html))
238+
239+
#### Updating a custom resource
240+
CloudFormation issues an UPDATE operation on a custom resource only when one or more custom resource properties change.
241+
During the update, the custom resource may update successfully, or may fail the update.
242+
```mermaid
243+
stateDiagram
244+
direction LR
245+
updateState: Update custom resource
246+
[*] --> updateState
247+
updateState --> UPDATE_COMPLETE
248+
updateState --> UPDATE_FAILED
249+
```
250+
251+
In both of these scenarios, the custom resource can return the same `physicalResourceId` it received in the CLoudFormation event, or a different `physicalResourceId`.
252+
Semantically an `UPDATE_COMPLETE` that returns the same `physicalResourceId` it received, means that the existing resource was updated successfully.
253+
Instead, an `UPDATE_COMPLETE` with a different `physicalResourceId` means that a new physical resource was created successfully.
254+
```mermaid
255+
flowchart BT
256+
id1(Logical resource)
257+
id2(Previous physical Resource)
258+
id3(New physical Resource)
259+
id2 --> id1
260+
id3 --> id1
261+
```
262+
Therefore, after the custom resource update completed or failed, there may be other cleanup operations by Cloudformation during the rollback, as described in the diagram below:
263+
```mermaid
264+
stateDiagram
265+
state if_state <<choice>>
266+
updateState: Update custom resource
267+
deletePrev: DELETE resource with previous physicalResourceId
268+
updatePrev: Rollback - UPDATE resource with previous properties
269+
noOp: No further operations
270+
[*] --> updateState
271+
updateState --> UPDATE_COMPLETE
272+
UPDATE_COMPLETE --> if_state
273+
if_state --> noOp : Same physicalResourceId
274+
if_state --> deletePrev : Different physicalResourceId
275+
updateState --> UPDATE_FAILED
276+
UPDATE_FAILED --> updatePrev
277+
```
278+
279+
#### Deleting a custom resource
280+
281+
CloudFormation issues a DELETE on a custom resource when:
282+
- the CloudFormation stack is being deleted
283+
- a new `physicalResourceId` was received during an update (see previous section)
284+
285+
```mermaid
286+
stateDiagram
287+
direction LR
288+
deleteState: Delete custom resource
289+
[*] --> deleteState
290+
deleteState --> DELETE_COMPLETE
291+
deleteState --> DELETE_FAILED
292+
```

0 commit comments

Comments
 (0)