Example usage for com.amazonaws.services.elasticbeanstalk AWSElasticBeanstalk updateEnvironment

List of usage examples for com.amazonaws.services.elasticbeanstalk AWSElasticBeanstalk updateEnvironment

Introduction

In this page you can find the example usage for com.amazonaws.services.elasticbeanstalk AWSElasticBeanstalk updateEnvironment.

Prototype

UpdateEnvironmentResult updateEnvironment(UpdateEnvironmentRequest updateEnvironmentRequest);

Source Link

Document

Updates the environment description, deploys a new application version, updates the configuration settings to an entirely new configuration template, or updates select configuration option values in the running environment.

Usage

From source file:jp.classmethod.aws.gradle.elasticbeanstalk.AWSElasticBeanstalkCreateEnvironmentTask.java

License:Apache License

@TaskAction
public void createEnvironment() { // NOPMD
    // to enable conventionMappings feature
    String appName = getAppName();
    String envName = getEnvName();
    String envDesc = getEnvDesc();
    String cnamePrefix = getCnamePrefix();
    String templateName = getTemplateName();
    String versionLabel = getVersionLabel();
    Tier tier = getTier();//from   w w  w.j  av a2  s .c o m
    Map<String, String> tags = getTags();

    AwsBeanstalkPluginExtension ext = getProject().getExtensions().getByType(AwsBeanstalkPluginExtension.class);
    AWSElasticBeanstalk eb = ext.getClient();

    DescribeEnvironmentsResult der = eb.describeEnvironments(new DescribeEnvironmentsRequest()
            .withApplicationName(appName).withEnvironmentNames(envName).withIncludeDeleted(false));

    List<Tag> ebTags = tags.entrySet().stream().map(entry -> {
        Tag t = new Tag();
        t.setKey(entry.getKey());
        t.setValue(entry.getValue());
        return t;
    }).collect(Collectors.toList());

    if (der.getEnvironments() == null || der.getEnvironments().isEmpty()) {
        CreateEnvironmentRequest req = new CreateEnvironmentRequest().withApplicationName(appName)
                .withEnvironmentName(envName).withDescription(envDesc).withTemplateName(templateName)
                .withVersionLabel(versionLabel);

        if (tier != null) {
            req.withTier(tier.toEnvironmentTier());
            if (tier == Tier.WebServer) {
                req.withCNAMEPrefix(cnamePrefix);
            }
        }

        if (ebTags != null && !ebTags.isEmpty()) {
            req.withTags(ebTags);
        }

        CreateEnvironmentResult result = eb.createEnvironment(req);
        getLogger().info("environment {} @ {} ({}) created", envName, appName, result.getEnvironmentId());
    } else {
        String environmentId = der.getEnvironments().get(0).getEnvironmentId();

        // Only these two values are required to deploy the a application
        UpdateEnvironmentRequest req = new UpdateEnvironmentRequest().withEnvironmentId(environmentId)
                .withVersionLabel(versionLabel);

        // All other variables are optional and refer to the environment
        if (isNotBlank(envName)) {
            req.withEnvironmentName(envName);
        }
        if (isNotBlank(envDesc)) {
            req.withDescription(envDesc);
        }
        if (isNotBlank(templateName)) {
            req.withTemplateName(templateName);
        }

        eb.updateEnvironment(req);

        getLogger().info("environment {} @ {} ({}) updated", envName, appName, environmentId);
    }
}

From source file:org.xmlsh.aws.gradle.elasticbeanstalk.AWSElasticBeanstalkCreateEnvironmentTask.java

License:BSD License

@TaskAction
public void createEnvironment() {
    // to enable conventionMappings feature
    String appName = getAppName();
    String envName = getEnvName();
    String envDesc = getEnvDesc();
    String cnamePrefix = getCnamePrefix();
    String templateName = getTemplateName();
    String versionLabel = getVersionLabel();
    Tier tier = getTier();//  w  w  w. j av a 2  s .  c  om

    AwsBeanstalkPluginExtension ext = getProject().getExtensions().getByType(AwsBeanstalkPluginExtension.class);
    AWSElasticBeanstalk eb = ext.getClient();

    DescribeEnvironmentsResult der = eb.describeEnvironments(new DescribeEnvironmentsRequest()
            .withApplicationName(appName).withEnvironmentNames(envName).withIncludeDeleted(false));

    if (der.getEnvironments() == null || der.getEnvironments().isEmpty()) {
        CreateEnvironmentRequest req = new CreateEnvironmentRequest().withApplicationName(appName)
                .withEnvironmentName(envName).withDescription(envDesc).withTemplateName(templateName)
                .withVersionLabel(versionLabel).withTier(tier.toEnvironmentTier());
        if (tier == Tier.WebServer) {
            req.withCNAMEPrefix(cnamePrefix);
        }
        CreateEnvironmentResult result = eb.createEnvironment(req);
        getLogger().info(
                "environment " + envName + " @ " + appName + " (" + result.getEnvironmentId() + ") created");
    } else {
        String environmentId = der.getEnvironments().get(0).getEnvironmentId();

        eb.updateEnvironment(new UpdateEnvironmentRequest().withEnvironmentId(environmentId)
                .withEnvironmentName(envName).withDescription(envDesc).withTemplateName(templateName)
                .withVersionLabel(versionLabel).withTier(tier.toEnvironmentTier()));
        getLogger().info("environment " + envName + " @ " + appName + " (" + environmentId + ") updated");
    }
}