List of usage examples for com.amazonaws.services.cloudformation.model UpdateStackRequest setStackName
public void setStackName(String stackName)
The name or unique stack ID of the stack to update.
From source file:com.cleanenergyexperts.aws.cf.CloudFormationMojo.java
License:Apache License
public void execute() throws MojoExecutionException { getLog().info("Bucket Name: " + bucketName); //getLog().info("Cloud Formation Stack Name: " + stackName); if (artifactFile == null || !artifactFile.isFile()) { throw new MojoExecutionException("Cannot find artifact file to upload"); }// w w w. j a v a 2 s . co m String artifactKey = artifactFile.getName(); getLog().info("Artifact Name: " + artifactKey); BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); AmazonCloudFormationClient cfClient = new AmazonCloudFormationClient(awsCredentials); cfClient.setEndpoint(getCloudFormationEndPoint()); AmazonS3Client s3Client = new AmazonS3Client(awsCredentials); // Upload Artifact to S3 try { getLog().info("Uploading artifact to S3..."); s3Client.putObject(bucketName, artifactKey, artifactFile); } catch (AmazonServiceException e) { throw new MojoExecutionException("[SERVICE] Could Not Upload File to S3", e); } catch (AmazonClientException e) { throw new MojoExecutionException("[CLIENT] Could Not Upload File to S3", e); } // Update each stack with the new artifact file for (String stackName : stackNames) { getLog().info("Cloud Formation Stack Name: " + stackName); String templateBody = getTemplateBody(cfClient, stackName); Stack stack = getStack(cfClient, stackName); // If passed additional parameters, update them List<Parameter> parameters = stack.getParameters(); if (stackParameters != null && !stackParameters.isEmpty()) { List<Parameter> tmpParams = new ArrayList<Parameter>(); // Add Existing Parameters we haven't locally overwritten for (Parameter oldParam : parameters) { String oldKey = oldParam.getParameterKey(); if (!stackParameters.containsKey(oldKey)) { tmpParams.add(oldParam); } } // Add Overwrite parameters for (String key : stackParameters.keySet()) { Parameter newParam = new Parameter(); newParam.setParameterKey(key); newParam.setParameterValue(stackParameters.get(key)); tmpParams.add(newParam); } parameters = tmpParams; } // Update the Stack UpdateStackRequest updateStackRequest = new UpdateStackRequest(); updateStackRequest.setStackName(stackName); updateStackRequest.setTemplateBody(templateBody); updateStackRequest.setParameters(parameters); updateStackRequest.setCapabilities(stack.getCapabilities()); try { getLog().info("Updating Cloud Formation Stack..."); cfClient.updateStack(updateStackRequest); } catch (AmazonServiceException e) { throw new MojoExecutionException("[SERVICE] Could Not Update Cloud Formation Stack", e); } catch (AmazonClientException e) { throw new MojoExecutionException("[CLIENT] Could Not Update Cloud Formation Stack", e); } getLog().info("Cloud Formation Stack " + stackName + "is now updating..."); } getLog().info("All stacks have been updated. Complete."); }
From source file:jetbrains.buildServer.runner.cloudformation.AWSClient.java
License:Apache License
/** * Uploads application revision archive to S3 bucket named s3BucketName with * the provided key and bundle type./*from www. java2 s. c o m*/ * <p> * For performing this operation target AWSClient must have corresponding S3 * permissions. * * @param s3BucketName * valid S3 bucket name * @param s3ObjectKey * valid S3 object key */ public void initiateCFN(@NotNull String stackName, @NotNull String region, @NotNull String s3BucketName, @NotNull String s3ObjectKey, @NotNull String cfnAction, @NotNull String onFailure) { try { String templateURL; Region reg = Region.getRegion(Regions.fromName(region)); myCloudFormationClient.setRegion(reg); templateURL = getTemplateUrl(reg, s3BucketName, s3ObjectKey); System.out.println("The template url is " + templateURL); if (cfnAction.equalsIgnoreCase("Create")) { System.out.println("The CFN action is " + cfnAction); myListener.createStackStarted(stackName, region, s3BucketName, s3ObjectKey, cfnAction); CreateStackRequest createRequest = new CreateStackRequest(); createRequest.setStackName(stackName); if (!onFailure.equalsIgnoreCase("null")) createRequest.setOnFailure(onFailure); createRequest.setTemplateURL(templateURL); myCloudFormationClient.createStack(createRequest); waitForCompletion(myCloudFormationClient, stackName); } else if (cfnAction.equalsIgnoreCase("Delete")) { myListener.deleteStarted(stackName, region); DeleteStackRequest deleteStackRequest = new DeleteStackRequest(); deleteStackRequest.setStackName(stackName); myCloudFormationClient.deleteStack(deleteStackRequest); waitForDelete(myCloudFormationClient, stackName); } else if (cfnAction.equalsIgnoreCase("Validate")) { myListener.validateStarted(stackName); ValidateTemplateRequest validatetempRequest = new ValidateTemplateRequest(); validatetempRequest.setTemplateURL(templateURL); myListener.validateFinished( myCloudFormationClient.validateTemplate(validatetempRequest).getParameters().toString()); } else if (cfnAction.equalsIgnoreCase("Update")) { myListener.updateInProgress(stackName); UpdateStackRequest updateStackRequest = new UpdateStackRequest(); updateStackRequest.setStackName(stackName); updateStackRequest.setTemplateURL(templateURL); myCloudFormationClient.updateStack(updateStackRequest); waitForCompletion(myCloudFormationClient, stackName); } } catch (Throwable t) { processFailure(t); } }
From source file:org.xmlsh.aws.cfnUpdateStack.java
License:BSD License
private int updateStack(List<XValue> args, Options opts) throws IOException, XMLStreamException, SaxonApiException, CoreException { OutputPort stdout = getStdout();/*from ww w . j a v a2 s . co m*/ mWriter = new SafeXMLStreamWriter(stdout.asXMLStreamWriter(getSerializeOpts())); startDocument(); startElement(getName()); UpdateStackRequest request = new UpdateStackRequest(); // "capability:+,disable-rollback,notification-arn:+,name:,template:,timeout:,tag:+"); if (opts.hasOpt("capability")) request.setCapabilities(Util.toStringList(opts.getOptValues("capability"))); request.setStackName(opts.getOptStringRequired("name")); if (opts.hasOpt("template-file")) request.setTemplateBody(Util.readString(mShell.getFile(opts.getOptValue("template-file")), getSerializeOpts().getInput_text_encoding())); else request.setTemplateURL(opts.getOptStringRequired("template-url")); request.setParameters(getParameters(args)); traceCall("updateStack"); UpdateStackResult result = getAWSClient().updateStack(request); writeStackResult(result); endElement(); endDocument(); closeWriter(); stdout.writeSequenceTerminator(getSerializeOpts()); return 0; }