Skip to content

Commit 82e137c

Browse files
committed
initial docs changes
1 parent b062a76 commit 82e137c

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

docs/utilities/custom_resources.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ title: Custom Resources
33
description: Utility
44
---
55

6-
[Custom resources](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html)
6+
[CloudFormation Custom resources](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html)
77
provide a way for [AWS Lambda functions](
88
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources-lambda.html) to execute
9-
provisioning logic whenever CloudFormation stacks are created, updated, or deleted. The CloudFormation utility enables
10-
developers to write these Lambda functions in Java.
9+
provisioning logic whenever CloudFormation stacks are created, updated, or deleted.
1110

12-
The utility provides a base `AbstractCustomResourceHandler` class which handles [custom resource request events](
13-
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-requests.html), constructs
14-
[custom resource responses](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-responses.html), and
15-
sends them to the custom resources. Subclasses implement the provisioning logic and configure certain properties of
16-
these response objects.
11+
Powertools-cloudformation makes it easy to write Lambda functions in Java that are used as CloudFormation custom resources.
12+
The utility reads incoming CloudFormation events, calls your custom code depending on the operation (CREATE, UPDATE or DELETE) and sends responses back to CloudFormation.
13+
By using this library you do not need to write code to integrate with CloudFormation, and you only focus on writing the custom provisioning logic inside the Lambda function.
1714

1815
## Install
1916

@@ -40,11 +37,14 @@ To install this utility, add the following dependency to your project.
4037

4138
## Usage
4239

43-
Create a new `AbstractCustomResourceHandler` subclass and implement the `create`, `update`, and `delete` methods with
44-
provisioning logic in the appropriate methods(s).
40+
To utilise the feature, extend the `AbstractCustomResourceHandler` class in your Lambda handler class.
41+
After you extend the `AbstractCustomResourceHandler`, implement and override the following 3 methods: `create`, `update` and `delete`. The `AbstractCustomResourceHandler` invokes the right method according to the CloudFormation [custom resource request event](
42+
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-requests.html) it receives.
43+
Inside the methods, implement your custom provisioning logic, and return a `Response`. The `AbstractCustomResourceHandler` takes your `Response`, builds a
44+
[custom resource responses](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-responses.html) and sends it to CloudFormation automatically.
4545

46-
As an example, if a Lambda function only needs to provision something when a stack is created, put the provisioning
47-
logic exclusively within the `create` method; the other methods can just return `null`.
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`.
4848

4949
```java hl_lines="8 9 10 11"
5050
import com.amazonaws.services.lambda.runtime.Context;
@@ -56,8 +56,13 @@ public class ProvisionOnCreateHandler extends AbstractCustomResourceHandler {
5656

5757
@Override
5858
protected Response create(CloudFormationCustomResourceEvent createEvent, Context context) {
59-
doProvisioning();
60-
return Response.success();
59+
String physicalResourceId = "sample-resource-id-" + UUID.randomUUID(); //Create a unique ID for your resource
60+
ProvisioningResult provisioningResult = doProvisioning();
61+
if(provisioningResult.isSuccessful()){ //check if the provisioning was successful
62+
return Response.success(physicalResourceId);
63+
}else{
64+
return Response.failed(physicalResourceId);
65+
}
6166
}
6267

6368
@Override
@@ -74,8 +79,8 @@ public class ProvisionOnCreateHandler extends AbstractCustomResourceHandler {
7479

7580
### Signaling Provisioning Failures
7681

77-
If provisioning fails, the stack creation/modification/deletion as a whole can be failed by either throwing a
78-
`RuntimeException` or by explicitly returning a `Response` with a failed status, e.g. `Response.failure()`.
82+
If the provisioning inside your Custom Resource fails, you can notify CloudFormation of the failure by returning a `Repsonse.failure(physicalResourceId)`.
83+
7984

8085
### Configuring Response Objects
8186

0 commit comments

Comments
 (0)