module Capistrano::Aws

Constants

VERSION

Public Instance Methods

bluegreen(role, target_arn, &block) click to toggle source
# File lib/capistrano/aws.rb, line 12
def bluegreen(role, target_arn, &block)
  servers = roles(role)
  servers.each_slice(servers.length / 2).each do |cluster|
    begin
      instance_ids = cluster.map{|x| x.properties.instance_id }
      deregister(target_arn, instance_ids)
      on(cluster, &block)
    ensure
      register(target_arn, instance_ids)
    end
  end
end
credentials() click to toggle source
# File lib/capistrano/aws/client.rb, line 11
def credentials
  @credentials ||= ::Aws::SharedCredentials.new(profile_name: fetch(:aws_profile)).credentials
end
deregister(target_arn, instance_ids) click to toggle source
# File lib/capistrano/aws.rb, line 38
def deregister(target_arn, instance_ids)
  params = {
    target_group_arn: target_arn,
    targets: instance_ids.map{|id| { id: id }}
  }

  elb.deregister_targets(params)
  loop do
    return if elb.describe_target_health(params).target_health_descriptions.all? { |t| t.target_health.state == 'unused' }
    sleep 5
  end
end
ec2() click to toggle source
# File lib/capistrano/aws/client.rb, line 15
def ec2
  @ec2 ||= AutoMapping.new(
    fetch(:aws_regions).map do |region|
      ::Aws::EC2::Client.new(credentials: credentials, region: region)
    end
  )
end
elb() click to toggle source
# File lib/capistrano/aws/client.rb, line 23
def elb
  @elb ||= AutoMapping.new(
    fetch(:aws_regions).map do |region|
      ::Aws::ElasticLoadBalancingV2::Client.new(credentials: credentials, region: region)
    end
  )
end
instances(options = {}) click to toggle source
# File lib/capistrano/aws.rb, line 8
def instances(options = {})
  ec2.describe_instances(filters: fetch(:ec2_filters)).reservations.instances
end
register(target_arn, instance_ids) click to toggle source
# File lib/capistrano/aws.rb, line 25
def register(target_arn, instance_ids)
  params = {
    target_group_arn: target_arn,
    targets: instance_ids.map{|id| { id: id }}
  }

  elb.register_targets(params)
  loop do
    return if elb.describe_target_health(params).target_health_descriptions.all? { |t| t.target_health.state == 'healthy' }
    sleep 5
  end
end