List of usage examples for com.amazonaws.services.cloudformation AmazonCloudFormationAsyncClient describeStacks
DescribeStacksResult describeStacks(DescribeStacksRequest describeStacksRequest);
Returns the description for the specified stack; if no stack name was specified, then it returns the description for all the stacks created.
From source file:com.mweagle.tereus.aws.CloudFormation.java
License:Open Source License
protected Optional<DescribeStacksResult> describeStack(final AmazonCloudFormationAsyncClient awsClient, final String stackName, Logger logger) throws Exception { final DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest(); describeStacksRequest.setStackName(stackName); return Optional.of(awsClient.describeStacks(describeStacksRequest)); }
From source file:com.mweagle.tereus.commands.pipelines.UpdatePipeline.java
License:Open Source License
protected void publishGlobals(ScriptEngine engine) { super.publishGlobals(engine); // Publish a function that accepts a stack target name, defined by the patch // file, that represents the target. We'll push all this Function<String, String> fnStackInfo = (stackName) -> { // Get the information... final GetTemplateRequest templateRequest = new GetTemplateRequest().withStackName(stackName); final AmazonCloudFormationAsyncClient awsClient = new AmazonCloudFormationAsyncClient( super.getAwsCredentials()); awsClient.setRegion(super.getRegion()); final GetTemplateResult stackTemplateResult = awsClient.getTemplate(templateRequest); // Get the stack info and return it final DescribeStacksRequest describeRequest = new DescribeStacksRequest().withStackName(stackName); final DescribeStacksResult describeResult = awsClient.describeStacks(describeRequest); // And finally the tags and parameters final Stack stackInfo = !describeResult.getStacks().isEmpty() ? describeResult.getStacks().get(0) : null;/*from w w w . j a va 2 s . com*/ final Map<String, Object> tags = (stackInfo != null) ? stackInfo.getTags().stream().collect(Collectors.toMap(Tag::getKey, Tag::getValue)) : Collections.emptyMap(); final Map<String, Object> params = (stackInfo != null) ? stackInfo.getParameters().stream() .collect(Collectors.toMap(Parameter::getParameterKey, Parameter::getParameterValue)) : Collections.emptyMap(); HashMap<String, Object> results = new HashMap<>(); results.put("tags", tags); results.put("params", params); results.put("stack", stackInfo); results.put("template", stackTemplateResult.getTemplateBody().toString()); Gson gson = new Gson(); return gson.toJson(results); }; engine.put("TargetStackInfoImpl", fnStackInfo); Supplier<String> fnArgs = () -> { HashMap<String, Map<String, Object>> args = new HashMap<>(); args.put("arguments", this.arguments); Gson gson = new Gson(); return gson.toJson(args); }; engine.put("ArgumentsImpl", fnArgs); }
From source file:com.mweagle.tereus.commands.UpdateCommand.java
License:Open Source License
protected void updateStack(UpdateInput updateInput, String transformedTemplate, String stackTargetName) throws UnsupportedEncodingException { if (updateInput.dryRun) { updateInput.logger.info("Dry run requested (-n/--noop). Stack update bypassed."); } else {//from ww w. j a v a 2 s . c om // Fetch the stack parameters final DescribeStacksRequest stackRequest = new DescribeStacksRequest().withStackName(stackTargetName); final AmazonCloudFormationAsyncClient awsClient = new AmazonCloudFormationAsyncClient( updateInput.awsCredentials); awsClient.setRegion(updateInput.awsRegion); final DescribeStacksResult result = awsClient.describeStacks(stackRequest); final Stack existantStack = result.getStacks().get(0); final Optional<Parameter> s3Bucket = findNamedParameter(CONSTANTS.PARAMETER_NAMES.S3_BUCKET_NAME, existantStack.getParameters()); Preconditions.checkArgument(s3Bucket.isPresent(), "Failed to determine S3 BucketName from existant template via parameter name: " + CONSTANTS.PARAMETER_NAMES.S3_BUCKET_NAME); // Super, now put the new content to S3, update the parameter list // to include the new URL, and submit the updated stack. final byte[] templateBytes = transformedTemplate.getBytes("UTF-8"); final InputStream is = new ByteArrayInputStream(templateBytes); final String templateDigest = DigestUtils.sha256Hex(templateBytes); final String keyName = String.format("%s-tereus.cf.template", templateDigest); try (S3Resource resource = new S3Resource(s3Bucket.get().getParameterValue(), keyName, is, Optional.of(Long.valueOf(templateBytes.length)))) { // Upload the template resource.upload(); // Go ahead and create the stack. final UpdateStackRequest request = new UpdateStackRequest().withStackName(stackTargetName); request.setTemplateURL(resource.getResourceURL().get()); request.setParameters(existantStack.getParameters()); request.setCapabilities(Arrays.asList("CAPABILITY_IAM")); updateInput.logger.debug("Updating stack: {}", stackTargetName); final Optional<DescribeStacksResult> updateResult = new CloudFormation().updateStack(request, updateInput.awsRegion, updateInput.logger); // If everything worked out, then release the template // URL s.t. subsequent ASG instantiated instances have access // to the template content if (updateResult.isPresent()) { updateInput.logger.info("Stack successfully updated"); updateInput.logger.info(updateResult.get().toString()); resource.setReleased(true); } } } }