List of usage examples for com.amazonaws.services.cloudformation.model CreateStackRequest setCapabilities
public void setCapabilities(java.util.Collection<String> capabilities)
In some cases, you must explicitly acknowledge that your stack template contains certain capabilities in order for AWS CloudFormation to create the stack.
From source file:com.kinesisboard.amazonaws.utils.CloudFormationUtils.java
License:Open Source License
public static void createStackIfNotExists(AmazonCloudFormation client, KinesisConnectorConfiguration config) { String stackName = config.ELASTICSEARCH_CLOUDFORMATION_STACK_NAME; if (stackExists(client, stackName)) { StackStatus status = stackStatus(client, stackName); switch (status) { case CREATE_COMPLETE: case UPDATE_COMPLETE: LOG.info("Stack " + stackName + " already exists."); return; case CREATE_IN_PROGRESS: case UPDATE_IN_PROGRESS: case UPDATE_COMPLETE_CLEANUP_IN_PROGRESS: LOG.info("Stack " + stackName + " exists with status: " + status + ". Waiting for completion."); break; default:/*from w ww . j ava 2 s . c om*/ throw new IllegalStateException( "Stack " + stackName + " exists but has an invalid status: " + status); } } else { CreateStackRequest createStackRequest = new CreateStackRequest(); createStackRequest.setStackName(stackName); String templateBody = null; try { templateBody = loadTemplate(config.ELASTICSEARCH_CLOUDFORMATION_TEMPLATE_URL); } catch (IOException ioe) { LOG.error("Error reading template", ioe); throw new RuntimeException( "Could not load template at location: " + config.ELASTICSEARCH_CLOUDFORMATION_TEMPLATE_URL); } createStackRequest.setTemplateBody(templateBody); List<Parameter> parameters = new ArrayList<Parameter>(); parameters.add(new Parameter().withParameterKey("KeyName") .withParameterValue(config.ELASTICSEARCH_CLOUDFORMATION_KEY_PAIR_NAME)); parameters.add(new Parameter().withParameterKey("InstanceType") .withParameterValue(config.ELASTICSEARCH_CLOUDFORMATION_CLUSTER_INSTANCE_TYPE)); parameters.add(new Parameter().withParameterKey("SSHLocation") .withParameterValue(config.ELASTICSEARCH_CLOUDFORMATION_SSH_LOCATION)); parameters.add(new Parameter().withParameterKey("ClusterSize") .withParameterValue(config.ELASTICSEARCH_CLOUDFORMATION_CLUSTER_SIZE)); parameters.add(new Parameter().withParameterKey("ElasticsearchVersion") .withParameterValue(config.ELASTICSEARCH_VERSION_NUMBER)); createStackRequest.setParameters(parameters); List<String> capabilities = new ArrayList<String>(); capabilities.add("CAPABILITY_IAM"); createStackRequest.setCapabilities(capabilities); client.createStack(createStackRequest); LOG.info("Stack " + stackName + " is creating"); } // now wait for good status while (true) { try { Thread.sleep(1000 * 10); } catch (Exception e) { } StackStatus status = stackStatus(client, stackName); switch (status) { case CREATE_COMPLETE: case UPDATE_COMPLETE: return; case CREATE_IN_PROGRESS: case UPDATE_IN_PROGRESS: case UPDATE_COMPLETE_CLEANUP_IN_PROGRESS: break; default: throw new IllegalStateException("Stack " + stackName + " failed to create with status: " + status); } } }
From source file:jp.classmethod.aws.gradle.cloudformation.AmazonCloudFormationMigrateStackTask.java
License:Apache License
private void createStack(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(); String cfnOnFailure = getCfnOnFailure(); getLogger().info("create stack: {}", stackName); CreateStackRequest req = new CreateStackRequest().withStackName(stackName).withParameters(cfnStackParams) .withTags(cfnStackTags).withOnFailure(cfnOnFailure); // If template URL is specified, then use it if (Strings.isNullOrEmpty(cfnTemplateUrl) == false) { req.setTemplateURL(cfnTemplateUrl); // Else, use the template file body } else {/*from w w w. ja v a 2s .c o 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())); } // If stack policy is specified, then use it if (Strings.isNullOrEmpty(cfnStackPolicyUrl) == false) { req.setStackPolicyURL(cfnStackPolicyUrl); // Else, use the stack policy file body } else if (cfnStackPolicyFile != null) { req.setStackPolicyBody(FileUtils.readFileToString(cfnStackPolicyFile)); } CreateStackResult createStackResult = cfn.createStack(req); getLogger().info("create requested: {}", createStackResult.getStackId()); }
From source file:org.xmlsh.aws.cfnCreateStack.java
License:BSD License
private int createStack(Options opts) throws IOException, XMLStreamException, SaxonApiException, CoreException { OutputPort stdout = getStdout();//from w w w.jav a 2s . co m mWriter = new SafeXMLStreamWriter(stdout.asXMLStreamWriter(getSerializeOpts())); startDocument(); startElement(getName()); CreateStackRequest request = new CreateStackRequest(); // "capability:+,disable-rollback,notification-arn:+,name:,template:,timeout:,tag:+"); if (opts.hasOpt("capability")) request.setCapabilities(Util.toStringList(opts.getOptValues("capability"))); String onFail = opts.getOptString("on-failure", null); if (onFail != null) request.setOnFailure(OnFailure.fromValue(onFail)); else request.setDisableRollback(opts.getOptFlag("disable-rollback", false)); if (opts.hasOpt("notification-arn")) request.setNotificationARNs(Util.toStringList(opts.getOptValues("notification-arn"))); 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")); if (opts.hasOpt("timeout")) request.setTimeoutInMinutes((int) opts.getOptLong("timeout", 10)); if (opts.hasOpt("tag")) request.setTags(getTags(opts.getOptValues("tag"))); request.setParameters(getParameters(opts)); traceCall("createStack"); CreateStackResult result = getAWSClient().createStack(request); writeStackResult(result, request.getStackName()); endElement(); endDocument(); closeWriter(); stdout.writeSequenceTerminator(getSerializeOpts()); return 0; }
From source file:org.xmlsh.aws.gradle.cloudformation.AmazonCloudFormationCreateStackTask.java
License:BSD License
private void createStack(AmazonCloudFormation cfn) { // to enable conventionMappings feature String stackName = getStackName(); List<Parameter> cfnStackParams = getCfnStackParams(); getLogger().info("create stack: {}", stackName); CreateStackRequest req = new CreateStackRequest().withStackName(stackName).withParameters(cfnStackParams) .withTemplateBody(getTemplateBody()).withDisableRollback(isDisableRollback()) .withOnFailure(getOnFailure()).withTags(getTags()); if (isCapabilityIam()) { req.setCapabilities(Arrays.asList(Capability.CAPABILITY_IAM.toString())); }/*w w w .jav a2 s . c o m*/ CreateStackResult createStackResult = cfn.createStack(req); getLogger().info("create requested: {}", createStackResult.getStackId()); }
From source file:org.xmlsh.aws.gradle.cloudformation.AmazonCloudFormationMigrateStackTask.java
License:BSD License
private void createStack(AmazonCloudFormation cfn) { // to enable conventionMappings feature String stackName = getStackName(); List<Parameter> cfnStackParams = getCfnStackParams(); getLogger().info("create stack: {}", stackName); CreateStackRequest req = new CreateStackRequest().withStackName(stackName).withParameters(cfnStackParams) .withTemplateBody(getTemplateBody()); if (isCapabilityIam()) { req.setCapabilities(Arrays.asList(Capability.CAPABILITY_IAM.toString())); }/* w w w . j av a 2 s .c o m*/ CreateStackResult createStackResult = cfn.createStack(req); getLogger().info("create requested: {}", createStackResult.getStackId()); }
From source file:org.xmlsh.aws.gradle.cloudformation.AmazonCloudFormationUpdateStackTask.java
License:BSD License
private void createStack(AmazonCloudFormation cfn) { // to enable conventionMappings feature String stackName = getStackName(); String cfnTemplateUrl = getCfnTemplateUrl(); List<Parameter> cfnStackParams = getCfnStackParams(); getLogger().info("create stack: {}", stackName); CreateStackRequest req = new CreateStackRequest().withStackName(stackName).withTemplateURL(cfnTemplateUrl) .withParameters(cfnStackParams); if (isCapabilityIam()) { req.setCapabilities(Arrays.asList(Capability.CAPABILITY_IAM.toString())); }/*from ww w . j av a2s .c o m*/ CreateStackResult createStackResult = cfn.createStack(req); getLogger().info("create requested: {}", createStackResult.getStackId()); }