Example usage for com.amazonaws.services.cloudformation.model Stack getCapabilities

List of usage examples for com.amazonaws.services.cloudformation.model Stack getCapabilities

Introduction

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

Prototype


public java.util.List<String> getCapabilities() 

Source Link

Document

The capabilities allowed in the stack.

Usage

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

License:Apache License

public void execute() throws MojoExecutionException {
    getLog().info("Bucket Name: " + bucketName);
    //getLog().info("Cloud Formation Stack Name: " + stackName);

    if (artifactFile == null || !artifactFile.isFile()) {
        throw new MojoExecutionException("Cannot find artifact file to upload");
    }//w  w w  .  j  a va 2  s .c  om
    String artifactKey = artifactFile.getName();
    getLog().info("Artifact Name: " + artifactKey);

    BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
    AmazonCloudFormationClient cfClient = new AmazonCloudFormationClient(awsCredentials);
    cfClient.setEndpoint(getCloudFormationEndPoint());
    AmazonS3Client s3Client = new AmazonS3Client(awsCredentials);

    // Upload Artifact to S3
    try {
        getLog().info("Uploading artifact to S3...");
        s3Client.putObject(bucketName, artifactKey, artifactFile);
    } catch (AmazonServiceException e) {
        throw new MojoExecutionException("[SERVICE] Could Not Upload File to S3", e);
    } catch (AmazonClientException e) {
        throw new MojoExecutionException("[CLIENT] Could Not Upload File to S3", e);
    }

    // Update each stack with the new artifact file
    for (String stackName : stackNames) {
        getLog().info("Cloud Formation Stack Name: " + stackName);
        String templateBody = getTemplateBody(cfClient, stackName);
        Stack stack = getStack(cfClient, stackName);

        // If passed additional parameters, update them
        List<Parameter> parameters = stack.getParameters();
        if (stackParameters != null && !stackParameters.isEmpty()) {
            List<Parameter> tmpParams = new ArrayList<Parameter>();

            // Add Existing Parameters we haven't locally overwritten
            for (Parameter oldParam : parameters) {
                String oldKey = oldParam.getParameterKey();
                if (!stackParameters.containsKey(oldKey)) {
                    tmpParams.add(oldParam);
                }
            }

            // Add Overwrite parameters
            for (String key : stackParameters.keySet()) {
                Parameter newParam = new Parameter();
                newParam.setParameterKey(key);
                newParam.setParameterValue(stackParameters.get(key));
                tmpParams.add(newParam);
            }
            parameters = tmpParams;
        }

        // Update the Stack
        UpdateStackRequest updateStackRequest = new UpdateStackRequest();
        updateStackRequest.setStackName(stackName);
        updateStackRequest.setTemplateBody(templateBody);
        updateStackRequest.setParameters(parameters);
        updateStackRequest.setCapabilities(stack.getCapabilities());
        try {
            getLog().info("Updating Cloud Formation Stack...");
            cfClient.updateStack(updateStackRequest);
        } catch (AmazonServiceException e) {
            throw new MojoExecutionException("[SERVICE] Could Not Update Cloud Formation Stack", e);
        } catch (AmazonClientException e) {
            throw new MojoExecutionException("[CLIENT] Could Not Update Cloud Formation Stack", e);
        }
        getLog().info("Cloud Formation Stack " + stackName + "is now updating...");
    }

    getLog().info("All stacks have been updated. Complete.");
}

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

License:BSD License

private void writeStack(Stack stack) throws XMLStreamException {
    startElement("stack");
    attribute("creation-time", stack.getCreationTime());
    attribute("description", stack.getDescription());
    attribute("disable-rollback", stack.getDisableRollback());
    attribute("last-update-time", stack.getLastUpdatedTime());
    attribute("stack-id", stack.getStackId());
    attribute("stack-name", stack.getStackName());
    attribute("stack-status", stack.getStackStatus());
    attribute("stack-status-reason", stack.getStackStatusReason());
    attribute("timeout", stack.getTimeoutInMinutes());

    writeParameters(stack.getParameters());
    writeOutputs(stack.getOutputs());//from   w  w  w .ja  v a 2  s . c o m
    writeCapibilities(stack.getCapabilities());
    writeNotifications(stack.getNotificationARNs());
    writeTags(stack.getTags());
}