Example usage for com.amazonaws.services.cloudformation.model Parameter Parameter

List of usage examples for com.amazonaws.services.cloudformation.model Parameter Parameter

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudformation.model Parameter Parameter.

Prototype

Parameter

Source Link

Usage

From source file:com.carrotgarden.maven.aws.cfn.CarrotCloudForm.java

License:BSD License

private List<Parameter> convert(final Map<String, String> paraMap) {

    final List<Parameter> list = Lists.newArrayList();

    if (paraMap == null || paraMap.values().size() == 0) {
        return list;
    }// w ww.  j  a v a2s. c  o  m

    for (final String name : paraMap.keySet()) {

        final Parameter parameter = new Parameter();
        parameter.setParameterKey(name);
        parameter.setParameterValue(paraMap.get(name));

        list.add(parameter);

    }

    return list;

}

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");
    }/*from w ww  .j av  a 2  s  .c  o 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:com.deploymentio.cfnstacker.template.TemplateParameters.java

License:Apache License

public List<Parameter> getApplicableParameters(JsonNode templateBodyJson) throws Exception {

    JsonNode parametersNode = templateBodyJson.get("Parameters");

    List<Parameter> params = new ArrayList<>();
    for (String key : config.getParameters().keySet()) {
        if (parametersNode != null && parametersNode.has(key)) {
            params.add(new Parameter().withParameterKey(key)
                    .withParameterValue(config.getParameters().get(key).textValue()));
        }/*from ww w .j av  a  2  s  .co m*/
    }
    return params;
}

From source file:com.github.kaklakariada.aws.sam.AwsSamDeployPlugin.java

License:Open Source License

private ReplacePlaceholerTask createUpdateSwaggerTask(File swaggerDefinition) {
    final ReplacePlaceholerTask task = createTask("updateSwagger", ReplacePlaceholerTask.class);
    final AwsMetadataService awsMetadataService = new AwsMetadataService(config);
    task.parameters = asList(//from   ww  w. j a va 2 s.  c  o  m
            new Parameter().withParameterKey("region").withParameterValue(config.getActiveRegion().getName()),
            new Parameter().withParameterKey("accountId")
                    .withParameterValue(awsMetadataService.getAccountId()));
    task.input = swaggerDefinition;
    task.output = new File(project.getBuildDir(), task.input.getName());
    return task;
}

From source file:com.github.kaklakariada.aws.sam.service.DeployService.java

License:Open Source License

private String updateTemplateBody(String templateBody, String codeUri, String swaggerDefinitionUri) {
    final Collection<Parameter> parameters = new ArrayList<>();
    parameters.add(/*  ww  w.j  av a 2s  . com*/
            new Parameter().withParameterKey("CodeUri").withParameterValue(Objects.requireNonNull(codeUri)));
    parameters.add(new Parameter().withParameterKey("stage").withParameterValue(config.getStageName()));
    if (swaggerDefinitionUri != null) {
        parameters.add(
                new Parameter().withParameterKey("DefinitionUri").withParameterValue(swaggerDefinitionUri));
    }
    final String newTemplateBody = templateService.replaceParameters(templateBody, parameters);
    templateService.writeFile(newTemplateBody, config.getBuildDir().resolve("updated-template.yaml"));
    return newTemplateBody;
}

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 w  w . jav a2s  . c  o  m
            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:com.mweagle.tereus.commands.CreateCommand.java

License:Open Source License

protected List<Parameter> toParameterList(final Map<String, Object> values) {
    return values.entrySet().stream().map(eachEntry -> {
        Parameter awsParam = new Parameter();
        awsParam.setParameterKey(eachEntry.getKey());
        awsParam.setParameterValue(eachEntry.getValue().toString());
        return awsParam;
    }).collect(Collectors.toList());
}

From source file:com.netflix.spinnaker.clouddriver.aws.deploy.ops.DeployCloudFormationAtomicOperation.java

License:Apache License

@Override
public Map operate(List priorOutputs) {
    Task task = TaskRepository.threadLocalTask.get();
    task.updateStatus(BASE_PHASE, "Configuring CloudFormation Stack");
    AmazonCloudFormation amazonCloudFormation = amazonClientProvider
            .getAmazonCloudFormation(description.getCredentials(), description.getRegion());
    String template;//from  ww  w .  j av  a2  s  . c  o m
    try {
        template = objectMapper.writeValueAsString(description.getTemplateBody());
    } catch (JsonProcessingException e) {
        throw new IllegalArgumentException("Could not serialize CloudFormation Stack template body", e);
    }
    List<Parameter> parameters = description.getParameters().entrySet().stream()
            .map(entry -> new Parameter().withParameterKey(entry.getKey()).withParameterValue(entry.getValue()))
            .collect(Collectors.toList());
    try {
        String stackId = createStack(amazonCloudFormation, template, parameters);
        return Collections.singletonMap("stackId", stackId);
    } catch (AlreadyExistsException e) {
        String stackId = updateStack(amazonCloudFormation, template, parameters);
        return Collections.singletonMap("stackId", stackId);
    }
}

From source file:com.nike.cerberus.service.CloudFormationService.java

License:Apache License

/**
 * Converts a Map into a list of {@link com.amazonaws.services.cloudformation.model.Parameter} objects.
 *
 * @param parameterMap Map to be converted.
 * @return Collection of parameters./*from ww w . j av  a 2 s . co  m*/
 */
public Collection<Parameter> convertParameters(final Map<String, String> parameterMap) {
    final List<Parameter> parameterList = Lists.newArrayListWithCapacity(parameterMap.size());

    for (Map.Entry<String, String> entry : parameterMap.entrySet()) {
        final Parameter param = new Parameter().withParameterKey(entry.getKey())
                .withParameterValue(entry.getValue());
        parameterList.add(param);
    }

    return parameterList;
}

From source file:de.taimos.pipeline.aws.cloudformation.parser.JSONParameterFileParser.java

License:Apache License

@Override
public Collection<Parameter> parseParams(InputStream fileContent) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode tree = mapper.readTree(fileContent);
    Collection<Parameter> parameters = new ArrayList<>();
    if (tree instanceof ArrayNode) {
        ArrayNode jsonNodes = (ArrayNode) tree;
        for (JsonNode node : jsonNodes) {
            Parameter param = new Parameter();
            param.withParameterKey(node.get("ParameterKey").asText());
            if (node.has("ParameterValue")) {
                param.withParameterValue(node.get("ParameterValue").asText());
            }//  w w  w. j a  v a2 s. c  om
            if (node.has("UsePreviousValue")) {
                param.withUsePreviousValue(node.get("UsePreviousValue").booleanValue());
            }
            parameters.add(param);
        }
    }
    return parameters;
}