Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ set :aws_secret_key, ENV['AWS_SECRET_ACCESS_KEY']
set :aws_region, ENV['AWS_REGION']
```

Set the means through which to communicate with instances. Select from `public_dns_name` *(the default)*, `public_ip_address`, `private_dns_name` and `private_ip_address`. For example, if you are using a bastion host and SSHing into your instances via a private subnet you would want to add the following:

```ruby
set :elbas_hostname_type, 'private_ip_address'
```

## Usage

Instead of using Capistrano's `server` method, use `autoscale` instead in
Expand Down
7 changes: 7 additions & 0 deletions lib/elbas/aws/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module AWS
class Base
include Capistrano::DSL

HOSTNAME_TYPES = %w(public_ip_address public_dns_name private_ip_address private_dns_name).freeze
DEFAULT_HOSTNAME_TYPE = 'public_dns_name'.freeze

attr_reader :aws_counterpart

def aws_client(namespace = aws_namespace)
Expand Down Expand Up @@ -31,6 +34,10 @@ def aws_region
fetch :aws_region
end

def elbas_hostname_type
HOSTNAME_TYPES.include?(fetch(:elbas_hostname_type)) ? fetch(:elbas_hostname_type) : DEFAULT_HOSTNAME_TYPE
end

def self.aws_client(namespace = aws_namespace)
Base.new.aws_client namespace
end
Expand Down
6 changes: 3 additions & 3 deletions lib/elbas/aws/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ class Instance < Base

attr_reader :aws_counterpart, :id, :state

def initialize(id, public_dns, state)
def initialize(id, hostname, state)
@id = id
@public_dns = public_dns
@hostname = hostname
@state = state
@aws_counterpart = aws_namespace::Instance.new id, client: aws_client
end

def hostname
@public_dns
@hostname
end

def running?
Expand Down
2 changes: 1 addition & 1 deletion lib/elbas/aws/instance_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class InstanceCollection < Base
def initialize(ids)
@ids = ids
@instances = query_instances_by_ids(ids).map do |i|
Instance.new(i.instance_id, i.public_dns_name, i.state.code)
Instance.new(i.instance_id, i.send(elbas_hostname_type), i.state.code)
end
end

Expand Down