/** * Makes a call to the operation specified by the waiter by taking the corresponding request and returns the * corresponding result * * @param describeStacksRequest * Corresponding request for the operation * @return Corresponding result of the operation */ @Override public DescribeStacksResult apply(DescribeStacksRequest describeStacksRequest) { return client.describeStacks(describeStacksRequest); } }
/** * Makes a call to the operation specified by the waiter by taking the corresponding request and returns the * corresponding result * * @param describeChangeSetRequest * Corresponding request for the operation * @return Corresponding result of the operation */ @Override public DescribeChangeSetResult apply(DescribeChangeSetRequest describeChangeSetRequest) { return client.describeChangeSet(describeChangeSetRequest); } }
List<Stack> stacks = cloudformation.describeStacks().getStacks(); cloudformation.describeStackEvents(request).getStackEvents() .stream() .filter(e -> e.getResourceStatus().equals("CREATE_FAILED"))
try { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest().withStackName(getExpandedStackName()); stack = getStack(amazonClient.describeStacks(describeStacksRequest)); } catch (AmazonServiceException e) { logger.println("Stack not found: " + getExpandedStackName() + ". Reason: " + detailedError(e)); logger.println("Creating Cloud Formation stack: " + getExpandedStackName()); CreateStackRequest request = createStackRequest(); amazonClient.createStack(request); amazonClient.updateStack(updateRequest);
@TaskAction public void deleteStack() { DeleteStackRequest deleteStackRequest = new DeleteStackRequest(); deleteStackRequest.withStackName(stackName); client.deleteStack(deleteStackRequest); } }
cfn.describeStacks(new DescribeStacksRequest().withStackName(stackName)); Stack stack = describeStackResult.getStacks().get(0); .withStackName(stackName) .withChangeSetName(changeSetName); cfn.executeChangeSet(req); getLogger().info("ChangeSet is executed : {}, {}", stackName, changeSetName); } else {
for (Stack stack : stackBuilder.describeStacks(describeStacksRequest).getStacks()) { results.put(Outputs.RETURN_RESULT, stack.getStackName() + "[" + stack.getStackStatus() + "]" ); results.put(Outputs.STACK_NAME_RESULT, stack.getStackName()); results.put(Outputs.STACK_RESOURCES_RESULT,stackBuilder.describeStackResources(stackResourceRequest).getStackResources().toString());
ValidateTemplateRequest validateTemplateRequest = new ValidateTemplateRequest(); validateTemplateRequest.withTemplateBody(file); ValidateTemplateResult validationResult = cloudFormation.validateTemplate(validateTemplateRequest); List<TemplateParameter> expectedParameters = validationResult.getParameters(); "' in region '", region, "'. Script : ", script.getFile())); final long start = System.currentTimeMillis(); CreateStackResult stack = cloudFormation.createStack(stackRequest); if (logger.isDebugEnabled()) { logger.info(StringUtil.concatStrings("Stack configuration created for name ", stackName)); .withStackName(stackName); DescribeStackEventsResult describeStackEventsResult = cloudFormation. describeStackEvents(describeStackEventsRequest);
public void delete(PollConfiguration pollConfiguration) throws ExecutionException { this.client.deleteStack(new DeleteStackRequest().withStackName(this.stack)); new EventPrinter(this.client, this.listener).waitAndPrintStackEvents(this.stack, this.client.waiters().stackDeleteComplete(), pollConfiguration); }
@TaskAction public void createStack() { CreateStackRequest stackRequest = new CreateStackRequest(); try { System.out.println("Stack Name: " + stackName); System.out.println("Stack File: " + filePath); stackRequest.withStackName(stackName); stackRequest.withTemplateBody(new String(Files.readAllBytes(Paths.get(filePath)))); stackRequest.withParameters(convertMapToParams()); client.createStack(stackRequest); System.out.println(String.format("Creating Stack %s", stackName)); waitForStackCreationToComplete(); } catch (Exception e) { System.out.println("Error creating stack: " + e.getMessage()); } }
public Map<String, String> create(String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags, PollConfiguration pollConfiguration, String roleArn, String onFailure, Boolean enableTerminationProtection) throws ExecutionException { if ((templateBody == null || templateBody.isEmpty()) && (templateUrl == null || templateUrl.isEmpty())) { throw new IllegalArgumentException("Either a file or url for the template must be specified"); } CreateStackRequest req = new CreateStackRequest(); req.withStackName(this.stack).withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM, Capability.CAPABILITY_AUTO_EXPAND).withEnableTerminationProtection(enableTerminationProtection); req.withTemplateBody(templateBody).withTemplateURL(templateUrl).withParameters(params).withTags(tags) .withTimeoutInMinutes(pollConfiguration.getTimeout() == null ? null : (int) pollConfiguration.getTimeout().toMinutes()) .withRoleARN(roleArn) .withOnFailure(OnFailure.valueOf(onFailure)); this.client.createStack(req); new EventPrinter(this.client, this.listener).waitAndPrintStackEvents(this.stack, this.client.waiters().stackCreateComplete(), pollConfiguration); Map<String, String> outputs = this.describeOutputs(); outputs.put(UPDATE_STATUS_OUTPUT, "true"); return outputs; }
while (run && !waitResult.isDone()) { try { DescribeStackEventsResult result = this.client.describeStackEvents(new DescribeStackEventsRequest().withStackName(stack)); List<StackEvent> stackEvents = new ArrayList<>(); for (StackEvent event : result.getStackEvents()) {
public Map<String, String> executeChangeSet(String changeSetName, PollConfiguration pollConfiguration) throws ExecutionException { if (!this.changeSetHasChanges(changeSetName) || !this.exists()) { // If the change set has no changes or the stack was not prepared we should simply delete it. this.listener.getLogger().format("Deleting empty change set %s for stack %s %n", changeSetName, this.stack); DeleteChangeSetRequest req = new DeleteChangeSetRequest().withChangeSetName(changeSetName).withStackName(this.stack); this.client.deleteChangeSet(req); Map<String, String> outputs = this.describeOutputs(); outputs.put(UPDATE_STATUS_OUTPUT, "false"); return outputs; } else { this.listener.getLogger().format("Executing change set %s for stack %s %n", changeSetName, this.stack); final Waiter<DescribeStacksRequest> waiter; if (this.isInReview()) { waiter = this.client.waiters().stackCreateComplete(); } else { waiter = this.client.waiters().stackUpdateComplete(); } ExecuteChangeSetRequest req = new ExecuteChangeSetRequest().withChangeSetName(changeSetName).withStackName(this.stack); this.client.executeChangeSet(req); new EventPrinter(this.client, this.listener).waitAndPrintStackEvents(this.stack, waiter, pollConfiguration); this.listener.getLogger().format("Executed change set %s for stack %s %n", changeSetName, this.stack); Map<String, String> outputs = this.describeOutputs(); outputs.put(UPDATE_STATUS_OUTPUT, "true"); return outputs; } }
public Map<String, String> update(String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags, PollConfiguration pollConfiguration, String roleArn, RollbackConfiguration rollbackConfig) throws ExecutionException { try { UpdateStackRequest req = new UpdateStackRequest(); req.withStackName(this.stack).withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM, Capability.CAPABILITY_AUTO_EXPAND); if (templateBody != null && !templateBody.isEmpty()) { req.setTemplateBody(templateBody); } else if (templateUrl != null && !templateUrl.isEmpty()) { req.setTemplateURL(templateUrl); } else { req.setUsePreviousTemplate(true); } req.withRollbackConfiguration(rollbackConfig); req.withParameters(params).withTags(tags).withRoleARN(roleArn); this.client.updateStack(req); new EventPrinter(this.client, this.listener).waitAndPrintStackEvents(this.stack, this.client.waiters().stackUpdateComplete(), pollConfiguration); this.listener.getLogger().format("Updated CloudFormation stack %s %n", this.stack); Map<String, String> outputs = this.describeOutputs(); outputs.put(UPDATE_STATUS_OUTPUT, "true"); return outputs; } catch (AmazonCloudFormationException e) { if (e.getMessage().contains("No updates are to be performed")) { this.listener.getLogger().format("No updates were needed for CloudFormation stack %s %n", this.stack); Map<String, String> outputs = this.describeOutputs(); outputs.put(UPDATE_STATUS_OUTPUT, "false"); return outputs; } this.listener.getLogger().format("Failed to update CloudFormation stack %s %n", this.stack); throw e; } }
this.client.createChangeSet(req); new EventPrinter(this.client, this.listener).waitAndPrintChangeSetEvents(this.stack, changeSetName, this.client.waiters().changeSetCreateComplete(), pollConfiguration);
public String createChangeSet(String changeSetName, String stackName, ChangeSetType changeSetType, String templateBody, Collection<Parameter> parameters) { logger.info("Creating change set for stack {} with name {}, type {} and parameters {}", stackName, changeSetName, changeSetType, parameters); final CreateChangeSetRequest changeSetRequest = new CreateChangeSetRequest() // .withCapabilities(Capability.CAPABILITY_IAM) // .withStackName(stackName) // .withDescription(stackName) // .withChangeSetName(changeSetName) // .withChangeSetType(changeSetType) // .withParameters(parameters).withTemplateBody(templateBody); final CreateChangeSetResult result = cloudFormation.createChangeSet(changeSetRequest); logger.info("Change set created: {}", result); return result.getId(); }
public void executeChangeSet(String changeSetArn) { cloudFormation.executeChangeSet(new ExecuteChangeSetRequest().withChangeSetName(changeSetArn)); logger.lifecycle("Executing change set {}", changeSetArn); }
UpdateStackResult updateStackResult = cfn.updateStack(req); getLogger().info("Update requested: {}", updateStackResult.getStackId());
DescribeStacksResult describeStacksResult = cloudFormation.describeStacks(describeStacksRequest); final List<Stack> stacks = describeStacksResult.getStacks(); if (stacks.size() > 1 || stacks.isEmpty()) { .withStackName(stackName); DescribeStackEventsResult describeStackEventsResult = cloudFormation. describeStackEvents(describeStackEventsRequest);
public void deleteStack(String stackName) { logger.info("Delete stack '{}'", stackName); cloudFormation.deleteStack(new DeleteStackRequest().withStackName(stackName)); } }