StringInputStream responseBodyStream()

in powertools-cloudformation/src/main/java/software/amazon/lambda/powertools/cloudformation/CloudFormationResponse.java [200:217]


    StringInputStream responseBodyStream(CloudFormationCustomResourceEvent event,
                                         Context context,
                                         Response resp) throws CustomResourceResponseException {
        try {
            if (resp == null) {
                ResponseBody body = new ResponseBody(event, context, Response.Status.SUCCESS, null, false);
                ObjectNode node = body.toObjectNode(null);
                return new StringInputStream(node.toString());
            } else {
                ResponseBody body = new ResponseBody(
                        event, context, resp.getStatus(), resp.getPhysicalResourceId(), resp.isNoEcho());
                ObjectNode node = body.toObjectNode(resp.getJsonNode());
                return new StringInputStream(node.toString());
            }
        } catch (RuntimeException e) {
            throw new CustomResourceResponseException("Unable to generate response body.", e);
        }
    }