Fog::Aws

Gem Version Build Status Dependency Status Test Coverage Code Climate

Installation

Add this line to your application's Gemfile:

gem 'fog-aws'

And then execute:

$ bundle

Or install it yourself as:

$ gem install fog-aws

Usage

Before you can use fog-aws, you must require it in your application:

require 'fog/aws'

Since it's a bad practice to have your credentials in source code, you should load them from default fog configuration file: ~/.fog. This file could look like this:

default:
  aws_access_key_id:     <YOUR_ACCESS_KEY_ID>
  aws_secret_access_key: <YOUR_SECRET_ACCESS_KEY>

Connecting to EC2 service

ec2 = Fog::Compute.new :provider => 'AWS', :region => 'us-west-2'

You can review all the requests available with this service using #requests method:

ec2.requests # => [:allocate_address, :assign_private_ip_addresses, :associate_address, ...]

Launch an EC2 on-demand instance:

response = ec2.run_instances(
  "ami-23ebb513",
  1,
  1,
  "InstanceType"  => "t1.micro",
  "SecurityGroup" => "ssh",
  "KeyName"       => "miguel"
)
instance_id = response.body["instancesSet"].first["instanceId"] # => "i-02db5af4"
instance = ec2.servers.get(instance_id)
instance.wait_for { ready? }
puts instance.public_ip_address # => "356.300.501.20"

Terminate an EC2 instance:

instance = ec2.servers.get("i-02db5af4")
instance.destroy

Fog::AWS is more than EC2 since it supports many services provided by AWS. The best way to learn and to know about how many services are supported is to take a look at the source code. To review the tests directory and to play with the library in irb can be very helpful resources as well.

Contributing

  1. Fork it ( https://github.com/fog/fog-aws/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request


Fog::Aws

宝石版data-canonical-src 测试覆盖 代码气候

安装

将此行添加到应用程序的Gemfile中:

gem 'fog-aws'

然后执行:

$ bundle

或者自己安装:

$ gem install fog-aws

用法

在使用fog-aws之前,您必须在应用程序中要求它:

require 'fog/aws'

由于在源代码中拥有凭证是一个糟糕的做法,因此您应该从默认的雾配置文件中加载它们:〜/ .fog 。此文件可能如下所示:

default:
  aws_access_key_id:     <YOUR_ACCESS_KEY_ID>
  aws_secret_access_key: <YOUR_SECRET_ACCESS_KEY>

连接到EC2服务

ec2 = Fog::Compute.new :provider => 'AWS', :region => 'us-west-2'

您可以使用 #requests 方法查看此服务可用的所有请求:

ec2.requests # => [:allocate_address, :assign_private_ip_addresses, :associate_address, …]

启动一个EC2按需实例:

response = ec2.run_instances(
  "ami-23ebb513",
  1,
  1,
  "InstanceType"  => "t1.micro",
  "SecurityGroup" => "ssh",
  "KeyName"       => "miguel"
)
instance_id = response.body["instancesSet"].first["instanceId"] # => "i-02db5af4"
instance = ec2.servers.get(instance_id)
instance.wait_for { ready? }
puts instance.public_ip_address # => "356.300.501.20"

终止EC2实例:

instance = ec2.servers.get("i-02db5af4")
instance.destroy

Fog :: AWS超过EC2,因为它支持AWS提供的许多服务。了解和了解支持多少服务的最佳方法是查看源代码。要查看测试目录,并在 irb 中使用库可以是非常有用的资源。

贡献

  1. Fork it ( https://github.com/fog/fog-aws/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request




相关问题推荐