Example usage for com.amazonaws.services.cloudformation.model Capability CAPABILITY_NAMED_IAM

List of usage examples for com.amazonaws.services.cloudformation.model Capability CAPABILITY_NAMED_IAM

Introduction

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

Prototype

Capability CAPABILITY_NAMED_IAM

To view the source code for com.amazonaws.services.cloudformation.model Capability CAPABILITY_NAMED_IAM.

Click Source Link

Usage

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

License:Apache License

public void create(String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags,
        Integer timeoutInMinutes, long pollIntervallMillis, String roleArn, String onFailure)
        throws ExecutionException {
    if ((templateBody == null || templateBody.isEmpty()) && (templateUrl == null || templateUrl.isEmpty())) {
        throw new IllegalArgumentException("Either a file or url for the template must be specified");
    }/*from   ww  w.j a v  a  2  s. co  m*/

    CreateStackRequest req = new CreateStackRequest();
    req.withStackName(this.stack).withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM);
    req.withTemplateBody(templateBody).withTemplateURL(templateUrl).withParameters(params).withTags(tags)
            .withTimeoutInMinutes(timeoutInMinutes).withRoleARN(roleArn)
            .withOnFailure(OnFailure.valueOf(onFailure));
    this.client.createStack(req);

    new EventPrinter(this.client, this.listener).waitAndPrintStackEvents(this.stack,
            this.client.waiters().stackCreateComplete(), pollIntervallMillis);
}

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

License:Apache License

public void update(String templateBody, String templateUrl, Collection<Parameter> params, Collection<Tag> tags,
        long pollIntervallMillis, String roleArn) throws ExecutionException {
    try {//  www. jav a 2  s  . c o  m
        UpdateStackRequest req = new UpdateStackRequest();
        req.withStackName(this.stack).withCapabilities(Capability.CAPABILITY_IAM,
                Capability.CAPABILITY_NAMED_IAM);

        if (templateBody != null && !templateBody.isEmpty()) {
            req.setTemplateBody(templateBody);
        } else if (templateUrl != null && !templateUrl.isEmpty()) {
            req.setTemplateURL(templateUrl);
        } else {
            req.setUsePreviousTemplate(true);
        }

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

        this.client.updateStack(req);

        new EventPrinter(this.client, this.listener).waitAndPrintStackEvents(this.stack,
                this.client.waiters().stackUpdateComplete(), pollIntervallMillis);

        this.listener.getLogger().format("Updated CloudFormation stack %s %n", this.stack);

    } catch (AmazonCloudFormationException e) {
        if (e.getMessage().contains("No updates are to be performed")) {
            this.listener.getLogger().format("No updates were needed for CloudFormation stack %s %n",
                    this.stack);
            return;
        }
        this.listener.getLogger().format("Failed to update CloudFormation stack %s %n", this.stack);
        throw e;
    }
}

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 w w . j av a 2 s. c o  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;
    }
}

From source file:de.taimos.pipeline.aws.cloudformation.stacksets.CloudFormationStackSet.java

License:Apache License

public CreateStackSetResult create(String templateBody, String templateUrl, Collection<Parameter> params,
        Collection<Tag> tags) {
    if ((templateBody == null || templateBody.isEmpty()) && (templateUrl == null || templateUrl.isEmpty())) {
        throw new IllegalArgumentException("Either a file or url for the template must be specified");
    }/*  w  w  w  .  j a  va  2 s.c om*/

    this.listener.getLogger().println("Creating stack set " + this.stackSet);
    CreateStackSetRequest req = new CreateStackSetRequest().withStackSetName(this.stackSet)
            .withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM)
            .withTemplateBody(templateBody).withTemplateURL(templateUrl).withParameters(params).withTags(tags);
    CreateStackSetResult result = this.client.createStackSet(req);
    this.listener.getLogger().println("Created Stack set stackSetId=" + result.getStackSetId());
    return result;
}

From source file:de.taimos.pipeline.aws.cloudformation.stacksets.CloudFormationStackSet.java

License:Apache License

public UpdateStackSetResult update(String templateBody, String templateUrl, Collection<Parameter> params,
        Collection<Tag> tags) {
    this.listener.getLogger().format("Updating CloudFormation stack set %s %n", this.stackSet);
    UpdateStackSetRequest req = new UpdateStackSetRequest().withStackSetName(this.stackSet)
            .withCapabilities(Capability.CAPABILITY_IAM, Capability.CAPABILITY_NAMED_IAM).withParameters(params)
            .withTags(tags);//  w  w w .  j a  va2  s . co  m

    if (templateBody != null && !templateBody.isEmpty()) {
        req.setTemplateBody(templateBody);
    } else if (templateUrl != null && !templateUrl.isEmpty()) {
        req.setTemplateURL(templateUrl);
    } else {
        req.setUsePreviousTemplate(true);
    }

    UpdateStackSetResult result = this.client.updateStackSet(req);

    this.listener.getLogger().format("Updated CloudFormation stack set %s %n", this.stackSet);
    return result;
}