List of usage examples for com.amazonaws.services.cloudformation.model UpdateStackResult getStackId
public String getStackId()
Unique identifier of the stack.
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; }/*from www . j a v a2 s. c om*/ 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> updateStack(final UpdateStackRequest request, final Region awsRegion, Logger logger) {// www . j av a2 s. c o m DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain(); final AmazonCloudFormationAsyncClient awsClient = new AmazonCloudFormationAsyncClient( credentialProviderChain.getCredentials()); awsClient.setRegion(awsRegion); logger.info("Updating stack: {}", request.getStackName()); Optional<DescribeStacksResult> completionResult = Optional.empty(); try { final List<StackEvent> priorEvents = getStackEvents(awsClient, request.getStackName(), logger); logger.info("Total number of pre-existing stack events: {}", priorEvents.size()); Future<UpdateStackResult> updateStackResult = awsClient.updateStackAsync(request); final UpdateStackResult stackResult = updateStackResult.get(); logger.info("Stack ({}) creation in progress.", stackResult.getStackId()); completionResult = waitForStackComplete(awsClient, request.getStackName(), priorEvents, 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 updateStack(AmazonCloudFormation amazonCloudFormation, String template, List<Parameter> parameters) { Task task = TaskRepository.threadLocalTask.get(); task.updateStatus(BASE_PHASE, "CloudFormation Stack exists. Updating it"); UpdateStackRequest updateStackRequest = new UpdateStackRequest().withStackName(description.getStackName()) .withParameters(parameters).withTemplateBody(template); task.updateStatus(BASE_PHASE, "Uploading CloudFormation Stack"); try {/* w ww. j a v a 2 s. co m*/ UpdateStackResult updateStackResult = amazonCloudFormation.updateStack(updateStackRequest); return updateStackResult.getStackId(); } catch (AmazonCloudFormationException e) { // No changes on the stack, ignore failure return amazonCloudFormation .describeStacks(new DescribeStacksRequest().withStackName(description.getStackName())) .getStacks().stream().findFirst() .orElseThrow(() -> new IllegalArgumentException( "No CloudFormation Stack found with stack name " + description.getStackName())) .getStackId(); } }
From source file:jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationMigrateStackTask.java
License:Apache License
private void updateStack(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(); getLogger().info("Update stack: {}", stackName); UpdateStackRequest req = new UpdateStackRequest().withStackName(stackName).withParameters(cfnStackParams) .withTags(cfnStackTags);/*from w w w . ja v a 2s . c o m*/ // If template URL is specified, then use it if (Strings.isNullOrEmpty(cfnTemplateUrl) == false) { req.setTemplateURL(cfnTemplateUrl); getLogger().info("Using template url: {}", cfnTemplateUrl); // Else, use the template file body } else { req.setTemplateBody(FileUtils.readFileToString(cfnTemplateFile)); getLogger().info("Using template file: {}", "$cfnTemplateFile.canonicalPath"); } 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 if present } else if (cfnStackPolicyFile != null) { req.setStackPolicyBody(FileUtils.readFileToString(cfnStackPolicyFile)); } UpdateStackResult updateStackResult = cfn.updateStack(req); getLogger().info("Update requested: {}", updateStackResult.getStackId()); }
From source file:org.xmlsh.aws.cfnUpdateStack.java
License:BSD License
private void writeStackResult(UpdateStackResult result) throws XMLStreamException { startElement("stack"); attribute("stack-id", result.getStackId()); endElement();/*from w w w . j av a 2 s.c om*/ }
From source file:org.xmlsh.aws.gradle.cloudformation.AmazonCloudFormationMigrateStackTask.java
License:BSD License
private void updateStack(AmazonCloudFormation cfn) { // to enable conventionMappings feature String stackName = getStackName(); List<Parameter> cfnStackParams = getCfnStackParams(); getLogger().info("update stack: {}", stackName); UpdateStackRequest req = new UpdateStackRequest().withStackName(stackName).withParameters(cfnStackParams) .withUsePreviousTemplate(isUsePreviousTemplate()); if (getTemplateBody() != null) req.setTemplateBody(getTemplateBody()); if (isCapabilityIam()) { req.setCapabilities(Arrays.asList(Capability.CAPABILITY_IAM.toString())); }//from w w w .j a v a 2 s . com UpdateStackResult updateStackResult = cfn.updateStack(req); getLogger().info("update requested: {}", updateStackResult.getStackId()); }
From source file:org.xmlsh.aws.gradle.cloudformation.AmazonCloudFormationUpdateStackTask.java
License:BSD License
private void updateStack(AmazonCloudFormation cfn) { // to enable conventionMappings feature String stackName = getStackName(); List<Parameter> cfnStackParams = getCfnStackParams(); getLogger().info("update stack: {}", stackName); UpdateStackRequest req = new UpdateStackRequest().withStackName(stackName).withParameters(cfnStackParams) .withUsePreviousTemplate(isUsePreviousTemplate()); if (getTemplateBody() != null) req.setTemplateBody(getTemplateBody()); if (isCapabilityIam()) { req.setCapabilities(Arrays.asList(Capability.CAPABILITY_IAM.toString())); }/* w ww .ja va 2 s . c o m*/ UpdateStackResult updateStackResult = cfn.updateStack(req); getLogger().info("update requested: {}", updateStackResult.getStackId()); }