Project

activeaws

0.0
No commit activity in last 3 years
No release in over 3 years
Managing aws resources with active way.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.15
~> 10.0

Runtime

 Project Readme

ActiveAws

Installation

Add this line to your application's Gemfile:

gem 'activeaws'

If you want to load this library automatically with Bundler.require, please specify require option at Gemfile.

gem 'activeaws', require: 'active_aws'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activeaws

Usage

require 'active_aws'

Initialize

ActiveAws::Base.load_config!(
  default: {
    region: 'ap-northeast-1',
    profile: 'rv-metheglin',
  }
)
ActiveAws::Base.load_config!( File.expand_path("./aws.yml", __dir__) )

Ec2

provisioner = ActiveAws::Ec2Provisioner.new(:test_instance_name) do |e|
  e.instance_type = 't2.nano'
  e.key_name = 'your-credential-key-name-here'
  e.image_id = 'ami-xxxxxx'
  e.security_group_ids = ['sg-xxxxxxx']
  e.subnet_id = 'subnet-xxxxxxx'
end
ec2 = provisioner.exec!
ec2.wait_until :instance_running
ec2 = ActiveAws::Ec2.find( 'your-instance-id' )
ec2.to_h

CloudFormation

# Prepare `vpc.json` with like:
# Ex): https://aws-quickstart.s3-ap-northeast-1.amazonaws.com/quickstart-linux-bastion/submodules/quickstart-aws-vpc/templates/aws-vpc.template
class VpcProduction < ActiveAws::CloudFormationProvisioner

  class << self
    def generate
      new(
        "your-cloudformation-stack-name-here",
        File.expand_path("vpc.json", __dir__),
        {
          "AvailabilityZones"   => "ap-northeast-1a,ap-northeast-1c,ap-northeast-1d",
          "KeyPairName"         => "your-credential-key-name-here",
          "PrivateSubnet1CIDR"  => "10.0.0.0/19",
          "PrivateSubnet2CIDR"  => "10.0.32.0/19",
          "PublicSubnet1CIDR"   => "10.0.128.0/20",
          "PublicSubnet2CIDR"   => "10.0.144.0/20",
          "RemoteAccessCIDR"    => "0.0.0.0/0",
          "VPCCIDR"             => "10.0.0.0/16",
        }
      )
    end
  end

  # # Please carefully use this method!! 
  # # The CloudFormationProvisioner class doesn't implement `destroy!` on purpose.
  # def destroy!
  #   self.class.client.delete_stack(stack_name: normalized_name)
  # end

end
prov = VpcProduction.generate
prov.save!
prov.wait_until :stack_create_complete

Configure Switching

default:
  region: ap-northeast-1
  profile: aws-default
staging:
  region: ap-northeast-1
  profile: aws-staging
production:
  region: ap-northeast-1
  profile: aws-production
ActiveAws::Base.load_config!( File.expand_path("./aws.yml", __dir__) )

# Fetch ec2 information from `default` profile
ActiveAws::Ec2.find_by_name('web-server-1') 

# Fetch ec2 information from `staging` profile
ActiveAws::Base.with_configure(:staging) do
  ActiveAws::Ec2.find_by_name('web-server-1')
end

# Fetch ec2 information from `production` profile
ActiveAws::Base.with_configure(:production) do
  ActiveAws::Ec2.find_by_name('web-server-1')
end

Changing Default Configure of Current Context

ActiveAws::Base.pool.add_context!( Thread.current, :staging )

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/metheglin/activeaws.

License

The gem is available as open source under the terms of the MIT License.