Java Code Examples for com.amazonaws.services.cloudformation.AmazonCloudFormationClient#createStack()

The following examples show how to use com.amazonaws.services.cloudformation.AmazonCloudFormationClient#createStack() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloudFormationManagerTest.java    From AWS-MIMIC-IIItoOMOP with Apache License 2.0 6 votes vote down vote up
/**
 * Test of terminateCluster method, of class EMRManager.
 */
@Test
public void testTerminateStack() throws IOException {
    AmazonCloudFormationClient client = new AmazonCloudFormationClient();
    String name = "JUnitStack" + UUID.randomUUID().toString();
    CreateStackRequest createStackRequest = new CreateStackRequest();
    CloudFormationManager manager = new CloudFormationManager(Region.getRegion(Regions.US_WEST_2));
    
    client.setRegion(Region.getRegion(Regions.US_WEST_2));
    
    createStackRequest.setStackName(name);
    createStackRequest.setTemplateBody(IOUtils.toString(getClass().getResourceAsStream("cloudformation.template"), "UTF-8"));
    
    client.createStack(createStackRequest);
    
    manager.terminateStack(name);
    
    for(StackSummary stack : client.listStacks().getStackSummaries())
    {
        if(stack.getStackStatus().equalsIgnoreCase("DELETE_COMPLETE")) continue;
        if(stack.getStackStatus().equalsIgnoreCase("DELETE_FAILED")) continue;
        if(stack.getStackStatus().equalsIgnoreCase("DELETE_IN_PROGRESS")) continue;
        
        if(stack.getStackName().equals(name)) fail(name +  " should have been deleted but status is: " + stack.getStackStatus());
    }
}
 
Example 2
Source File: LoaderTest.java    From AWS-MIMIC-IIItoOMOP with Apache License 2.0 5 votes vote down vote up
/**
 * Test of teardown method, of class Loader.
 */
@Test
public void testTeardown() throws IOException, SQLException, ClassNotFoundException 
{
    AmazonCloudFormationClient client = new AmazonCloudFormationClient();
    String name = "TestTeardownCluster" + UUID.randomUUID().toString();
    CreateStackRequest createStackRequest = new CreateStackRequest();
    
    client.setRegion(Region.getRegion(Regions.US_WEST_2)); 
    
    createStackRequest.setStackName(name);
    createStackRequest.setTemplateBody(IOUtils.toString(getClass().getResourceAsStream("cloudformation.template"), "UTF-8"));
    
    client.createStack(createStackRequest);
    
    loader.setConfiguration(configuration);
    loader.teardown(name, Region.getRegion(Regions.US_WEST_2));
    
    for(StackSummary stack : client.listStacks().getStackSummaries())
    {
        if(stack.getStackStatus().equalsIgnoreCase("DELETE_COMPLETE")) continue;
        if(stack.getStackStatus().equalsIgnoreCase("DELETE_FAILED")) continue;
        if(stack.getStackStatus().equalsIgnoreCase("DELETE_IN_PROGRESS")) continue;
        
        if(stack.getStackName().equals(name)) fail(name +  " should have been deleted but status is: " + stack.getStackStatus());
    }
}
 
Example 3
Source File: CreateStackTask.java    From aws-ant-tasks with Apache License 2.0 5 votes vote down vote up
public void execute() {
    checkParams();
    AmazonCloudFormationClient client = getOrCreateClient(AmazonCloudFormationClient.class);
    CreateStackRequest createStackRequest = new CreateStackRequest()
            .withDisableRollback(disableRollback).withOnFailure(onFailure)
            .withStackName(stackName).withStackPolicyBody(stackPolicyBody)
            .withStackPolicyURL(stackPolicyURL)
            .withTemplateBody(templateBody).withTemplateURL(templateURL)
            .withTimeoutInMinutes(timeoutInMinutes);

    if (capabilities.size() > 0) {
        createStackRequest.setCapabilities(capabilities);
    }
    if (parameters.size() > 0) {
        createStackRequest.setParameters(parameters);
    }
    if (tags.size() > 0) {
        createStackRequest.setTags(tags);
    }
    try {
        client.createStack(createStackRequest);
        System.out.println("Create stack " + stackName
                + " request submitted.");
        if(waitForCreation) {
            WaitForStackToReachStateTask.waitForCloudFormationStackToReachStatus(client, stackName, CREATE_COMPLETE);
        }
    } catch (Exception e) {
        throw new BuildException(
                "Could not create stack " + e.getMessage(), e);
    }
}