diff --git a/README.md b/README.md index 036d9959a..c1034100c 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,56 @@ Or install it yourself as: ## Usage -TODO: Write usage instructions here +Before you can use fog-aws, you must require it in your application: + +```ruby +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: AKIAKFA8FKVJBJS8W3JG + aws_secret_access_key: k5OVuSAkh4dGeEiKHRC2ke0fSpX/5qOKGaoV+HBm +``` + +### Connecting to EC2 service +```ruby +ec2 = Fog::Compute.new :provider => 'AWS', :region => 'us-west-2' +``` + +You can review all the requests available with this service using ```#requests``` method: + +```ruby +ec2.requests # => [:allocate_address, :assign_private_ip_addresses, :associate_address, ...] +``` + +### Launch an EC2 on-demand instance: + +```ruby +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 # => "54.200.201.120" +``` + +### Terminate an EC2 instance: + +```ruby +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