Example usage for com.amazonaws.services.cloudformation.model CreateStackResult getStackId

List of usage examples for com.amazonaws.services.cloudformation.model CreateStackResult getStackId

Introduction

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

Prototype


public String getStackId() 

Source Link

Document

Unique identifier of the stack.

Usage

From source file:br.com.ingenieux.mojo.cloudformation.PushStackMojo.java

License:Apache License

@Override
protected Object executeInternal() throws Exception {
    shouldFailIfMissingStack(failIfMissing);

    if (!templateLocation.exists() && !templateLocation.isFile()) {
        getLog().warn("File not found (or not a file): " + templateLocation.getPath() + ". Skipping.");

        return null;
    }// w ww.  ja  v a2 s. c  o  m

    if (isNotBlank(s3Url)) {
        getLog().info("Uploading file " + this.templateLocation + " to location " + this.s3Url);

        s3Client = new BeanstalkerS3Client(getAWSCredentials(), getClientConfiguration(), getRegion());

        s3Client.setMultipartUpload(false);

        this.destinationS3Uri = new AmazonS3URI(s3Url);

        uploadContents(templateLocation, destinationS3Uri);
    } else {
        templateBody = IOUtils.toString(new FileInputStream(this.templateLocation));
    }

    {
        ValidateTemplateResult validateTemplateResult = validateTemplate();

        if (!validateTemplateResult.getParameters().isEmpty()) {
            Set<String> existingParameterNames = this.parameters.stream().map(x -> x.getParameterKey())
                    .collect(Collectors.toSet());

            Set<String> requiredParameterNames = validateTemplateResult.getParameters().stream()
                    .map(x -> x.getParameterKey()).collect(Collectors.toSet());

            for (String requiredParameter : requiredParameterNames) {
                if (!existingParameterNames.contains(requiredParameter)) {
                    getLog().warn("Missing required parameter name: " + requiredParameter);
                    getLog().warn("If its an update, will reuse previous value");
                }

                this.parameters.add(new com.amazonaws.services.cloudformation.model.Parameter()
                        .withParameterKey(requiredParameter).withUsePreviousValue(true));
            }
        }
    }

    WaitForStackCommand.WaitForStackContext ctx = null;

    Object result = null;

    if (null == stackSummary) {
        getLog().info("Must Create Stack");

        CreateStackResult createStackResult;
        result = createStackResult = createStack();

        ctx = new WaitForStackCommand.WaitForStackContext(createStackResult.getStackId(), getService(),
                this::info, 30, asList(StackStatus.CREATE_COMPLETE));

    } else {
        getLog().info("Must Update Stack");

        UpdateStackResult updateStackResult;

        result = updateStackResult = updateStack();

        if (null != result) {

            ctx = new WaitForStackCommand.WaitForStackContext(updateStackResult.getStackId(), getService(),
                    this::info, 30, asList(StackStatus.UPDATE_COMPLETE));
        }
    }

    if (null != ctx)
        new WaitForStackCommand(ctx).execute();

    return result;
}

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  w  w.  j  a va2 s.c o m
    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.netflix.spinnaker.clouddriver.aws.deploy.ops.DeployCloudFormationAtomicOperation.java

License:Apache License

private String createStack(AmazonCloudFormation amazonCloudFormation, String template,
        List<Parameter> parameters) {
    Task task = TaskRepository.threadLocalTask.get();
    task.updateStatus(BASE_PHASE, "Preparing CloudFormation Stack");
    CreateStackRequest createStackRequest = new CreateStackRequest().withStackName(description.getStackName())
            .withParameters(parameters).withTemplateBody(template);
    task.updateStatus(BASE_PHASE, "Uploading CloudFormation Stack");
    CreateStackResult createStackResult = amazonCloudFormation.createStack(createStackRequest);
    return createStackResult.getStackId();
}

From source file:com.nike.cerberus.service.CloudFormationService.java

License:Apache License

/**
 * Creates a new stack./*from   w  w  w . ja  v  a2s.  c o  m*/
 *
 * @param name Stack name.
 * @param parameters Input parameters.
 * @param templatePath Classpath to the JSON template of the stack.
 * @return Stack ID
 */
public String createStack(final String name, final Map<String, String> parameters, final String templatePath,
        final boolean iamCapabilities) {
    logger.info(String.format("Executing the Cloud Formation: %s, Stack Name: %s", templatePath, name));

    final CreateStackRequest request = new CreateStackRequest().withStackName(name)
            .withParameters(convertParameters(parameters)).withTemplateBody(getTemplateText(templatePath));

    if (iamCapabilities) {
        request.getCapabilities().add("CAPABILITY_IAM");
    }

    final CreateStackResult result = cloudFormationClient.createStack(request);
    return result.getStackId();
}

From source file:jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationMigrateStackTask.java

License:Apache License

