Example usage for com.amazonaws.services.cloudformation.model ValidateTemplateResult toString

List of usage examples for com.amazonaws.services.cloudformation.model ValidateTemplateResult toString

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudformation.model ValidateTemplateResult toString.

Prototype

@Override
public String toString() 

Source Link

Document

Returns a string representation of this object.

Usage

From source file:com.mweagle.tereus.commands.CreateCommand.java

License:Open Source License

protected void validateTemplate(TereusInput tereusInput, String parameterizedTemplate)
        throws UnsupportedEncodingException {
    if (tereusInput.dryRun) {
        tereusInput.logger.info("Dry run requested (-n/--noop). Stack validation bypassed.");
    } else {/*from   w w w  .j av a  2s  . c  o m*/
        tereusInput.logger.info("Validating template with AWS");
        final String bucketName = tereusInput.params.get(CONSTANTS.PARAMETER_NAMES.S3_BUCKET_NAME).toString();
        final byte[] templateBytes = parameterizedTemplate.getBytes("UTF-8");
        final InputStream is = new ByteArrayInputStream(templateBytes);

        final String templateDigest = DigestUtils.sha256Hex(templateBytes);
        final String keyName = String.format("%s-tereus-pre.cf.template", templateDigest);
        try (S3Resource resource = new S3Resource(bucketName, keyName, is,
                Optional.of(Long.valueOf(templateBytes.length)))) {
            Optional<String> templateURL = resource.upload();
            final ValidateTemplateRequest validationRequest = new ValidateTemplateRequest();
            validationRequest.setTemplateURL(templateURL.get());
            final AmazonCloudFormationClient awsClient = new AmazonCloudFormationClient(
                    tereusInput.awsCredentials);
            awsClient.setRegion(tereusInput.awsRegion);
            final ValidateTemplateResult validationResult = awsClient.validateTemplate(validationRequest);
            tereusInput.logger.debug("Stack template validation results:");
            tereusInput.logger.debug(validationResult.toString());
        }
    }
}