@@ -29,17 +29,45 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
2929 // https://github.com/aws-cloudformation/cloudformation-cli-java-plugin/blob/master/src/main/java/software/amazon/cloudformation/proxy/CallChain.java
3030
3131 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
3336 .then (progress ->
3437 // 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]
3563 // Implement client invocation of the update request through the proxyClient, which is already initialised with
3664 // caller credentials, correct region and retry settings
3765 proxy .initiate ("{{ call_graph }}::{{ operation }}::first" , proxyClient , progress .getResourceModel (), progress .getCallbackContext ())
3866
39- // STEP 1 .1 [TODO: construct a body of a request]
67+ // STEP 2 .1 [TODO: construct a body of a request]
4068 .translateToServiceRequest (Translator ::translateToFirstUpdateRequest )
4169
42- // STEP 1 .2 [TODO: make an api call]
70+ // STEP 2 .2 [TODO: make an api call]
4371 .makeServiceCall ((awsRequest , client ) -> {
4472 AwsResponse awsResponse = null ;
4573 try {
@@ -60,7 +88,7 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
6088 return awsResponse ;
6189 })
6290
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]
6492 // stabilization step may or may not be needed after each API call
6593 // for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html
6694 .stabilize ((awsRequest , awsResponse , client , model , context ) -> {
@@ -74,17 +102,17 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
74102 .progress ())
75103
76104 // 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]
78106 .then (progress ->
79- // STEP 2 .0 [initialize a proxy context]
107+ // STEP 3 .0 [initialize a proxy context]
80108 // If your resource is provisioned through multiple API calls, you will need to apply each subsequent update
81109 // step in a discrete call/stabilize chain to ensure the entire resource is provisioned as intended.
82110 proxy .initiate ("{{ call_graph }}::{{ operation }}::second" , proxyClient , progress .getResourceModel (), progress .getCallbackContext ())
83111
84- // STEP 2 .1 [TODO: construct a body of a request]
112+ // STEP 3 .1 [TODO: construct a body of a request]
85113 .translateToServiceRequest (Translator ::translateToSecondUpdateRequest )
86114
87- // STEP 2 .2 [TODO: make an api call]
115+ // STEP 3 .2 [TODO: make an api call]
88116 .makeServiceCall ((awsRequest , client ) -> {
89117 AwsResponse awsResponse = null ;
90118 try {
@@ -106,7 +134,7 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
106134 })
107135 .progress ())
108136
109- // STEP 3 [TODO: describe call/chain to return the resource model]
137+ // STEP 4 [TODO: describe call/chain to return the resource model]
110138 .then (progress -> new ReadHandler ().handleRequest (proxy , request , callbackContext , proxyClient , logger ));
111139 }
112140}
0 commit comments