/** * Creates a new stack. * * @param name Stack name. * @param parameters Input parameters. * @param templatePath Classpath to the JSON template of the stack. * @return Stack ID */ public String createStack(final String name, final Map<String, String> parameters, final String templatePath, final boolean iamCapabilities) { logger.info(String.format("Executing the Cloud Formation: %s, Stack Name: %s", templatePath, name)); final CreateStackRequest request = new CreateStackRequest() .withStackName(name) .withParameters(convertParameters(parameters)) .withTemplateBody(getTemplateText(templatePath)); if (iamCapabilities) { request.getCapabilities().add("CAPABILITY_IAM"); } final CreateStackResult result = cloudFormationClient.createStack(request); return result.getStackId(); }
public static StackNameAndId createTemporarySimpleStack(AmazonCloudFormation cfnClient, String vpcId, String arn) throws IOException { CreateStackRequest createStackRequest = new CreateStackRequest(); createStackRequest.setStackName(TEMPORARY_STACK); File file = new File(FilesForTesting.SIMPLE_STACK); createStackRequest.setTemplateBody(FileUtils.readFileToString(file , Charset.defaultCharset())); Collection<Parameter> parameters = new LinkedList<>(); parameters.add(createParam("env", EnvironmentSetupForTests.ENV)); parameters.add(createParam("vpc", vpcId)); if (!arn.isEmpty()) { Collection<String> notificationARNs = new LinkedList<>(); notificationARNs.add(arn); logger.debug("Adding arn subscription "+ arn); createStackRequest.setNotificationARNs(notificationARNs); } createStackRequest.setParameters(parameters); CreateStackResult result = cfnClient.createStack(createStackRequest); return new StackNameAndId(TEMPORARY_STACK, result.getStackId()); }