Example usage for com.amazonaws.services.cloudformation AmazonCloudFormationAsyncClient updateStackAsync

List of usage examples for com.amazonaws.services.cloudformation AmazonCloudFormationAsyncClient updateStackAsync

Introduction

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

Prototype

@Override
    public java.util.concurrent.Future<UpdateStackResult> updateStackAsync(UpdateStackRequest request) 

Source Link

Usage

From source file:com.mweagle.tereus.aws.CloudFormation.java

License:Open Source License

public Optional<DescribeStacksResult> updateStack(final UpdateStackRequest request, final Region awsRegion,
        Logger logger) {/*from   w  w  w .jav a  2s  .  c  om*/
    DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain();
    final AmazonCloudFormationAsyncClient awsClient = new AmazonCloudFormationAsyncClient(
            credentialProviderChain.getCredentials());
    awsClient.setRegion(awsRegion);
    logger.info("Updating stack: {}", request.getStackName());
    Optional<DescribeStacksResult> completionResult = Optional.empty();

    try {
        final List<StackEvent> priorEvents = getStackEvents(awsClient, request.getStackName(), logger);
        logger.info("Total number of pre-existing stack events: {}", priorEvents.size());
        Future<UpdateStackResult> updateStackResult = awsClient.updateStackAsync(request);
        final UpdateStackResult stackResult = updateStackResult.get();
        logger.info("Stack ({}) creation in progress.", stackResult.getStackId());
        completionResult = waitForStackComplete(awsClient, request.getStackName(), priorEvents, logger);
    } catch (Exception ex) {
        logger.error(ex);
    }
    return completionResult;
}