Skip to content

Commit e44bc5c

Browse files
committed
changed request -> translate
1 parent 8dfc874 commit e44bc5c

File tree

4 files changed

+42
-34
lines changed

4 files changed

+42
-34
lines changed

python/rpdk/java/templates/init/guided_aws/StubCreateHandler.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
3737

3838
// STEP 1 [check if resource already exists]
3939
// if target API does not support 'ResourceAlreadyExistsException' then following check is required
40-
// for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html#resource-type-test-contract-communication
40+
// for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html
4141
//.then(progress -> checkForPreCreateResourceExistence(proxy, request, progress))
4242

4343
// STEP 2 [create/stabilize progress chain - required for resource creation]
@@ -47,13 +47,13 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
4747
proxy.initiate("{{ call_graph }}::{{ operation }}", proxyClient, model, callbackContext)
4848

4949
// STEP 2.1 [TODO: construct a body of a request]
50-
.request(Translator::translateToCreateRequest)
50+
.translate(Translator::translateToCreateRequest)
5151

5252
// STEP 2.2 [TODO: make an api call]
5353
.call(this::createResource)
5454

5555
// 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]
56-
// for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html#resource-type-test-contract-communication
56+
// for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html
5757
.stabilize(this::stabilizedOnCreate)
5858
.progress())
5959

@@ -104,13 +104,13 @@ private AwsResponse createResource(
104104
// TODO: put your create resource code here
105105
// e.g. https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-logs/commit/ffb15c1a2ca6eb19c051d19d79c0f022719b1493#diff-cbc963180c54a3bf4965fff3f499f365R37-R43
106106

107+
} catch (final AwsServiceException e) {
107108
/*
108109
* While the handler contract states that the handler must always return a progress event,
109-
* you may throw any instance of BaseHandlerException (https://code.amazon.com/packages/AWSCloudFormationRPDKJavaPlugin/blobs/mainline/--/src/main/java/software/amazon/cloudformation/exceptions/BaseHandlerException.java),
110-
* as the wrapper map it to a progress event. Each BaseHandlerException maps to a specific error code, and you should map service exceptions as closely as possible
111-
* to more specific error codes (https://code.amazon.com/packages/AWSCloudFormationRPDKJavaPlugin/blobs/mainline/--/src/main/java/software/amazon/cloudformation/proxy/HandlerErrorCode.java)
110+
* you may throw any instance of BaseHandlerException, as the wrapper map it to a progress event.
111+
* Each BaseHandlerException maps to a specific error code, and you should map service exceptions as closely as possible
112+
* to more specific error codes
112113
*/
113-
} catch (final AwsServiceException e) {
114114
throw new CfnGeneralServiceException(ResourceModel.TYPE_NAME, e);
115115
}
116116

@@ -121,7 +121,7 @@ private AwsResponse createResource(
121121
/**
122122
* If your resource requires some form of stabilization (e.g. service does not provide strong consistency), you will need to ensure that your code
123123
* accounts for any potential issues, so that a subsequent read/update requests will not cause any conflicts (e.g. NotFoundException/InvalidRequestException)
124-
* for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html#resource-type-test-contract-communication
124+
* for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html
125125
* @param awsRequest the aws service request to create a resource
126126
* @param awsResponse the aws service response to create a resource
127127
* @param proxyClient the aws service client to make the call
@@ -158,15 +158,14 @@ private ProgressEvent<ResourceModel, CallbackContext> postCreate(
158158
final CallbackContext callbackContext = progressEvent.getCallbackContext();
159159
try {
160160
// TODO: put your post creation resource update code here
161-
// e.g. https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-logs/commit/2077c92299aeb9a68ae8f4418b5e932b12a8b186#diff-c959c290785791b96fa4442573750fcdR69-R74
162161

162+
} catch (final AwsServiceException e) {
163163
/*
164164
* While the handler contract states that the handler must always return a progress event,
165-
* you may throw any instance of BaseHandlerException (https://code.amazon.com/packages/AWSCloudFormationRPDKJavaPlugin/blobs/mainline/--/src/main/java/software/amazon/cloudformation/exceptions/BaseHandlerException.java),
166-
* as the wrapper map it to a progress event. Each BaseHandlerException maps to a specific error code, and you should map service exceptions as closely as possible
167-
* to more specific error codes (https://code.amazon.com/packages/AWSCloudFormationRPDKJavaPlugin/blobs/mainline/--/src/main/java/software/amazon/cloudformation/proxy/HandlerErrorCode.java)
165+
* you may throw any instance of BaseHandlerException, as the wrapper map it to a progress event.
166+
* Each BaseHandlerException maps to a specific error code, and you should map service exceptions as closely as possible
167+
* to more specific error codes
168168
*/
169-
} catch (final AwsServiceException e) {
170169
throw new CfnGeneralServiceException(ResourceModel.TYPE_NAME, e);
171170
}
172171

