List of usage examples for com.amazonaws.services.cloudformation.model CreateChangeSetRequest setTemplateBody
public void setTemplateBody(String templateBody)
A structure that contains the body of the revised template, with a minimum length of 1 byte and a maximum length of 51,200 bytes.
From source file:de.taimos.pipeline.aws.cloudformation.CloudFormationStack.java
License:Apache License
public void createChangeSet(String changeSetName, String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags, long pollIntervallMillis, ChangeSetType changeSetType, String roleArn) throws ExecutionException { try {//from ww w . ja v a 2 s . c o m CreateChangeSetRequest req = new CreateChangeSetRequest(); req.withChangeSetName(changeSetName).withStackName(this.stack) .withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM) .withChangeSetType(changeSetType); if (ChangeSetType.CREATE.equals(changeSetType)) { this.listener.getLogger().format("Creating CloudFormation change set %s for new stack %s %n", changeSetName, this.stack); if ((templateBody == null || templateBody.isEmpty()) && (templateUrl == null || templateUrl.isEmpty())) { throw new IllegalArgumentException("Either a file or url for the template must be specified"); } req.withTemplateBody(templateBody).withTemplateURL(templateUrl); } else if (ChangeSetType.UPDATE.equals(changeSetType)) { this.listener.getLogger().format("Creating CloudFormation change set %s for existing stack %s %n", changeSetName, this.stack); if (templateBody != null && !templateBody.isEmpty()) { req.setTemplateBody(templateBody); } else if (templateUrl != null && !templateUrl.isEmpty()) { req.setTemplateURL(templateUrl); } else { req.setUsePreviousTemplate(true); } } else { throw new IllegalArgumentException( "Cannot create a CloudFormation change set without a valid change set type."); } req.withParameters(params).withTags(tags).withRoleARN(roleArn); this.client.createChangeSet(req); new EventPrinter(this.client, this.listener).waitAndPrintChangeSetEvents(this.stack, changeSetName, this.client.waiters().changeSetCreateComplete(), pollIntervallMillis); this.listener.getLogger().format("Created CloudFormation change set %s for stack %s %n", changeSetName, this.stack); } catch (ExecutionException e) { try { if (this.changeSetExists(changeSetName) && !this.changeSetHasChanges(changeSetName)) { // Ignore the failed creation of a change set with no changes. this.listener.getLogger().format("Created empty change set %s for stack %s %n", changeSetName, this.stack); return; } } catch (Throwable throwable) { e.addSuppressed(throwable); } this.listener.getLogger().format("Failed to create CloudFormation change set %s for stack %s %n", changeSetName, this.stack); throw e; } }
From source file:jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationCreateChangeSetTask.java
License:Apache License
private void createChangeSet(AmazonCloudFormation cfn) throws IOException { // to enable conventionMappings feature String stackName = getStackName(); String cfnTemplateUrl = getCfnTemplateUrl(); List<Parameter> cfnStackParams = getCfnStackParams(); List<Tag> cfnStackTags = getCfnStackTags(); File cfnTemplateFile = getCfnTemplateFile(); String changeSetName = changeSetName(stackName); getLogger().info("Create change set '{}' for stack '{}'", changeSetName, stackName); CreateChangeSetRequest req = new CreateChangeSetRequest().withChangeSetName(changeSetName) .withStackName(stackName).withParameters(cfnStackParams).withTags(cfnStackTags); // If template URL is specified, then use it if (Strings.isNullOrEmpty(cfnTemplateUrl) == false) { req.setTemplateURL(cfnTemplateUrl); // Else, use the template file body } else {/* www. j ava 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())); } CreateChangeSetResult createChangeSetResult = cfn.createChangeSet(req); getLogger().info("Create change set requested: {}", createChangeSetResult.getId()); }