Skip to content

Commit db26ec5

Browse files
author
John Tompkins
authored
Add bearerToken to response and pass it to handler as clientRequestToken (#43)
* Add bearerToken to response as well as pass it to handler as clientRequestToken * Also add errorCode to response
1 parent 4f2149a commit db26ec5

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

python/rpdk/java/templates/HandlerWrapper.java

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public InputStream provideResourceSchema() {
9797

9898
return new ResourceHandlerRequest<>(
9999
request.getAwsAccountId(),
100+
request.getBearerToken(),
100101
request.getNextToken(),
101102
request.getRegion(),
102103
request.getResourceType(),

src/main/java/com/aws/cfn/LambdaWrapper.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void handleRequest(final InputStream inputStream,
114114
} finally {
115115
// A response will be output on all paths, though CloudFormation will
116116
// not block on invoking the handlers, but rather listen for callbacks
117-
writeResponse(outputStream, createProgressResponse(handlerResponse));
117+
writeResponse(outputStream, createProgressResponse(handlerResponse, request.getBearerToken()));
118118
}
119119
}
120120

@@ -237,11 +237,13 @@ public ProgressEvent<ResourceT, CallbackT> processInvocation(final HandlerReques
237237
return handlerResponse;
238238
}
239239

240-
private Response<ResourceT> createProgressResponse(final ProgressEvent<ResourceT, CallbackT> progressEvent) {
240+
private Response<ResourceT> createProgressResponse(final ProgressEvent<ResourceT, CallbackT> progressEvent, final String bearerToken) {
241241
final Response<ResourceT> response = new Response<>();
242242
response.setMessage(progressEvent.getMessage());
243243
response.setOperationStatus(progressEvent.getStatus());
244244
response.setResourceModel(progressEvent.getResourceModel());
245+
response.setBearerToken(bearerToken);
246+
response.setErrorCode(progressEvent.getErrorCode());
245247
return response;
246248
}
247249

src/main/java/com/aws/cfn/Response.java

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88

99
@Data
1010
public class Response<ResourceT> {
11+
/**
12+
* The bearerToken is used to report progress back to CloudFormation and is passed
13+
* back to CloudFormation
14+
*/
15+
private String bearerToken;
16+
17+
/**
18+
* The errorCode is used to report granular failures back to CloudFormation
19+
*/
20+
private HandlerErrorCode errorCode;
21+
1122
/**
1223
* The operationStatus indicates whether the handler has reached a terminal state or
1324
* is still computing and requires more time to complete

src/main/java/com/aws/cfn/proxy/ResourceHandlerRequest.java

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@Builder(toBuilder = true)
1717
public class ResourceHandlerRequest<T> {
1818
private String awsAccountId;
19+
private String clientRequestToken;
1920
private String nextToken;
2021
private String region;
2122
private String resourceType;

src/test/java/com/aws/cfn/LambdaWrapperTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private void testInvokeHandler_NullResponse(final String requestDataPath,
128128
// verify output response
129129
assertThat(
130130
out.toString(),
131-
is(equalTo("{\"operationStatus\":\"FAILED\",\"resourceModel\":{\"property2\":123,\"property1\":\"abc\"}," +
131+
is(equalTo("{\"operationStatus\":\"FAILED\",\"bearerToken\":\"123456\",\"resourceModel\":{\"property2\":123,\"property1\":\"abc\"}," +
132132
"\"message\":\"Handler failed to provide a response.\"}"))
133133
);
134134
}
@@ -205,7 +205,7 @@ private void testInvokeHandler_Failed(final String requestDataPath,
205205
// verify output response
206206
assertThat(
207207
out.toString(),
208-
is(equalTo("{\"operationStatus\":\"FAILED\",\"message\":\"Custom Fault\"}"))
208+
is(equalTo("{\"operationStatus\":\"FAILED\",\"bearerToken\":\"123456\",\"message\":\"Custom Fault\"}"))
209209
);
210210
}
211211

@@ -281,7 +281,7 @@ private void testInvokeHandler_CompleteSynchronously(final String requestDataPat
281281
// verify output response
282282
assertThat(
283283
out.toString(),
284-
is(equalTo("{\"operationStatus\":\"SUCCESS\"}"))
284+
is(equalTo("{\"operationStatus\":\"SUCCESS\",\"bearerToken\":\"123456\"}"))
285285
);
286286
}
287287

@@ -363,7 +363,7 @@ private void testInvokeHandler_InProgress(final String requestDataPath,
363363
// verify output response
364364
assertThat(
365365
out.toString(),
366-
is(equalTo("{\"operationStatus\":\"IN_PROGRESS\",\"resourceModel\":{}}"))
366+
is(equalTo("{\"operationStatus\":\"IN_PROGRESS\",\"bearerToken\":\"123456\",\"resourceModel\":{}}"))
367367
);
368368
}
369369

@@ -447,7 +447,7 @@ private void testReInvokeHandler_InProgress(final String requestDataPath,
447447
// verify output response
448448
assertThat(
449449
out.toString(),
450-
is(equalTo("{\"operationStatus\":\"IN_PROGRESS\",\"resourceModel\":{}}"))
450+
is(equalTo("{\"operationStatus\":\"IN_PROGRESS\",\"bearerToken\":\"123456\",\"resourceModel\":{}}"))
451451
);
452452
}
453453

@@ -526,7 +526,7 @@ private void testInvokeHandler_SchemaValidationFailure(final String requestDataP
526526
// verify output response
527527
assertThat(
528528
out.toString(),
529-
is(equalTo( "{\"operationStatus\":\"FAILED\",\"resourceModel\":{\"property2\":123,\"property1\":\"abc\"}}"))
529+
is(equalTo( "{\"operationStatus\":\"FAILED\",\"bearerToken\":\"123456\",\"resourceModel\":{\"property2\":123,\"property1\":\"abc\"}}"))
530530
);
531531
}
532532

@@ -584,7 +584,7 @@ public void testInvokeHandler_WithMalformedRequest() throws IOException {
584584
// verify output response
585585
assertThat(
586586
out.toString(),
587-
is(equalTo("{\"operationStatus\":\"SUCCESS\",\"resourceModel\":{}}"))
587+
is(equalTo("{\"operationStatus\":\"SUCCESS\",\"bearerToken\":\"123456\",\"resourceModel\":{}}"))
588588
);
589589
}
590590
}

0 commit comments

Comments
 (0)