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
[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.
17
14
18
15
## Install
19
16
@@ -40,11 +37,14 @@ To install this utility, add the following dependency to your project.
40
37
41
38
## Usage
42
39
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.
45
45
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`.
if(provisioningResult.isSuccessful()){ //check if the provisioning was successful
62
+
returnResponse.success(physicalResourceId);
63
+
}else{
64
+
returnResponse.failed(physicalResourceId);
65
+
}
61
66
}
62
67
63
68
@Override
@@ -74,8 +79,8 @@ public class ProvisionOnCreateHandler extends AbstractCustomResourceHandler {
74
79
75
80
### Signaling Provisioning Failures
76
81
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)`.
0 commit comments