@@ -29,17 +29,45 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
29
29
// https://github.com/aws-cloudformation/cloudformation-cli-java-plugin/blob/master/src/main/java/software/amazon/cloudformation/proxy/CallChain.java
30
30
31
31
return ProgressEvent .progress (request .getDesiredResourceState (), callbackContext )
32
- // STEP 1 [first update/stabilize progress chain - required for resource update]
32
+
33
+ // STEP 1 [check if resource already exists]
34
+ // for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html
35
+ // if target API does not support 'ResourceNotFoundException' then following check is required
33
36
.then (progress ->
34
37
// STEP 1.0 [initialize a proxy context]
38
+ // If your service API does not return ResourceNotFoundException on update requests against some identifier (e.g; resource Name)
39
+ // and instead returns a 200 even though a resource does not exist, you must first check if the resource exists here
40
+ // NOTE: If your service API throws 'ResourceNotFoundException' for update requests this method is not necessary
41
+ proxy .initiate ("{{ call_graph }}::{{ operation }}::PreUpdateCheck" , proxyClient , progress .getResourceModel (), progress .getCallbackContext ())
42
+
43
+ // STEP 1.1 [initialize a proxy context]
44
+ .translateToServiceRequest (Translator ::translateToReadRequest )
45
+
46
+ // STEP 1.2 [TODO: make an api call]
47
+ .makeServiceCall ((awsRequest , client ) -> {
48
+ AwsResponse awsResponse = null ;
49
+
50
+ // TODO: add custom read resource logic
51
+ // If describe request does not return ResourceNotFoundException, you must throw ResourceNotFoundException based on
52
+ // awsResponse values
53
+
54
+ logger .log (String .format ("%s has successfully been read." , ResourceModel .TYPE_NAME ));
55
+ return awsResponse ;
56
+ })
57
+ .progress ()
58
+ )
59
+
60
+ // STEP 2 [first update/stabilize progress chain - required for resource update]
61
+ .then (progress ->
62
+ // STEP 2.0 [initialize a proxy context]
35
63
// Implement client invocation of the update request through the proxyClient, which is already initialised with
36
64
// caller credentials, correct region and retry settings
37
65
proxy .initiate ("{{ call_graph }}::{{ operation }}::first" , proxyClient , progress .getResourceModel (), progress .getCallbackContext ())
38
66
39
- // STEP 1 .1 [TODO: construct a body of a request]
67
+ // STEP 2 .1 [TODO: construct a body of a request]
40
68
.translateToServiceRequest (Translator ::translateToFirstUpdateRequest )
41
69
42
- // STEP 1 .2 [TODO: make an api call]
70
+ // STEP 2 .2 [TODO: make an api call]
43
71
.makeServiceCall ((awsRequest , client ) -> {
44
72
AwsResponse awsResponse = null ;
45
73
try {
@@ -60,7 +88,7 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
60
88
return awsResponse ;
61
89
})
62
90
63
- // STEP 1 .3 [TODO: stabilize step is not necessarily required but typically involves describing the resource until it is in a certain status, though it can take many forms]
91
+ // STEP 2 .3 [TODO: stabilize step is not necessarily required but typically involves describing the resource until it is in a certain status, though it can take many forms]
64
92
// stabilization step may or may not be needed after each API call
65
93
// for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html
66
94
.stabilize ((awsRequest , awsResponse , client , model , context ) -> {
@@ -74,17 +102,17 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
74
102
.progress ())
75
103
76
104
// If your resource is provisioned through multiple API calls, then the following pattern is required (and might take as many postUpdate callbacks as necessary)
77
- // STEP 2 [second update/stabilize progress chain]
105
+ // STEP 3 [second update/stabilize progress chain]
78
106
.then (progress ->
79
- // STEP 2 .0 [initialize a proxy context]
107
+ // STEP 3 .0 [initialize a proxy context]
80
108
// If your resource is provisioned through multiple API calls, you will need to apply each subsequent update
81
109
// step in a discrete call/stabilize chain to ensure the entire resource is provisioned as intended.
82
110
proxy .initiate ("{{ call_graph }}::{{ operation }}::second" , proxyClient , progress .getResourceModel (), progress .getCallbackContext ())
83
111
84
- // STEP 2 .1 [TODO: construct a body of a request]
112
+ // STEP 3 .1 [TODO: construct a body of a request]
85
113
.translateToServiceRequest (Translator ::translateToSecondUpdateRequest )
86
114
87
- // STEP 2 .2 [TODO: make an api call]
115
+ // STEP 3 .2 [TODO: make an api call]
88
116
.makeServiceCall ((awsRequest , client ) -> {
89
117
AwsResponse awsResponse = null ;
90
118
try {
@@ -106,7 +134,7 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
106
134
})
107
135
.progress ())
108
136
109
- // STEP 3 [TODO: describe call/chain to return the resource model]
137
+ // STEP 4 [TODO: describe call/chain to return the resource model]
110
138
.then (progress -> new ReadHandler ().handleRequest (proxy , request , callbackContext , proxyClient , logger ));
111
139
}
112
140
}
0 commit comments