Example usage for com.amazonaws.services.cloudformation.model GetTemplateRequest GetTemplateRequest

List of usage examples for com.amazonaws.services.cloudformation.model GetTemplateRequest GetTemplateRequest

Introduction

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

Prototype

GetTemplateRequest

Source Link

Usage

From source file:com.cleanenergyexperts.aws.cf.CloudFormationMojo.java

License:Apache License

protected String getTemplateBody(AmazonCloudFormationClient cfClient, String stackName)
        throws MojoExecutionException {
    String templateBody = null;/*  w w  w . j  a v a2s  . c  o  m*/
    try {
        GetTemplateRequest getTemplateRequest = new GetTemplateRequest();
        getTemplateRequest.setStackName(stackName);
        getLog().info("Getting Cloud Formation Stack Template...");
        GetTemplateResult getTemplateResult = cfClient.getTemplate(getTemplateRequest);
        if (getTemplateResult == null) {
            throw new MojoExecutionException("[NULL] Could Not Get Cloud Formation Stack Template");
        }
        templateBody = getTemplateResult.getTemplateBody();
    } catch (AmazonServiceException e) {
        throw new MojoExecutionException("[SERVICE] Could Not Get Cloud Formation Stack Template", e);
    } catch (AmazonClientException e) {
        throw new MojoExecutionException("[CLIENT] Could Not Get Cloud Formation Stack Template", e);
    }
    return templateBody;
}

From source file:com.deploymentio.cfnstacker.CloudFormationClient.java

License:Apache License

/**
 * Looks up a stack's template from Cloud formation
 *//*from   ww  w.  ja  v  a2s . co m*/
public JsonNode getTemplateValue(String stackName) throws Exception {
    String templateBody = client.getTemplate(new GetTemplateRequest().withStackName(stackName))
            .getTemplateBody();
    return new ObjectMapper().readTree(templateBody);
}

From source file:com.mweagle.tereus.commands.pipelines.UpdatePipeline.java

License:Open Source License

protected void publishGlobals(ScriptEngine engine) {
    super.publishGlobals(engine);

    // Publish a function that accepts a stack target name, defined by the patch
    // file, that represents the target.  We'll push all this
    Function<String, String> fnStackInfo = (stackName) -> {
        // Get the information...
        final GetTemplateRequest templateRequest = new GetTemplateRequest().withStackName(stackName);
        final AmazonCloudFormationAsyncClient awsClient = new AmazonCloudFormationAsyncClient(
                super.getAwsCredentials());
        awsClient.setRegion(super.getRegion());
        final GetTemplateResult stackTemplateResult = awsClient.getTemplate(templateRequest);

        // Get the stack info and return it
        final DescribeStacksRequest describeRequest = new DescribeStacksRequest().withStackName(stackName);
        final DescribeStacksResult describeResult = awsClient.describeStacks(describeRequest);

        // And finally the tags and parameters
        final Stack stackInfo = !describeResult.getStacks().isEmpty() ? describeResult.getStacks().get(0)
                : null;/*from ww  w  .j  a  v a2  s. c  om*/
        final Map<String, Object> tags = (stackInfo != null)
                ? stackInfo.getTags().stream().collect(Collectors.toMap(Tag::getKey, Tag::getValue))
                : Collections.emptyMap();

        final Map<String, Object> params = (stackInfo != null)
                ? stackInfo.getParameters().stream()
                        .collect(Collectors.toMap(Parameter::getParameterKey, Parameter::getParameterValue))
                : Collections.emptyMap();

        HashMap<String, Object> results = new HashMap<>();
        results.put("tags", tags);
        results.put("params", params);
        results.put("stack", stackInfo);
        results.put("template", stackTemplateResult.getTemplateBody().toString());
        Gson gson = new Gson();
        return gson.toJson(results);
    };
    engine.put("TargetStackInfoImpl", fnStackInfo);

    Supplier<String> fnArgs = () -> {
        HashMap<String, Map<String, Object>> args = new HashMap<>();
        args.put("arguments", this.arguments);
        Gson gson = new Gson();
        return gson.toJson(args);
    };
    engine.put("ArgumentsImpl", fnArgs);
}

From source file:org.xmlsh.aws.cfnGetTemplate.java

License:BSD License

private int getTemplate(String stack, boolean bJson)
        throws IOException, XMLStreamException, SaxonApiException, CoreException {

    OutputPort stdout = getStdout();//from  ww w. ja v a2s  .co  m

    GetTemplateRequest request = new GetTemplateRequest().withStackName(stack);

    traceCall("getTemplate");

    GetTemplateResult result = getAWSClient().getTemplate(request);

    if (bJson) {
        SerializeOpts opts = getSerializeOpts().clone();
        opts.setOutput_text_encoding("utf-8");

        PrintWriter w = stdout.asPrintWriter(opts);
        w.print(result.getTemplateBody());
        w.close();

    } else {
        mWriter = new SafeXMLStreamWriter(stdout.asXMLStreamWriter(getSerializeOpts()));

        startDocument();
        startElement(this.getName());

        characters(result.getTemplateBody());

        endElement();
        endDocument();
        closeWriter();

        stdout.writeSequenceTerminator(getSerializeOpts());
    }
    return 0;

}