Example usage for com.amazonaws.services.ecs AmazonECS createService

List of usage examples for com.amazonaws.services.ecs AmazonECS createService

Introduction

In this page you can find the example usage for com.amazonaws.services.ecs AmazonECS createService.

Prototype

CreateServiceResult createService(CreateServiceRequest createServiceRequest);

Source Link

Document

Runs and maintains a desired number of tasks from a specified task definition.

Usage

From source file:com.netflix.spinnaker.clouddriver.ecs.deploy.ops.CreateServerGroupAtomicOperation.java

License:Apache License

private Service createService(AmazonECS ecs, TaskDefinition taskDefinition, String ecsServiceRole,
        String version) {//from  w w  w .  j  a v  a  2  s.  c om
    String serviceName = getNextServiceName(version);
    Collection<LoadBalancer> loadBalancers = new LinkedList<>();
    loadBalancers.add(retrieveLoadBalancer(version));

    Integer desiredCount = description.getCapacity().getDesired();
    String taskDefinitionArn = taskDefinition.getTaskDefinitionArn();

    DeploymentConfiguration deploymentConfiguration = new DeploymentConfiguration()
            .withMinimumHealthyPercent(100).withMaximumPercent(200);

    CreateServiceRequest request = new CreateServiceRequest().withServiceName(serviceName)
            .withDesiredCount(desiredCount).withCluster(description.getEcsClusterName())
            .withRole(ecsServiceRole).withLoadBalancers(loadBalancers).withTaskDefinition(taskDefinitionArn)
            .withPlacementStrategy(description.getPlacementStrategySequence())
            .withDeploymentConfiguration(deploymentConfiguration);

    updateTaskStatus(String.format("Creating %s of %s with %s for %s.", desiredCount, serviceName,
            taskDefinitionArn, description.getCredentialAccount()));

    Service service = ecs.createService(request).getService();

    updateTaskStatus(String.format("Done creating %s of %s with %s for %s.", desiredCount, serviceName,
            taskDefinitionArn, description.getCredentialAccount()));

    return service;
}