python/rpdk/java/templates/init/guided_aws/StubDeleteHandler.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
3434
return ProgressEvent.progress(model, callbackContext)
3535

3636
// STEP 1 [check if resource already exists]
37-
// for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html#resource-type-test-contract-communication
37+
// for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html
3838
// if target API does not support 'ResourceNotFoundException' then following check is required
3939
.then(progress -> checkForPreDeleteResourceExistence(proxy, request, progress))
4040

@@ -45,13 +45,13 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
4545
proxy.initiate("{{ call_graph }}::{{ operation }}", proxyClient, model, callbackContext)
4646

4747
// STEP 2.1 [TODO: construct a body of a request]
48-
.request(Translator::translateToDeleteRequest)
48+
.translate(Translator::translateToDeleteRequest)
4949

5050
// STEP 2.2 [TODO: make an api call]
5151
.call(this::deleteResource)
5252

5353
// 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]
54-
// for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html#resource-type-test-contract-communication
54+
// for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html
5555
.stabilize(this::stabilizedOnDelete)
5656
.success());
5757
}
@@ -75,7 +75,10 @@ private ProgressEvent<ResourceModel, CallbackContext> checkForPreDeleteResourceE
7575
new ReadHandler().handleRequest(proxy, request, callbackContext, logger);
7676
return ProgressEvent.progress(model, callbackContext);
7777
} catch (CfnNotFoundException e) { // ResourceNotFoundException
78-
logger.log(model.getPrimaryIdentifier() + " does not exist.");
78+
logger.log(String.format("%s does not exist. RequestId: %s. Message: %s",
79+
model.getPrimaryIdentifier(),
80+
request.getClientRequestToken(),
81+
e.getMessage()));
7982
throw e;
8083
}
8184
}
@@ -95,13 +98,13 @@ private AwsResponse deleteResource(
9598
// TODO: put your delete resource code here
9699
// e.g. https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-logs/commit/2077c92299aeb9a68ae8f4418b5e932b12a8b186#diff-82aedf3b1de1e4a4948229fa3cac03f0R21-R30
97100

101+
} catch (final AwsServiceException e) {
98102
/*
99103
* While the handler contract states that the handler must always return a progress event,
100-
* you may throw any instance of BaseHandlerException (https://code.amazon.com/packages/AWSCloudFormationRPDKJavaPlugin/blobs/mainline/--/src/main/java/software/amazon/cloudformation/exceptions/BaseHandlerException.java),
101-
* as the wrapper map it to a progress event. Each BaseHandlerException maps to a specific error code, and you should map service exceptions as closely as possible
102-
* to more specific error codes (https://code.amazon.com/packages/AWSCloudFormationRPDKJavaPlugin/blobs/mainline/--/src/main/java/software/amazon/cloudformation/proxy/HandlerErrorCode.java)
104+
* you may throw any instance of BaseHandlerException, as the wrapper map it to a progress event.
105+
* Each BaseHandlerException maps to a specific error code, and you should map service exceptions as closely as possible
106+
* to more specific error codes
103107
*/
104-
} catch (final AwsServiceException e) {
105108
throw new CfnGeneralServiceException(ResourceModel.TYPE_NAME, e);
106109
}
107110

@@ -111,7 +114,7 @@ private AwsResponse deleteResource(
111114

112115
/**
113116
* If deletion of your resource requires some form of stabilization (e.g. propagation delay)
114-
* for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html#resource-type-test-contract-communication
117+
* for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html
115118
* @param awsRequest the aws service request to delete a resource
116119
* @param awsResponse the aws service response to delete a resource
117120
* @param proxyClient the aws service client to make the call

python/rpdk/java/templates/init/guided_aws/StubReadHandler.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
3434
return proxy.initiate("{{ call_graph }}::{{ operation }}", proxyClient, model, callbackContext)
3535

3636
// STEP 2 [TODO: construct a body of a request]
37-
.request(Translator::translateToReadRequest)
37+
.translate(Translator::translateToReadRequest)
3838

3939
// STEP 3 [TODO: make an api call]
4040
.call((awsRequest, sdkProxyClient) -> readResource(awsRequest, sdkProxyClient , model))
@@ -61,6 +61,12 @@ private AwsResponse readResource(
6161

6262
// e.g. https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-logs/commit/2077c92299aeb9a68ae8f4418b5e932b12a8b186#diff-5761e3a9f732dc1ef84103dc4bc93399R41-R46
6363
} catch (final AwsServiceException e) { // ResourceNotFoundException
64+
/*
65+
* While the handler contract states that the handler must always return a progress event,
66+
* you may throw any instance of BaseHandlerException, as the wrapper map it to a progress event.
67+
* Each BaseHandlerException maps to a specific error code, and you should map service exceptions as closely as possible
68+
* to more specific error codes
69+
*/
6470
throw new CfnGeneralServiceException(ResourceModel.TYPE_NAME, e); // e.g. https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-logs/commit/2077c92299aeb9a68ae8f4418b5e932b12a8b186#diff-5761e3a9f732dc1ef84103dc4bc93399R56-R63
6571
}
6672

