diff --git a/python/rpdk/java/templates/init/guided_aws/StubDeleteHandler.java b/python/rpdk/java/templates/init/guided_aws/StubDeleteHandler.java index 11293dbe..43807a7a 100644 --- a/python/rpdk/java/templates/init/guided_aws/StubDeleteHandler.java +++ b/python/rpdk/java/templates/init/guided_aws/StubDeleteHandler.java @@ -56,7 +56,7 @@ protected ProgressEvent handleRequest( // STEP 1.3 [TODO: handle exception] .handleError((awsRequest, exception, client, model, context) -> { // TODO: uncomment when ready to implement - // if (exception instanceof CfnNotFoundException) + // if (exception instanceof ResourceNotFoundException) // return ProgressEvent.success(model, context); // throw exception; return ProgressEvent.progress(model, context); @@ -105,6 +105,10 @@ protected ProgressEvent handleRequest( logger.log(String.format("%s [%s] deletion has stabilized: %s", ResourceModel.TYPE_NAME, model.getPrimaryIdentifier(), stabilized)); return stabilized; }) - .success()); + .progress() + ) + + // STEP 3 [TODO: return the successful progress event without resource model] + .then(progress -> ProgressEvent.defaultSuccessHandler(null)); } } diff --git a/python/rpdk/java/templates/init/guided_aws/StubHandlerTest.java b/python/rpdk/java/templates/init/guided_aws/StubHandlerTest.java index 07d38e09..b243c57e 100644 --- a/python/rpdk/java/templates/init/guided_aws/StubHandlerTest.java +++ b/python/rpdk/java/templates/init/guided_aws/StubHandlerTest.java @@ -60,7 +60,11 @@ public void handleRequest_SimpleSuccess() { assertThat(response).isNotNull(); assertThat(response.getStatus()).isEqualTo(OperationStatus.SUCCESS); assertThat(response.getCallbackDelaySeconds()).isEqualTo(0); + {% if operation == "Delete" %} + assertThat(response.getResourceModel()).isNull(); + {% else %} assertThat(response.getResourceModel()).isEqualTo(request.getDesiredResourceState()); + {% endif %} assertThat(response.getResourceModels()).isNull(); assertThat(response.getMessage()).isNull(); assertThat(response.getErrorCode()).isNull(); diff --git a/python/rpdk/java/templates/init/guided_aws/StubReadHandler.java b/python/rpdk/java/templates/init/guided_aws/StubReadHandler.java index 7b896f92..71d747c8 100644 --- a/python/rpdk/java/templates/init/guided_aws/StubReadHandler.java +++ b/python/rpdk/java/templates/init/guided_aws/StubReadHandler.java @@ -42,6 +42,8 @@ protected ProgressEvent handleRequest( try { // TODO: add custom read resource logic + // If describe request does not return ResourceNotFoundException, you must throw ResourceNotFoundException based on + // awsResponse values } catch (final AwsServiceException e) { // ResourceNotFoundException /* diff --git a/python/rpdk/java/templates/init/guided_aws/StubUpdateHandler.java b/python/rpdk/java/templates/init/guided_aws/StubUpdateHandler.java index 59fe4f77..ce00d765 100644 --- a/python/rpdk/java/templates/init/guided_aws/StubUpdateHandler.java +++ b/python/rpdk/java/templates/init/guided_aws/StubUpdateHandler.java @@ -29,17 +29,45 @@ protected ProgressEvent handleRequest( // https://github.com/aws-cloudformation/cloudformation-cli-java-plugin/blob/master/src/main/java/software/amazon/cloudformation/proxy/CallChain.java return ProgressEvent.progress(request.getDesiredResourceState(), callbackContext) - // STEP 1 [first update/stabilize progress chain - required for resource update] + + // STEP 1 [check if resource already exists] + // for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html + // if target API does not support 'ResourceNotFoundException' then following check is required .then(progress -> // STEP 1.0 [initialize a proxy context] + // If your service API does not return ResourceNotFoundException on update requests against some identifier (e.g; resource Name) + // and instead returns a 200 even though a resource does not exist, you must first check if the resource exists here + // NOTE: If your service API throws 'ResourceNotFoundException' for update requests this method is not necessary + proxy.initiate("{{ call_graph }}::{{ operation }}::PreUpdateCheck", proxyClient, progress.getResourceModel(), progress.getCallbackContext()) + + // STEP 1.1 [initialize a proxy context] + .translateToServiceRequest(Translator::translateToReadRequest) + + // STEP 1.2 [TODO: make an api call] + .makeServiceCall((awsRequest, client) -> { + AwsResponse awsResponse = null; + + // TODO: add custom read resource logic + // If describe request does not return ResourceNotFoundException, you must throw ResourceNotFoundException based on + // awsResponse values + + logger.log(String.format("%s has successfully been read.", ResourceModel.TYPE_NAME)); + return awsResponse; + }) + .progress() + ) + + // STEP 2 [first update/stabilize progress chain - required for resource update] + .then(progress -> + // STEP 2.0 [initialize a proxy context] // Implement client invocation of the update request through the proxyClient, which is already initialised with // caller credentials, correct region and retry settings proxy.initiate("{{ call_graph }}::{{ operation }}::first", proxyClient, progress.getResourceModel(), progress.getCallbackContext()) - // STEP 1.1 [TODO: construct a body of a request] + // STEP 2.1 [TODO: construct a body of a request] .translateToServiceRequest(Translator::translateToFirstUpdateRequest) - // STEP 1.2 [TODO: make an api call] + // STEP 2.2 [TODO: make an api call] .makeServiceCall((awsRequest, client) -> { AwsResponse awsResponse = null; try { @@ -60,7 +88,7 @@ protected ProgressEvent handleRequest( return awsResponse; }) - // 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] + // 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] // stabilization step may or may not be needed after each API call // for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html .stabilize((awsRequest, awsResponse, client, model, context) -> { @@ -74,17 +102,17 @@ protected ProgressEvent handleRequest( .progress()) // If your resource is provisioned through multiple API calls, then the following pattern is required (and might take as many postUpdate callbacks as necessary) - // STEP 2 [second update/stabilize progress chain] + // STEP 3 [second update/stabilize progress chain] .then(progress -> - // STEP 2.0 [initialize a proxy context] + // STEP 3.0 [initialize a proxy context] // If your resource is provisioned through multiple API calls, you will need to apply each subsequent update // step in a discrete call/stabilize chain to ensure the entire resource is provisioned as intended. proxy.initiate("{{ call_graph }}::{{ operation }}::second", proxyClient, progress.getResourceModel(), progress.getCallbackContext()) - // STEP 2.1 [TODO: construct a body of a request] + // STEP 3.1 [TODO: construct a body of a request] .translateToServiceRequest(Translator::translateToSecondUpdateRequest) - // STEP 2.2 [TODO: make an api call] + // STEP 3.2 [TODO: make an api call] .makeServiceCall((awsRequest, client) -> { AwsResponse awsResponse = null; try { @@ -106,7 +134,7 @@ protected ProgressEvent handleRequest( }) .progress()) - // STEP 3 [TODO: describe call/chain to return the resource model] + // STEP 4 [TODO: describe call/chain to return the resource model] .then(progress -> new ReadHandler().handleRequest(proxy, request, callbackContext, proxyClient, logger)); } }