in gremlin-client/src/main/java/software/amazon/neptune/cluster/GetEndpointsFromLambdaProxy.java [122:166]
public NeptuneClusterMetadata refreshClusterMetadata() {
Callable<NeptuneClusterMetadata> query = () -> {
InvokeRequest invokeRequest = InvokeRequest.builder()
.functionName(lambdaName)
.payload(SdkBytes.fromUtf8String("\"\""))
.build();
InvokeResponse result = lambdaClient.invoke(invokeRequest);
if (StringUtils.isNotEmpty(result.functionError())){
String payload = result.payload().asUtf8String();
if (payload.contains("Task timed out after")){
throw new TimeoutException(String.format("Lambda proxy invocation timed out. Last error message: %s", payload));
} else {
throw new RuntimeException(String.format("Unexpected error while invoking Lambda proxy: %s", payload));
}
}
return NeptuneClusterMetadata.fromByteArray(result.payload().asByteArray());
};
@SuppressWarnings("unchecked")
CallExecutor<NeptuneClusterMetadata> executor =
new CallExecutorBuilder<NeptuneClusterMetadata>().config(retryConfig).build();
Status<NeptuneClusterMetadata> status;
try {
status = executor.execute(query);
} catch (UnexpectedException e) {
if (e.getCause() instanceof MismatchedInputException) {
throw new IllegalStateException(String.format("The AWS Lambda proxy (%s) isn't returning a NeptuneClusterMetadata JSON document. Check that the function supports returning a NeptuneClusterMetadata JSON document.", lambdaName), e.getCause());
} else {
throw new IllegalStateException(String.format("There was an unexpected error while attempting to get a NeptuneClusterMetadata JSON document from the AWS Lambda proxy (%s). Check that the function supports returning a NeptuneClusterMetadata JSON document.", lambdaName), e.getCause());
}
}
NeptuneClusterMetadata clusterMetadata = status.getResult();
cachedClusterMetadata.set(clusterMetadata);
logger.debug("clusterMetadata: {}", clusterMetadata);
return clusterMetadata;
}