Example usage for com.amazonaws.services.cloudformation AmazonCloudFormationClient AmazonCloudFormationClient

List of usage examples for com.amazonaws.services.cloudformation AmazonCloudFormationClient AmazonCloudFormationClient

Introduction

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

Prototype

@Deprecated
public AmazonCloudFormationClient() 

Source Link

Document

Constructs a new client to invoke service methods on AWS CloudFormation.

Usage

From source file:com.mweagle.tereus.commands.DeleteCommand.java

License:Open Source License

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings({ "DM_EXIT", "OBL_UNSATISFIED_OBLIGATION" })
@Override/*w ww . j av a  2s  .  c  om*/
public void run() {
    // Get the stack, delete the stack...
    int exitCode = 0;
    final Logger logger = LogManager.getLogger();

    try {
        final AmazonCloudFormationClient awsClient = new AmazonCloudFormationClient();
        awsClient.setRegion(RegionUtils.getRegion(this.region));
        final DescribeStacksRequest describeRequest = new DescribeStacksRequest().withStackName(this.stackName);
        final DescribeStacksResult describeResult = awsClient.describeStacks(describeRequest);
        logger.info(describeResult);
        logger.info("Deleting stack: {}", this.stackName);

        if (this.dryRun) {
            logger.info("Dry run requested (-n/--noop). Stack deletion bypassed.");
        } else {
            final DeleteStackRequest deleteRequest = new DeleteStackRequest().withStackName(this.stackName);
            awsClient.deleteStack(deleteRequest);
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        exitCode = 1;
    }
    System.exit(exitCode);
}

From source file:com.nike.cerberus.operation.gateway.CreateCloudFrontSecurityGroupUpdaterLambdaOperation.java

License:Apache License

@Inject
public CreateCloudFrontSecurityGroupUpdaterLambdaOperation(final CloudFormationService cloudFormationService,
        final EnvironmentMetadata environmentMetadata,
        @Named(CF_OBJECT_MAPPER) final ObjectMapper cloudformationObjectMapper, AWSLambda awsLambda,
        AmazonS3 amazonS3) {/*from   w  w  w . j  a v  a2  s.c om*/

    this.cloudFormationService = cloudFormationService;
    this.cloudformationObjectMapper = cloudformationObjectMapper;
    this.environmentMetadata = environmentMetadata;
    this.awsLambda = awsLambda;
    this.amazonS3 = amazonS3;

    final Region region = Region.getRegion(Regions.US_EAST_1);
    AmazonCloudFormation amazonCloudFormation = new AmazonCloudFormationClient();
    amazonCloudFormation.setRegion(region);
    amazonSNS = new AmazonSNSClient();
    amazonSNS.setRegion(region);
}

From source file:doug.iotdemo.common.AmazonUtils.java

License:Open Source License

public static String getStackOutput(String outputKey) {
    AmazonCloudFormation cf = new AmazonCloudFormationClient();
    DescribeStacksRequest request = new DescribeStacksRequest().withStackName(stackName);
    for (Stack stack : cf.describeStacks(request).getStacks()) {
        for (Output output : stack.getOutputs()) {
            if (outputKey.equals(output.getOutputKey())) {
                return output.getOutputValue();
            }/*from   w  ww  . j a v  a2s .  co m*/
        }
    }
    return null;
}

From source file:io.konig.schemagen.aws.AWSCloudFormationUtil.java

License:Apache License

public static void writeCloudFormationTemplate(File cfDir, String template, boolean validate)
        throws IOException, ParseException {

    for (File file : cfDir.listFiles()) {
        if (file.getName().endsWith("_template.yml")) {
            String contents = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())));

            VelocityContext context = new VelocityContext();
            context.put("functions", new VelocityFunctions(cfDir));
            StringWriter tempresult = new StringWriter();
            Template vmtemplate = new Template();
            RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
            StringReader reader = new StringReader(contents);
            vmtemplate.setRuntimeServices(runtimeServices);
            vmtemplate.setData(runtimeServices.parse(reader, template));
            vmtemplate.initDocument();/*  w  w  w .  j  av a  2  s .  com*/
            vmtemplate.merge(context, tempresult);
            contents = tempresult.toString();
            YAMLMapper mapper = new YAMLMapper(new YAMLFactory());
            JsonNode node = mapper.readTree(contents);
            JsonNode outputNode = node.get("Outputs");
            if (outputNode != null) {
                String outputs = contents.substring(contents.lastIndexOf("Outputs:"));
                String resources = contents.substring(0, contents.lastIndexOf("Outputs:"));
                resources = resources + template;
                contents = resources + outputs;
            }

            AmazonCloudFormationClient client = new AmazonCloudFormationClient();
            ValidateTemplateRequest request = new ValidateTemplateRequest();
            request.setTemplateBody(contents);
            if (validate) {
                ValidateTemplateResult result = client.validateTemplate(request);
            }

            try (FileWriter fileWriter = new FileWriter(file)) {
                fileWriter.write(contents);
            }
        }
    }

}