private void createStack(AmazonCloudFormation cfn) throws IOException {
    // to enable conventionMappings feature
    String stackName = getStackName();
    String cfnTemplateUrl = getCfnTemplateUrl();
    File cfnTemplateFile = getCfnTemplateFile();
    List<Parameter> cfnStackParams = getCfnStackParams();
    List<Tag> cfnStackTags = getCfnStackTags();
    String cfnStackPolicyUrl = getCfnStackPolicyUrl();
    File cfnStackPolicyFile = getCfnStackPolicyFile();
    String cfnOnFailure = getCfnOnFailure();

    getLogger().info("create stack: {}", stackName);

    CreateStackRequest req = new CreateStackRequest().withStackName(stackName).withParameters(cfnStackParams)
            .withTags(cfnStackTags).withOnFailure(cfnOnFailure);

    // If template URL is specified, then use it
    if (Strings.isNullOrEmpty(cfnTemplateUrl) == false) {
        req.setTemplateURL(cfnTemplateUrl);
        // Else, use the template file body
    } else {//from ww w.j a va  2 s .  co m
        req.setTemplateBody(FileUtils.readFileToString(cfnTemplateFile));
    }
    if (isCapabilityIam()) {
        Capability selectedCapability = (getUseCapabilityIam() == null) ? Capability.CAPABILITY_IAM
                : getUseCapabilityIam();
        getLogger().info("Using IAM capability: " + selectedCapability);
        req.setCapabilities(Arrays.asList(selectedCapability.toString()));
    }

    // If stack policy is specified, then use it
    if (Strings.isNullOrEmpty(cfnStackPolicyUrl) == false) {
        req.setStackPolicyURL(cfnStackPolicyUrl);
        // Else, use the stack policy file body
    } else if (cfnStackPolicyFile != null) {
        req.setStackPolicyBody(FileUtils.readFileToString(cfnStackPolicyFile));
    }

    CreateStackResult createStackResult = cfn.createStack(req);
    getLogger().info("create requested: {}", createStackResult.getStackId());
}

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

License:BSD License

private void writeStackResult(CreateStackResult result, String name) throws XMLStreamException {
    startElement("stack");
    attribute("stack-id", result.getStackId());
    attribute("stack-name", name);
    endElement();/* w ww .java  2  s  .c om*/

}

From source file:org.xmlsh.aws.gradle.cloudformation.AmazonCloudFormationCreateStackTask.java

License:BSD License

private void createStack(AmazonCloudFormation cfn) {
    // to enable conventionMappings feature
    String stackName = getStackName();
    List<Parameter> cfnStackParams = getCfnStackParams();

    getLogger().info("create stack: {}", stackName);

    CreateStackRequest req = new CreateStackRequest().withStackName(stackName).withParameters(cfnStackParams)
            .withTemplateBody(getTemplateBody()).withDisableRollback(isDisableRollback())
            .withOnFailure(getOnFailure()).withTags(getTags());
    if (isCapabilityIam()) {
        req.setCapabilities(Arrays.asList(Capability.CAPABILITY_IAM.toString()));
    }//w  w  w.j  a va  2  s . c o  m
    CreateStackResult createStackResult = cfn.createStack(req);
    getLogger().info("create requested: {}", createStackResult.getStackId());
}

From source file:org.xmlsh.aws.gradle.cloudformation.AmazonCloudFormationMigrateStackTask.java

License:BSD License

private void createStack(AmazonCloudFormation cfn) {
    // to enable conventionMappings feature
    String stackName = getStackName();
    List<Parameter> cfnStackParams = getCfnStackParams();

    getLogger().info("create stack: {}", stackName);

    CreateStackRequest req = new CreateStackRequest().withStackName(stackName).withParameters(cfnStackParams)
            .withTemplateBody(getTemplateBody());

    if (isCapabilityIam()) {
        req.setCapabilities(Arrays.asList(Capability.CAPABILITY_IAM.toString()));
    }//  www  .  j  a v  a 2 s .com
    CreateStackResult createStackResult = cfn.createStack(req);
    getLogger().info("create requested: {}", createStackResult.getStackId());
}

From source file:org.xmlsh.aws.gradle.cloudformation.AmazonCloudFormationUpdateStackTask.java

License:BSD License

private void createStack(AmazonCloudFormation cfn) {
    // to enable conventionMappings feature
    String stackName = getStackName();
    String cfnTemplateUrl = getCfnTemplateUrl();
    List<Parameter> cfnStackParams = getCfnStackParams();

    getLogger().info("create stack: {}", stackName);

    CreateStackRequest req = new CreateStackRequest().withStackName(stackName).withTemplateURL(cfnTemplateUrl)
            .withParameters(cfnStackParams);
    if (isCapabilityIam()) {
        req.setCapabilities(Arrays.asList(Capability.CAPABILITY_IAM.toString()));
    }/*from w  ww  . j av  a2  s  .  com*/
    CreateStackResult createStackResult = cfn.createStack(req);
    getLogger().info("create requested: {}", createStackResult.getStackId());
}