Code borrowed from fog (github.com/geemus/fog).
This gem will simply generate the AWS EC2 signature so that you can use your own HTTP methods and libraries to POST to your choice of AWS/EC2 compatible API servers such as Eucalyptus, OpenNebula, OpenAuth. Apparently, most of the AWS/EC2 API gems out there are not compatible with the aforementioned cloud frameworks, due to running on a custom port they do not account for that when generating the signature. Fog had implemented a compatible signature method, however, I did not want to use the EXCON http library implemented in it so I extracted the signature method only for use with my own choice of HTTP library.
############################## #### OpenStack Example 1 #### ##############################
require ‘ec2-signature’ # pass a hash containing your aws auth params to new obj mysig = EC2Signature.new( {
:access_id => ,
:secret_key => ,
:ec2_url => 'http://myec2server:8773/services/Cloud'
} )
# generate the signature provided the query action you want to issue to your ec2 provider signature = mysig.sign( => ‘DescribeImages’ ) # use the example net/http post method to post your signature to the ec2_url specified above mysig.post signature
############################## #### OpenStack Example 2 #### ############################## mysig.path = ‘/services/Admin’ # opennebula’s aws/ec2 api implementation has a diff path for admin cmds signature = mysig.sign( {
'Action' => 'DescribeUser',
'Name' => 'jsmith',
} )
mysig.post signature