Skip to content

Instantly share code, notes, and snippets.

@murayama
Created July 9, 2013 01:29
Show Gist options
  • Save murayama/5953936 to your computer and use it in GitHub Desktop.
Save murayama/5953936 to your computer and use it in GitHub Desktop.
AWSのelb配下にあるEC2にcapistranoでデプロイする
# -*- coding: utf-8 -*-
require 'aws-sdk'
set :elb_name, "{ELBの名前}"
# 踏み台経由の場合はgatewayを設定する
# set :gateway, "{踏み台サーバーIP or Host}"
set :user, '{ユーザー名}'
ssh_options[:keys] = %w(/home/username/.ssh/id_rsa)
set :use_sudo, false
AWS.config({
:access_key_id => '{AWSのアクセスキー}',
:secret_access_key => '{AWSのシークレットキー}',
:ec2_endpoint => 'ec2.ap-northeast-1.amazonaws.com', # tokyo region
:elb_endpoint => 'elasticloadbalancing.ap-northeast-1.amazonaws.com'
})
elb = AWS::ELB.new
lb_instances = elb.load_balancers[elb_name].instances
instance_ips = lb_instances.map { |instance| instance.private_ip_address }
role(:app) { instance_ips }
role(:web) { instance_ips }
role(:db, :primary => true) { instance_ips.first }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment