Example usage for com.amazonaws.services.cloudformation.model ChangeSetType UPDATE

List of usage examples for com.amazonaws.services.cloudformation.model ChangeSetType UPDATE

Introduction

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

Prototype

ChangeSetType UPDATE

To view the source code for com.amazonaws.services.cloudformation.model ChangeSetType UPDATE.

Click Source Link

Usage

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

License:Open Source License

public void deploy(String templateBody, String codeUri, String swaggerDefinitionUri) {
    final String stackName = config.getStackName();
    final String changeSetName = stackName + "-" + System.currentTimeMillis();
    final ChangeSetType changeSetType = cloudFormationService.stackExists(stackName) ? ChangeSetType.UPDATE
            : ChangeSetType.CREATE;/*w w w  . ja  v  a2 s  .  c o  m*/
    final String newTemplateBody = updateTemplateBody(templateBody, codeUri, swaggerDefinitionUri);
    final String changeSetArn = cloudFormationService.createChangeSet(changeSetName, stackName, changeSetType,
            newTemplateBody, emptyList());
    pollingService.waitForChangeSetReady(changeSetArn);
    cloudFormationService.executeChangeSet(changeSetArn);
    pollingService.waitForStackReady(stackName);
    logStackOutput();
}

From source file:de.taimos.pipeline.aws.cloudformation.CloudFormationStack.java

License:Apache License

public void createChangeSet(String changeSetName, String templateBody, String templateUrl,
        Collection<Parameter> params, Collection<Tag> tags, long pollIntervallMillis,
        ChangeSetType changeSetType, String roleArn) throws ExecutionException {
    try {/*from w  ww .  j a va  2s.co m*/
        CreateChangeSetRequest req = new CreateChangeSetRequest();
        req.withChangeSetName(changeSetName).withStackName(this.stack)
                .withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM)
                .withChangeSetType(changeSetType);

        if (ChangeSetType.CREATE.equals(changeSetType)) {
            this.listener.getLogger().format("Creating CloudFormation change set %s for new stack %s %n",
                    changeSetName, this.stack);
            if ((templateBody == null || templateBody.isEmpty())
                    && (templateUrl == null || templateUrl.isEmpty())) {
                throw new IllegalArgumentException("Either a file or url for the template must be specified");
            }
            req.withTemplateBody(templateBody).withTemplateURL(templateUrl);
        } else if (ChangeSetType.UPDATE.equals(changeSetType)) {
            this.listener.getLogger().format("Creating CloudFormation change set %s for existing stack %s %n",
                    changeSetName, this.stack);
            if (templateBody != null && !templateBody.isEmpty()) {
                req.setTemplateBody(templateBody);
            } else if (templateUrl != null && !templateUrl.isEmpty()) {
                req.setTemplateURL(templateUrl);
            } else {
                req.setUsePreviousTemplate(true);
            }
        } else {
            throw new IllegalArgumentException(
                    "Cannot create a CloudFormation change set without a valid change set type.");
        }

        req.withParameters(params).withTags(tags).withRoleARN(roleArn);

        this.client.createChangeSet(req);

        new EventPrinter(this.client, this.listener).waitAndPrintChangeSetEvents(this.stack, changeSetName,
                this.client.waiters().changeSetCreateComplete(), pollIntervallMillis);

        this.listener.getLogger().format("Created CloudFormation change set %s for stack %s %n", changeSetName,
                this.stack);

    } catch (ExecutionException e) {
        try {
            if (this.changeSetExists(changeSetName) && !this.changeSetHasChanges(changeSetName)) {
                // Ignore the failed creation of a change set with no changes.
                this.listener.getLogger().format("Created empty change set %s for stack %s %n", changeSetName,
                        this.stack);
                return;
            }
        } catch (Throwable throwable) {
            e.addSuppressed(throwable);
        }
        this.listener.getLogger().format("Failed to create CloudFormation change set %s for stack %s %n",
                changeSetName, this.stack);
        throw e;
    }
}