in statemachine/src/main/java/com/amazonaws/stepfunctions/cloudformation/statemachine/DefinitionProcessor.java [95:130]
private static String fetchS3Definition(final S3Location s3Location, final AmazonWebServicesClientProxy proxy, final MetricsRecorder metricsRecorder) {
AmazonS3 s3Client = ClientBuilder.getS3Client();
GetObjectRequest getObjectRequest = new GetObjectRequest(s3Location.getBucket(), s3Location.getKey());
if (s3Location.getVersion() != null && !s3Location.getVersion().isEmpty()) {
getObjectRequest.setVersionId(s3Location.getVersion());
}
GetObjectResult getObjectResult = proxy.injectCredentialsAndInvoke(getObjectRequest, new GetObjectFunction(s3Client)::get);
if (getObjectResult.getS3Object().getObjectMetadata().getContentLength() > Constants.MAX_DEFINITION_SIZE) {
throw new CfnInvalidRequestException(Constants.DEFINITION_SIZE_LIMIT_ERROR_MESSAGE);
}
String definition;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(getObjectResult.getS3Object().getObjectContent()))) {
definition = reader.lines().collect(Collectors.joining("\n"));
} catch (IOException e) {
throw new CfnInternalFailureException(e);
}
// Parse JSON format first, then YAML.
try {
jsonMapper.readTree(definition);
metricsRecorder.setS3DefinitionJson(true);
} catch (IOException jsonException) {
try {
JsonNode root = yamlMapper.readTree(definition);
definition = jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(root);
metricsRecorder.setS3DefinitionYaml(true);
} catch (IOException yamlException) {
throw new TerminalException(Constants.DEFINITION_INVALID_FORMAT_ERROR_MESSAGE);
}
}
return definition;
}