python/rpdk/java/templates/init/guided_aws/StubUpdateHandler.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
3434
return proxy.initiate("{{ call_graph }}::{{ operation }}", proxyClient, model, callbackContext)
3535

3636
// STEP 2 [TODO: construct a body of a request]
37-
.request(Translator::translateToUpdateRequest)
37+
.translate(Translator::translateToUpdateRequest)
3838

3939
// STEP 3 [TODO: make an api call]
4040
.call(this::updateResource)
4141

4242
// STEP 4 [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]
4343
// stabilization step may or may not be needed after each API call
44-
// for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html#resource-type-test-contract-communication
44+
// for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html
4545
.stabilize(this::stabilizedOnFirstUpdate)
4646
.progress()
4747

@@ -68,13 +68,13 @@ private AwsResponse updateResource(
6868
// TODO: put your update resource code here
6969
// e.g. https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-logs/commit/2077c92299aeb9a68ae8f4418b5e932b12a8b186#diff-c959c290785791b96fa4442573750fcdR69-R74
7070

71+
} catch (final AwsServiceException e) {
7172
/*
7273
* While the handler contract states that the handler must always return a progress event,
73-
* you may throw any instance of BaseHandlerException (https://code.amazon.com/packages/AWSCloudFormationRPDKJavaPlugin/blobs/mainline/--/src/main/java/software/amazon/cloudformation/exceptions/BaseHandlerException.java),
74-
* as the wrapper map it to a progress event. Each BaseHandlerException maps to a specific error code, and you should map service exceptions as closely as possible
75-
* to more specific error codes (https://code.amazon.com/packages/AWSCloudFormationRPDKJavaPlugin/blobs/mainline/--/src/main/java/software/amazon/cloudformation/proxy/HandlerErrorCode.java)
74+
* you may throw any instance of BaseHandlerException, as the wrapper map it to a progress event.
75+
* Each BaseHandlerException maps to a specific error code, and you should map service exceptions as closely as possible
76+
* to more specific error codes
7677
*/
77-
} catch (final AwsServiceException e) {
7878
throw new CfnGeneralServiceException(ResourceModel.TYPE_NAME, e);
7979
}
8080

@@ -85,7 +85,7 @@ private AwsResponse updateResource(
8585
/**
8686
* If your resource requires some form of stabilization (e.g. service does not provide strong consistency), you will need to ensure that your code
8787
* accounts for any potential issues, so that a subsequent read/update requests will not cause any conflicts (e.g. NotFoundException/InvalidRequestException)
88-
* for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html#resource-type-test-contract-communication
88+
* for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html
8989
* @param awsResponse the aws service update resource response
9090
* @param proxyClient the aws service client to make the call
9191
* @param model resource model
@@ -123,13 +123,13 @@ private ProgressEvent<ResourceModel, CallbackContext> secondUpdate(
123123
try {
124124
// TODO: put your post update resource code here
125125

126+
} catch (final AwsServiceException e) {
126127
/*
127128
* While the handler contract states that the handler must always return a progress event,
128-
* you may throw any instance of BaseHandlerException (https://code.amazon.com/packages/AWSCloudFormationRPDKJavaPlugin/blobs/mainline/--/src/main/java/software/amazon/cloudformation/exceptions/BaseHandlerException.java),
129-
* as the wrapper map it to a progress event. Each BaseHandlerException maps to a specific error code, and you should map service exceptions as closely as possible
130-
* to more specific error codes (https://code.amazon.com/packages/AWSCloudFormationRPDKJavaPlugin/blobs/mainline/--/src/main/java/software/amazon/cloudformation/proxy/HandlerErrorCode.java)
129+
* you may throw any instance of BaseHandlerException, as the wrapper map it to a progress event.
130+
* Each BaseHandlerException maps to a specific error code, and you should map service exceptions as closely as possible
131+
* to more specific error codes
131132
*/
132-
} catch (final AwsServiceException e) {
133133
throw new CfnGeneralServiceException(ResourceModel.TYPE_NAME, e);
134134
}
135135

0 commit comments

Comments
 (0)