Example usage for com.amazonaws.services.cloudformation.model CreateStackRequest getStackName

List of usage examples for com.amazonaws.services.cloudformation.model CreateStackRequest getStackName

Introduction

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

Prototype


public String getStackName() 

Source Link

Document

The name that is associated with the stack.

Usage

From source file:CloudFormation.java

License:Open Source License

public static void main(String[] args) throws Exception {
    /*/*from ww  w  .  ja  v  a 2  s .  c  o  m*/
     * This credentials provider implementation loads your AWS credentials
     * from a properties file at the root of your classpath.
     * Important: Be sure to fill in your AWS access credentials in the
     *            AwsCredentials.properties file before you try to run this
     *            sample.
     * http://aws.amazon.com/security-credentials
     */
    AmazonCloudFormation stackbuilder = new AmazonCloudFormationClient(
            new ClasspathPropertiesFileCredentialsProvider());
    Region usWest2 = Region.getRegion(Regions.US_EAST_1);
    stackbuilder.setRegion(usWest2);

    System.out.println("===========================================");
    System.out.println("Getting Started with AWS CloudFormation");
    System.out.println("===========================================\n");

    String stackName = "CloudFormationSampleStack";
    String logicalResourceName = "SampleNotificationTopic";

    try {
        // Create a stack
        CreateStackRequest createRequest = new CreateStackRequest();
        createRequest.setStackName(stackName);
        createRequest.setTemplateBody(
                convertStreamToString(CloudFormation.class.getResourceAsStream("CloudFormation.template")));
        System.out.println("Creating a stack called " + createRequest.getStackName() + ".");
        stackbuilder.createStack(createRequest);

        // Wait for stack to be created
        // Note that you could use SNS notifications on the CreateStack call to track the progress of the stack creation
        System.out.println("Stack creation completed, the stack " + stackName + " completed with "
                + waitForCompletion(stackbuilder, stackName));

        // Show all the stacks for this account along with the resources for each stack
        for (Stack stack : stackbuilder.describeStacks(new DescribeStacksRequest()).getStacks()) {
            System.out.println(
                    "Stack : " + stack.getStackName() + " [" + stack.getStackStatus().toString() + "]");

            DescribeStackResourcesRequest stackResourceRequest = new DescribeStackResourcesRequest();
            stackResourceRequest.setStackName(stack.getStackName());
            for (StackResource resource : stackbuilder.describeStackResources(stackResourceRequest)
                    .getStackResources()) {
                System.out.format("    %1$-40s %2$-25s %3$s\n", resource.getResourceType(),
                        resource.getLogicalResourceId(), resource.getPhysicalResourceId());
            }
        }

        // Lookup a resource by its logical name
        DescribeStackResourcesRequest logicalNameResourceRequest = new DescribeStackResourcesRequest();
        logicalNameResourceRequest.setStackName(stackName);
        logicalNameResourceRequest.setLogicalResourceId(logicalResourceName);
        System.out.format("Looking up resource name %1$s from stack %2$s\n",
                logicalNameResourceRequest.getLogicalResourceId(), logicalNameResourceRequest.getStackName());
        for (StackResource resource : stackbuilder.describeStackResources(logicalNameResourceRequest)
                .getStackResources()) {
            System.out.format("    %1$-40s %2$-25s %3$s\n", resource.getResourceType(),
                    resource.getLogicalResourceId(), resource.getPhysicalResourceId());
        }

        // Delete the stack
        DeleteStackRequest deleteRequest = new DeleteStackRequest();
        deleteRequest.setStackName(stackName);
        System.out.println("Deleting the stack called " + deleteRequest.getStackName() + ".");
        stackbuilder.deleteStack(deleteRequest);

        // Wait for stack to be deleted
        // Note that you could used SNS notifications on the original CreateStack call to track the progress of the stack deletion
        System.out.println("Stack creation completed, the stack " + stackName + " completed with "
                + waitForCompletion(stackbuilder, stackName));

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS CloudFormation, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with AWS CloudFormation, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:CloudFormationSample.java

License:Open Source License

public static void main(String[] args) throws Exception {
    /*/*w  w w.j  a  v  a2  s . c  om*/
    * Important: Be sure to fill in your AWS access credentials in the
    *            AwsCredentials.properties file before you try to run this
    *            sample.
    * http://aws.amazon.com/security-credentials
    */
    AmazonCloudFormation stackbuilder = new AmazonCloudFormationClient(new PropertiesCredentials(
            CloudFormationSample.class.getResourceAsStream("AwsCredentials.properties")));

    System.out.println("===========================================");
    System.out.println("Getting Started with AWS CloudFormation");
    System.out.println("===========================================\n");

    String stackName = "CloudFormationSampleStack";
    String logicalResourceName = "SampleNotificationTopic";

    try {
        // Create a stack
        CreateStackRequest createRequest = new CreateStackRequest();
        createRequest.setStackName(stackName);
        createRequest.setTemplateBody(convertStreamToString(
                CloudFormationSample.class.getResourceAsStream("CloudFormationSample.template")));
        System.out.println("Creating a stack called " + createRequest.getStackName() + ".");
        stackbuilder.createStack(createRequest);

        // Wait for stack to be created
        // Note that you could use SNS notifications on the CreateStack call to track the progress of the stack creation
        System.out.println("Stack creation completed, the stack " + stackName + " completed with "
                + waitForCompletion(stackbuilder, stackName));

        // Show all the stacks for this account along with the resources for each stack
        for (Stack stack : stackbuilder.describeStacks(new DescribeStacksRequest()).getStacks()) {
            System.out.println(
                    "Stack : " + stack.getStackName() + " [" + stack.getStackStatus().toString() + "]");

            DescribeStackResourcesRequest stackResourceRequest = new DescribeStackResourcesRequest();
            stackResourceRequest.setStackName(stack.getStackName());
            for (StackResource resource : stackbuilder.describeStackResources(stackResourceRequest)
                    .getStackResources()) {
                System.out.format("    %1$-40s %2$-25s %3$s\n", resource.getResourceType(),
                        resource.getLogicalResourceId(), resource.getPhysicalResourceId());
            }
        }

        // Lookup a resource by its logical name
        DescribeStackResourcesRequest logicalNameResourceRequest = new DescribeStackResourcesRequest();
        logicalNameResourceRequest.setStackName(stackName);
        logicalNameResourceRequest.setLogicalResourceId(logicalResourceName);
        System.out.format("Looking up resource name %1$s from stack %2$s\n",
                logicalNameResourceRequest.getLogicalResourceId(), logicalNameResourceRequest.getStackName());
        for (StackResource resource : stackbuilder.describeStackResources(logicalNameResourceRequest)
                .getStackResources()) {
            System.out.format("    %1$-40s %2$-25s %3$s\n", resource.getResourceType(),
                    resource.getLogicalResourceId(), resource.getPhysicalResourceId());
        }

        // Delete the stack
        DeleteStackRequest deleteRequest = new DeleteStackRequest();
        deleteRequest.setStackName(stackName);
        System.out.println("Deleting the stack called " + deleteRequest.getStackName() + ".");
        stackbuilder.deleteStack(deleteRequest);

        // Wait for stack to be deleted
        // Note that you could used SNS notifications on the original CreateStack call to track the progress of the stack deletion
        System.out.println("Stack creation completed, the stack " + stackName + " completed with "
                + waitForCompletion(stackbuilder, stackName));

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS CloudFormation, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with AWS CloudFormation, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:com.mweagle.tereus.aws.CloudFormation.java

License:Open Source License

public Optional<DescribeStacksResult> createStack(final CreateStackRequest request, final Region awsRegion,
        Logger logger) {/*from   w ww  .j  av  a2  s . c om*/
    DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain();
    final AmazonCloudFormationAsyncClient awsClient = new AmazonCloudFormationAsyncClient(
            credentialProviderChain.getCredentials());
    awsClient.setRegion(awsRegion);
    logger.info("Creating stack: {}", request.getStackName());
    Optional<DescribeStacksResult> completionResult = Optional.empty();

    try {
        // There are no prior events for a creation request
        Future<CreateStackResult> createStackRequest = awsClient.createStackAsync(request);
        final CreateStackResult stackResult = createStackRequest.get();
        logger.info("Stack ({}) creation in progress.", stackResult.getStackId());
        completionResult = waitForStackComplete(awsClient, stackResult.getStackId(), Collections.emptyList(),
                logger);
    } catch (Exception ex) {
        logger.error(ex);
    }
    return completionResult;
}

From source file:com.tvarit.plugin.StackMaker.java

License:Open Source License

public Stack makeStack(CreateStackRequest createStackRequest,
        AmazonCloudFormationClient amazonCloudFormationClient, Log log) throws MojoFailureException {

    CreateStackResult createStackResult = amazonCloudFormationClient.createStack(createStackRequest);
    final String stackName = createStackRequest.getStackName();
    DescribeStacksResult describeStacksResult = amazonCloudFormationClient
            .describeStacks(new DescribeStacksRequest().withStackName(stackName));
    while (describeStacksResult.getStacks().get(0).getStackStatus()
            .equals(StackStatus.CREATE_IN_PROGRESS.toString())) {
        try {//from   w w w .  j  av  a  2 s . c o  m
            log.info("Awaiting stack create completion!");
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            log.error(e);
            throw new RuntimeException(e);
        }
        describeStacksResult = amazonCloudFormationClient
                .describeStacks(new DescribeStacksRequest().withStackName(stackName));
    }
    final Stack stack = describeStacksResult.getStacks().get(0);

    final String stackStatus = stack.getStackStatus();
    if (!stackStatus.equals(StackStatus.CREATE_COMPLETE.toString())) {
        throw new MojoFailureException("Could not create infrastructure. Stack Status is: " + stackStatus
                + ". Please review details on the AWS console and open a new github issue on https://github.com/sdole/tvarit-maven/issues/new that is needed.");
    }
    return stack;
}

From source file:edu.columbia.cc.elPonePeli.app.LiveStreamingHelper.java

public void createFormation(String stackName, String logicalResourceName) {

    try {//  w  ww  .  jav a2 s.com

        // Create a stack
        Collection<Parameter> params = new ArrayList<Parameter>();
        Parameter pInstanceType = new Parameter().withParameterKey("InstanceType")
                .withParameterValue("m1.small");
        params.add(pInstanceType);
        Parameter pKeyPair = new Parameter().withParameterKey("KeyPair").withParameterValue("fbtest");
        params.add(pKeyPair);
        Parameter pLicKey = new Parameter().withParameterKey("WowzaLicenseKey")
                .withParameterValue("SVRT3-HEKkZ-zRp6C-xPTA7-b4a8P-VwR9R-7U6W7f6TXXxt");
        params.add(pLicKey);

        CreateStackRequest createRequest = new CreateStackRequest().withTemplateURL(streamingTemplateURL)
                .withStackName(streamingStackName).withParameters(params);
        System.out.println("Creating a stack called " + createRequest.getStackName() + ".");
        stackbuilder.createStack(createRequest);

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS CloudFormation, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with AWS CloudFormation, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

From source file:org.terracotta.TerracottaCloudFormationSample.java

License:Open Source License

@org.junit.BeforeClass
public static void createStack() throws Exception {

    /*//from  w w  w .j a v a2  s. c o m
    * Important: Be sure to fill in your AWS access credentials in the
    *            AwsCredentials.properties file before you try to run this
    *            sample.
    * http://aws.amazon.com/security-credentials
    */
    amazonCloudFormationClient = new AmazonCloudFormationClient(new PropertiesCredentials(
            TerracottaCloudFormationSample.class.getResourceAsStream("/AwsCredentials.properties")));

    System.out.println("================================");
    System.out.println("Terracotta CloudFormation Sample");
    System.out.println("================================\n");

    try {
        // Create a stack
        CreateStackRequest createRequest = new CreateStackRequest();
        createRequest.setStackName(stackName);
        createRequest.setTemplateBody(convertStreamToString(
                TerracottaCloudFormationSample.class.getResourceAsStream("/TerracottaServerArray.template")));

        Parameter parameter = new Parameter();
        parameter.setParameterKey("KeyName");
        parameter.setParameterValue(keyChainName);
        List parameters = new ArrayList();
        parameters.add(parameter);
        createRequest.setParameters(parameters);
        System.out.println("Creating a stack called " + createRequest.getStackName() + ".");
        amazonCloudFormationClient.createStack(createRequest);

        // Wait for stack to be created
        // Note that you could use SNS notifications on the CreateStack call to track the progress of the stack creation
        System.out.println("Stack creation completed, the stack " + stackName + " completed with "
                + waitForCompletion(amazonCloudFormationClient, stackName));

        // Show all the stacks for this account along with the resources for each stack
        for (Stack stack : amazonCloudFormationClient.describeStacks(new DescribeStacksRequest()).getStacks()) {
            System.out.println(
                    "Stack : " + stack.getStackName() + " [" + stack.getStackStatus().toString() + "]");

            DescribeStackResourcesRequest stackResourceRequest = new DescribeStackResourcesRequest();
            stackResourceRequest.setStackName(stack.getStackName());
            for (StackResource resource : amazonCloudFormationClient
                    .describeStackResources(stackResourceRequest).getStackResources()) {
                System.out.format("    %1$-40s %2$-25s %3$s\n", resource.getResourceType(),
                        resource.getLogicalResourceId(), resource.getPhysicalResourceId());
            }
        }

        // Lookup a resource by its logical name
        DescribeStackResourcesRequest logicalNameResourceRequest = new DescribeStackResourcesRequest();
        logicalNameResourceRequest.setStackName(stackName);
        logicalNameResourceRequest.setLogicalResourceId(logicalResourceName);
        System.out.format("Looking up resource name %1$s from stack %2$s\n",
                logicalNameResourceRequest.getLogicalResourceId(), logicalNameResourceRequest.getStackName());
        for (StackResource resource : amazonCloudFormationClient
                .describeStackResources(logicalNameResourceRequest).getStackResources()) {
            System.out.format("    %1$-40s %2$-25s %3$s\n", resource.getResourceType(),
                    resource.getLogicalResourceId(), resource.getPhysicalResourceId());
        }

        //deleteStack

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS CloudFormation, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with AWS CloudFormation, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}

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

License:BSD License

private int createStack(Options opts) throws IOException, XMLStreamException, SaxonApiException, CoreException {

    OutputPort stdout = getStdout();//  www  .  j  a v  a  2 s.  co m
    mWriter = new SafeXMLStreamWriter(stdout.asXMLStreamWriter(getSerializeOpts()));

    startDocument();
    startElement(getName());

    CreateStackRequest request = new CreateStackRequest();

    // "capability:+,disable-rollback,notification-arn:+,name:,template:,timeout:,tag:+");

    if (opts.hasOpt("capability"))
        request.setCapabilities(Util.toStringList(opts.getOptValues("capability")));

    String onFail = opts.getOptString("on-failure", null);
    if (onFail != null)
        request.setOnFailure(OnFailure.fromValue(onFail));
    else
        request.setDisableRollback(opts.getOptFlag("disable-rollback", false));

    if (opts.hasOpt("notification-arn"))
        request.setNotificationARNs(Util.toStringList(opts.getOptValues("notification-arn")));

    request.setStackName(opts.getOptStringRequired("name"));

    if (opts.hasOpt("template-file"))
        request.setTemplateBody(Util.readString(mShell.getFile(opts.getOptValue("template-file")),
                getSerializeOpts().getInput_text_encoding()));
    else
        request.setTemplateURL(opts.getOptStringRequired("template-url"));

    if (opts.hasOpt("timeout"))
        request.setTimeoutInMinutes((int) opts.getOptLong("timeout", 10));
    if (opts.hasOpt("tag"))
        request.setTags(getTags(opts.getOptValues("tag")));

    request.setParameters(getParameters(opts));

    traceCall("createStack");

    CreateStackResult result = getAWSClient().createStack(request);

    writeStackResult(result, request.getStackName());

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

    stdout.writeSequenceTerminator(getSerializeOpts());

    return 0;

}