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

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

Introduction

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

Prototype


public void setParameterValue(String parameterValue) 

Source Link

Document

The input value associated with the parameter.

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;
    }//from   w w w  .  j  a va2  s  .  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 w w . j  a  v a  2 s  .  c om
    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.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:org.terracotta.TerracottaCloudFormationSample.java

License:Open Source License

@org.junit.BeforeClass
public static void createStack() throws Exception {

    /*//from   w  w  w.jav a  2s . c  om
    * Important: Be sure to fill in your AWS access credentials in the
    *            AwsCredentials.properties file before you try to run this
    *            sample.
    * http://aws.amazon.com/security-credentials
    */
    amazonCloudFormationClient = new AmazonCloudFormationClient(new PropertiesCredentials(
            TerracottaCloudFormationSample.class.getResourceAsStream("/AwsCredentials.properties")));

    System.out.println("================================");
    System.out.println("Terracotta CloudFormation Sample");
    System.out.println("================================\n");

    try {
        // Create a stack
        CreateStackRequest createRequest = new CreateStackRequest();
        createRequest.setStackName(stackName);
        createRequest.setTemplateBody(convertStreamToString(
                TerracottaCloudFormationSample.class.getResourceAsStream("/TerracottaServerArray.template")));

        Parameter parameter = new Parameter();
        parameter.setParameterKey("KeyName");
        parameter.setParameterValue(keyChainName);
        List parameters = new ArrayList();
        parameters.add(parameter);
        createRequest.setParameters(parameters);
        System.out.println("Creating a stack called " + createRequest.getStackName() + ".");
        amazonCloudFormationClient.createStack(createRequest);

        // Wait for stack to be created
        // Note that you could use SNS notifications on the CreateStack call to track the progress of the stack creation
        System.out.println("Stack creation completed, the stack " + stackName + " completed with "
                + waitForCompletion(amazonCloudFormationClient, stackName));

        // Show all the stacks for this account along with the resources for each stack
        for (Stack stack : amazonCloudFormationClient.describeStacks(new DescribeStacksRequest()).getStacks()) {
            System.out.println(
                    "Stack : " + stack.getStackName() + " [" + stack.getStackStatus().toString() + "]");

            DescribeStackResourcesRequest stackResourceRequest = new DescribeStackResourcesRequest();
            stackResourceRequest.setStackName(stack.getStackName());
            for (StackResource resource : amazonCloudFormationClient
                    .describeStackResources(stackResourceRequest).getStackResources()) {
                System.out.format("    %1$-40s %2$-25s %3$s\n", resource.getResourceType(),
                        resource.getLogicalResourceId(), resource.getPhysicalResourceId());
            }
        }

        // Lookup a resource by its logical name
        DescribeStackResourcesRequest logicalNameResourceRequest = new DescribeStackResourcesRequest();
        logicalNameResourceRequest.setStackName(stackName);
        logicalNameResourceRequest.setLogicalResourceId(logicalResourceName);
        System.out.format("Looking up resource name %1$s from stack %2$s\n",
                logicalNameResourceRequest.getLogicalResourceId(), logicalNameResourceRequest.getStackName());
        for (StackResource resource : amazonCloudFormationClient
                .describeStackResources(logicalNameResourceRequest).getStackResources()) {
            System.out.format("    %1$-40s %2$-25s %3$s\n", resource.getResourceType(),
                    resource.getLogicalResourceId(), resource.getPhysicalResourceId());
        }

        //deleteStack

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to AWS CloudFormation, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with AWS CloudFormation, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
}