Skip to content

Commit 85ef205

Browse files
author
RJ Lohan
authored
Adds a proxy overload for SdkIterable calls (#190)
AWS' Java SDK v2 introduces SdkIterable responses as a clean way to interact with paginated APIs and this change adds an interface to the AmazonWebServicesClientProxy class to invoke these.
1 parent c4dc8d0 commit 85ef205

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/java/com/amazonaws/cloudformation/proxy/AmazonWebServicesClientProxy.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import software.amazon.awssdk.awscore.exception.AwsErrorDetails;
4545
import software.amazon.awssdk.awscore.exception.AwsServiceException;
4646
import software.amazon.awssdk.core.exception.NonRetryableException;
47+
import software.amazon.awssdk.core.pagination.sync.SdkIterable;
4748
import software.amazon.awssdk.http.HttpStatusCode;
4849

4950
/**
@@ -350,6 +351,24 @@ public final long getRemainingTimeInMillis() {
350351
}
351352
}
352353

354+
public <RequestT extends AwsRequest, ResultT extends AwsResponse, IterableT extends SdkIterable<ResultT>>
355+
IterableT
356+
injectCredentialsAndInvokeIterableV2(final RequestT request, final Function<RequestT, IterableT> requestFunction) {
357+
358+
AwsRequestOverrideConfiguration overrideConfiguration = AwsRequestOverrideConfiguration.builder()
359+
.credentialsProvider(v2CredentialsProvider).build();
360+
361+
@SuppressWarnings("unchecked")
362+
RequestT wrappedRequest = (RequestT) request.toBuilder().overrideConfiguration(overrideConfiguration).build();
363+
364+
try {
365+
return requestFunction.apply(wrappedRequest);
366+
} catch (final Throwable e) {
367+
loggerProxy.log(String.format("Failed to execute remote function: {%s}", e.getMessage()));
368+
throw e;
369+
}
370+
}
371+
353372
public <RequestT, ClientT, ModelT, CallbackT extends StdCallbackContext>
354373
ProgressEvent<ModelT, CallbackT>
355374
defaultHandler(RequestT request, Exception e, ClientT client, ModelT model, CallbackT context) {

0 commit comments

Comments
 (0)