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

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

Introduction

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

Prototype


public void setStackPolicyURL(String stackPolicyURL) 

Source Link

Document

Location of a file containing the stack policy.

Usage

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.  ja v  a2  s .c om
        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());
}